summaryrefslogtreecommitdiffstats
path: root/winsup/mingw/mingwex/wctrans.c
diff options
context:
space:
mode:
authorDanny Smith <dannysmith@users.sourceforge.net>2005-02-25 01:43:43 +0000
committerDanny Smith <dannysmith@users.sourceforge.net>2005-02-25 01:43:43 +0000
commit7e9439a0eb2bd5494694dd750a3034c6a32babca (patch)
tree6ba17457bf398e7f7170c83ee5c98861f233d8fc /winsup/mingw/mingwex/wctrans.c
parent2598f908ca5317ae743f875ca1351185909ab3a6 (diff)
downloadcygnal-7e9439a0eb2bd5494694dd750a3034c6a32babca.tar.gz
cygnal-7e9439a0eb2bd5494694dd750a3034c6a32babca.tar.bz2
cygnal-7e9439a0eb2bd5494694dd750a3034c6a32babca.zip
* mingwex/wctype.c: New file.
* mingwex/wctrans.c: New file. * mingwex/Makefile.in (DISTFILES): Add wctype.c, wctrans.c. * mingwex/Makefile.in (Q8_OBJS): Add wctype.o, wctrans.o.
Diffstat (limited to 'winsup/mingw/mingwex/wctrans.c')
-rwxr-xr-xwinsup/mingw/mingwex/wctrans.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/winsup/mingw/mingwex/wctrans.c b/winsup/mingw/mingwex/wctrans.c
new file mode 100755
index 000000000..e129af471
--- /dev/null
+++ b/winsup/mingw/mingwex/wctrans.c
@@ -0,0 +1,60 @@
+/*
+ wctrans.c
+ 7.25.3.2 Extensible wide-character case mapping functions
+
+ Contributed by: Danny Smith <dannysmith@usesr.sourcefoge.net>
+ 2005-02-24
+
+ This source code is placed in the PUBLIC DOMAIN. It is modified
+ from the Q8 package created by Doug Gwyn <gwyn@arl.mil>
+
+ */
+
+#include <string.h>
+#include <wctype.h>
+
+/*
+ This differs from the MS implementation of wctrans which
+ returns 0 for tolower and 1 for toupper. According to
+ C99, a 0 return value indicates invalid input.
+
+ These two function go in the same translation unit so that we
+ can ensure that
+ towctrans(wc, wctrans("tolower")) == towlower(wc)
+ towctrans(wc, wctrans("toupper")) == towupper(wc)
+ It also ensures that
+ towctrans(wc, wctrans("")) == wc
+ which is not required by standard.
+*/
+
+static const struct {
+ const char *name;
+ wctrans_t val; } tmap[] = {
+ {"tolower", _LOWER},
+ {"toupper", _UPPER}
+ };
+
+#define NTMAP (sizeof tmap / sizeof tmap[0])
+
+wctrans_t
+wctrans (const char* property)
+{
+ int i;
+ for ( i = 0; i < NTMAP; ++i )
+ if (strcmp (property, tmap[i].name) == 0)
+ return tmap[i].val;
+ return 0;
+}
+
+wint_t towctrans (wint_t wc, wctrans_t desc)
+{
+ switch (desc)
+ {
+ case _LOWER:
+ return towlower (wc);
+ case _UPPER:
+ return towupper (wc);
+ default:
+ return wc;
+ }
+}