]> sourceware.org Git - newlib-cygwin.git/commitdiff
* mingwex/wctype.c: New file.
authorDanny Smith <dannysmith@users.sourceforge.net>
Fri, 25 Feb 2005 01:43:43 +0000 (01:43 +0000)
committerDanny Smith <dannysmith@users.sourceforge.net>
Fri, 25 Feb 2005 01:43:43 +0000 (01:43 +0000)
* mingwex/wctrans.c: New file.
* mingwex/Makefile.in (DISTFILES): Add wctype.c, wctrans.c.
* mingwex/Makefile.in (Q8_OBJS): Add wctype.o, wctrans.o.

winsup/mingw/ChangeLog
winsup/mingw/mingwex/Makefile.in
winsup/mingw/mingwex/wctrans.c [new file with mode: 0755]
winsup/mingw/mingwex/wctype.c [new file with mode: 0755]

index f8b87f969aacbb9135dfba568d5e23bd7ee4ec75..8948eeb6c4e4525f7b8dfd3d37e04bb4ded9af8e 100644 (file)
@@ -1,3 +1,10 @@
+2005-02-25  Danny Smith  <dannysmith@users.sourceforge.net>
+
+       * 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.
+
 2005-02-11  Danny Smith  <dannysmith@users.sourceforge.net>
 
        * include/tchar.h (_tstat64, _tstati64): Add Unicode/ANSI mappings.
index 7dc0087f5209b9e895e64eb36da3d76ad6969f9d..5cfde769d63e933bcc4436f050a592abb2d9249d 100644 (file)
@@ -33,9 +33,8 @@ DISTFILES = Makefile.in configure configure.in \
        ldtoa.c lltoa.c lltow.c mbsinit.c mingw-aligned-malloc.c \
        mingw-fseek.c sitest.c strtof.c strtoimax.c strtold.c strtoumax.c \
        testwmem.c tst-aligned-malloc.c ulltoa.c ulltow.c wcstof.c \
-       wcstoimax.c wcstold.c wcstoumax.c wdirent.c wmemchr.c wmemcmp.c \
-       wmemcpy.c wmemmove.c wmemset.c wtoll.c
-       
+       wcstoimax.c wcstold.c wcstoumax.c wctrans.c wctype.c \
+       wdirent.c wmemchr.c wmemcmp.c wmemcpy.c wmemmove.c wmemset.c wtoll.c    
 MATH_DISTFILES = \
        acosf.c acosl.c asinf.c asinl.c atan2f.c atan2l.c \
        atanf.c atanl.c cbrt.c cbrtf.c cbrtl.c ceilf.S ceill.S \
@@ -114,7 +113,8 @@ LIBMINGWEX_A = libmingwex.a
 Q8_OBJS = \
        fwide.o imaxabs.o imaxdiv.o mbsinit.o \
        strtoimax.o strtoumax.o wcstoimax.o wcstoumax.o \
-       wmemchr.o wmemcmp.o wmemcpy.o wmemmove.o wmemset.o
+       wmemchr.o wmemcmp.o wmemcpy.o wmemmove.o wmemset.o \
+       wctrans.o wctype.o
 STDLIB_OBJS = \
        strtold.o wcstold.o
 STDLIB_STUB_OBJS = \
diff --git a/winsup/mingw/mingwex/wctrans.c b/winsup/mingw/mingwex/wctrans.c
new file mode 100755 (executable)
index 0000000..e129af4
--- /dev/null
@@ -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;
+   }
+}
diff --git a/winsup/mingw/mingwex/wctype.c b/winsup/mingw/mingwex/wctype.c
new file mode 100755 (executable)
index 0000000..197fde5
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+  wctype.c
+  7.25.2.2.2 The wctype function
+
+  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>  
+
+  The wctype function constructs a value with type wctype_t that
+  describes a class of wide characters identified by the string
+  argument property.
+
+  In particular, we map the property strings so that:
+
+  iswctype(wc, wctype("alnum")) == iswalnum(wc) 
+  iswctype(wc, wctype("alpha")) == iswalpha(wc)
+  iswctype(wc, wctype("cntrl")) == iswcntrl(wc)
+  iswctype(wc, wctype("digit")) == iswdigit(wc)
+  iswctype(wc, wctype("graph")) == iswgraph(wc)
+  iswctype(wc, wctype("lower")) == iswlower(wc)
+  iswctype(wc, wctype("print")) == iswprint(wc)
+  iswctype(wc, wctype("punct")) == iswpunct(wc)
+  iswctype(wc, wctype("space")) == iswspace(wc)
+  iswctype(wc, wctype("upper")) == iswupper(wc)
+  iswctype(wc, wctype("xdigit")) == iswxdigit(wc)
+
+*/
+
+#include       <string.h>
+#include       <wctype.h>
+
+/* Using the bit-OR'd ctype character classification flags as return
+   values achieves compatibility with MS iswctype().  */
+static const struct {
+  const char *name;
+  wctype_t flags;} cmap[] = {
+    {"alnum", _ALPHA|_DIGIT},
+    {"alpha", _ALPHA},
+    {"cntrl", _CONTROL},
+    {"digit", _DIGIT},
+    {"graph", _PUNCT|_ALPHA|_DIGIT},
+    {"lower", _LOWER},
+    {"print", _BLANK|_PUNCT|_ALPHA|_DIGIT},
+    {"punct", _PUNCT},
+    {"space", _SPACE},
+    {"upper", _UPPER},
+    {"xdigit", _HEX}
+  };
+
+#define NCMAP  (sizeof cmap / sizeof cmap[0])
+wctype_t wctype (const char *property)
+{
+  int i;
+  for (i = 0; i < NCMAP; ++i)
+    if (strcmp (property, cmap[i].name) == 0)
+      return cmap[i].flags;
+  return 0;
+}
This page took 0.039759 seconds and 5 git commands to generate.