changeset 11953:5c391da16504

Support towlower and towupper.
author Bruno Haible <bruno@clisp.org>
date Sat, 05 Sep 2009 18:06:54 +0200
parents 0ae7f1f4ed08
children c2aabb82023d
files ChangeLog doc/posix-functions/towlower.texi doc/posix-functions/towupper.texi lib/wctype.in.h tests/test-wctype.c
diffstat 5 files changed, 78 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+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.
--- 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
--- 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
--- 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 <wctype.h> 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 @@
 	  || ((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 */
--- a/tests/test-wctype.c
+++ b/tests/test-wctype.c
@@ -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
@@ -20,8 +20,25 @@
 
 #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 @@
   (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;
 }