+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.
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
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
# 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
|| ((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 */
/* 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 ()
(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;
}