Support towlower and towupper.
authorBruno Haible <bruno@clisp.org>
Sat, 5 Sep 2009 16:06:54 +0000 (18:06 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 5 Sep 2009 16:06:54 +0000 (18:06 +0200)
ChangeLog
doc/posix-functions/towlower.texi
doc/posix-functions/towupper.texi
lib/wctype.in.h
tests/test-wctype.c

index 7ef7441..69c5c16 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2009-09-05  Bruno Haible  <bruno@clisp.org>
 
+       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 <alanh@fairlite.co.uk>.
+
+2009-09-05  Bruno Haible  <bruno@clisp.org>
+
        Fix conversion behaviour when the input is invalid.
        * lib/striconveh.c (mem_cd_iconveh_internal): Fix storing of question
        mark occurring in first pass of indirect conversion.
index 8fd6b62..9857c56 100644 (file)
@@ -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
index 52b17f8..2fd8aea 100644 (file)
@@ -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
index bcd0151..fef31dd 100644 (file)
@@ -84,6 +84,8 @@
 #  undef iswspace
 #  undef iswupper
 #  undef iswxdigit
+#  undef towlower
+#  undef towupper
 
 /* Linux libc5 has <wctype.h> and the functions but they are broken.  */
 #  if @REPLACE_ISWCNTRL@
 #   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 */
index c2d8601..5deae45 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of <wctype.h> 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
 
 #include <wctype.h>
 
+#include <stdio.h>
+#include <stdlib.h>
+
+#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;
 }