From: Bruno Haible Date: Sat, 5 Sep 2009 16:06:54 +0000 (+0200) Subject: Support towlower and towupper. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2dbdc8c00c75511c14b16c90e90a24796093ac91;p=pspp Support towlower and towupper. --- diff --git a/ChangeLog b/ChangeLog index 7ef7441880..69c5c16572 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2009-09-05 Bruno Haible + + Support towlower, towupper. + * doc/posix-functions/towlower.texi: Mention module wctype. + * doc/posix-functions/towupper.texi: Likewise. + * lib/wctype.in.h (towlower, towupper): New functions. + * tests/test-wctype.c: Include stdio.h, stdlib.h. + (ASSERT): New macro. + (e): New variable. + (main): Test also towlower, towupper. Test WEOF argument. + Reported by Alan Hourihane . + 2009-09-05 Bruno Haible Fix conversion behaviour when the input is invalid. diff --git a/doc/posix-functions/towlower.texi b/doc/posix-functions/towlower.texi index 8fd6b62357..9857c56a74 100644 --- a/doc/posix-functions/towlower.texi +++ b/doc/posix-functions/towlower.texi @@ -4,18 +4,18 @@ POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/towlower.html} -Gnulib module: --- +Gnulib module: wctype Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +IRIX 5.3, Solaris 2.5.1. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function is missing on some platforms: -IRIX 5.3, Solaris 2.5.1. -@item On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot accommodate all Unicode characters. @end itemize diff --git a/doc/posix-functions/towupper.texi b/doc/posix-functions/towupper.texi index 52b17f861c..2fd8aea20c 100644 --- a/doc/posix-functions/towupper.texi +++ b/doc/posix-functions/towupper.texi @@ -4,18 +4,18 @@ POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/towupper.html} -Gnulib module: --- +Gnulib module: wctype Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +IRIX 5.3, Solaris 2.5.1. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function is missing on some platforms: -IRIX 5.3, Solaris 2.5.1. -@item On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot accommodate all Unicode characters. @end itemize diff --git a/lib/wctype.in.h b/lib/wctype.in.h index bcd0151d2f..fef31dd80d 100644 --- a/lib/wctype.in.h +++ b/lib/wctype.in.h @@ -84,6 +84,8 @@ # undef iswspace # undef iswupper # undef iswxdigit +# undef towlower +# undef towupper /* Linux libc5 has and the functions but they are broken. */ # if @REPLACE_ISWCNTRL@ @@ -99,6 +101,8 @@ # define iswspace rpl_iswspace # define iswupper rpl_iswupper # define iswxdigit rpl_iswxdigit +# define towlower rpl_towlower +# define towupper rpl_towupper # endif static inline int @@ -178,6 +182,18 @@ iswxdigit (wint_t wc) || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F')); } +static inline wint_t +towlower (wint_t wc) +{ + return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc); +} + +static inline wint_t +towupper (wint_t wc) +{ + return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc); +} + # endif /* ! HAVE_ISWCNTRL */ #endif /* _GL_WCTYPE_H */ diff --git a/tests/test-wctype.c b/tests/test-wctype.c index c2d8601664..5deae45de9 100644 --- a/tests/test-wctype.c +++ b/tests/test-wctype.c @@ -1,5 +1,5 @@ /* Test of substitute. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,8 +20,25 @@ #include +#include +#include + +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ + while (0) + /* Check that the type wint_t is defined. */ wint_t a = 'x'; +/* Check that WEOF is defined. */ +wint_t e = WEOF; int main () @@ -42,5 +59,29 @@ main () (void) iswupper (0); (void) iswxdigit (0); + /* Check that the isw* functions map WEOF to 0. */ + ASSERT (!iswalnum (e)); + ASSERT (!iswalpha (e)); +#if 0 /* not portable: missing on mingw */ + ASSERT (!iswblank (e)); +#endif + ASSERT (!iswcntrl (e)); + ASSERT (!iswdigit (e)); + ASSERT (!iswgraph (e)); + ASSERT (!iswlower (e)); + ASSERT (!iswprint (e)); + ASSERT (!iswpunct (e)); + ASSERT (!iswspace (e)); + ASSERT (!iswupper (e)); + ASSERT (!iswxdigit (e)); + + /* Check that the tow* functions exist as functions or as macros. */ + (void) towlower (0); + (void) towupper (0); + + /* Check that the tow* functions map WEOF to WEOF. */ + ASSERT (towlower (e) == e); + ASSERT (towupper (e) == e); + return 0; }