]> pd.if.org Git - pdclib.old/commitdiff
PDCLIB-3 #resolve Implement towctrans/wctrans. Completes wctype.h
authorOwen Shepherd <owen.shepherd@e43.eu>
Sat, 16 Mar 2013 20:33:00 +0000 (20:33 +0000)
committerOwen Shepherd <owen.shepherd@e43.eu>
Sat, 16 Mar 2013 20:33:00 +0000 (20:33 +0000)
functions/wctype/towctrans.c [new file with mode: 0644]
functions/wctype/wctrans.c [new file with mode: 0644]
internals/_PDCLIB_locale.h

diff --git a/functions/wctype/towctrans.c b/functions/wctype/towctrans.c
new file mode 100644 (file)
index 0000000..aea9b1a
--- /dev/null
@@ -0,0 +1,37 @@
+/* towctrans( wint_t, wctrans_t )\r
+\r
+   This file is part of the Public Domain C Library (PDCLib).\r
+   Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+#include <wctype.h>\r
+#ifndef REGTEST\r
+#include <string.h>\r
+#include <_PDCLIB_locale.h>\r
+\r
+wint_t towctrans( wint_t wc, wctrans_t trans )\r
+{\r
+    switch( trans ) {\r
+        case 0:                         return wc;\r
+        case _PDCLIB_WCTRANS_TOLOWER:   return towlower( wc );\r
+        case _PDCLIB_WCTRANS_TOUPPER:   return towupper( wc );\r
+        default: abort();\r
+    }\r
+}\r
+\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    TESTCASE(towctrans(L'a', wctrans("toupper")) == L'A');\r
+    TESTCASE(towctrans(L'B', wctrans("toupper")) == L'B');\r
+    TESTCASE(towctrans(L'a', wctrans("tolower")) == L'a');\r
+    TESTCASE(towctrans(L'B', wctrans("tolower")) == L'b');\r
+    TESTCASE(towctrans(L'B', wctrans("invalid")) == L'B');\r
+    TESTCASE(towctrans(L'B', 0)                  == L'B');\r
+    return TEST_RESULTS;\r
+}\r
+#endif\r
diff --git a/functions/wctype/wctrans.c b/functions/wctype/wctrans.c
new file mode 100644 (file)
index 0000000..31f36be
--- /dev/null
@@ -0,0 +1,38 @@
+/* wctrans( const char * )\r
+\r
+   This file is part of the Public Domain C Library (PDCLib).\r
+   Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+#include <wctype.h>\r
+#ifndef REGTEST\r
+#include <string.h>\r
+#include <_PDCLIB_locale.h>\r
+\r
+wctrans_t wctrans( const char * property )\r
+{\r
+    if(!property) {\r
+        return 0;\r
+    } else if(strcmp(property, "tolower") == 0) {\r
+        return _PDCLIB_WCTRANS_TOLOWER;\r
+    } else if(strcmp(property, "toupper") == 0) {\r
+        return _PDCLIB_WCTRANS_TOUPPER;\r
+    } else {\r
+        return 0;\r
+    }\r
+}\r
+\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+    TESTCASE(wctrans("") == 0);\r
+    TESTCASE(wctrans("invalid") == 0);\r
+    TESTCASE(wctrans("toupper") != 0);\r
+    TESTCASE(wctrans("tolower") != 0);\r
+    return TEST_RESULTS;\r
+}\r
+#endif\r
index dbedc8093e1829b1ed32e1c956aeca2573483830..3b2deced51b3f519eb01ed49f1a325da69183955 100644 (file)
@@ -59,6 +59,9 @@
 #define _PDCLIB_CTYPE_DIGIT 256
 #define _PDCLIB_CTYPE_XDIGT 512
 
+#define _PDCLIB_WCTRANS_TOLOWER 1
+#define _PDCLIB_WCTRANS_TOUPPER 2
+
 typedef struct _PDCLIB_ctype
 {
     _PDCLIB_uint16_t flags;