diff --git a/libc/Makefile b/libc/Makefile
index 54a65edc..09ef93ea 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -228,6 +228,21 @@ wchar/wmemcmp.o \
wchar/wmemcpy.o \
wchar/wmemmove.o \
wchar/wmemset.o \
+wctype/iswalnum.o \
+wctype/iswalpha.o \
+wctype/iswblank.o \
+wctype/iswcntrl.o \
+wctype/iswctype.o \
+wctype/iswdigit.o \
+wctype/iswgraph.o \
+wctype/iswlower.o \
+wctype/iswprint.o \
+wctype/iswpunct.o \
+wctype/iswspace.o \
+wctype/iswupper.o \
+wctype/iswxdigit.o \
+wctype/towlower.o \
+wctype/towupper.o \
wctype/wctype.o \
HOSTEDOBJS=\
diff --git a/libc/wctype/iswalnum.cpp b/libc/wctype/iswalnum.cpp
new file mode 100644
index 00000000..9c278b65
--- /dev/null
+++ b/libc/wctype/iswalnum.cpp
@@ -0,0 +1,30 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/iswalnum.cpp
+ Returns whether the wide character is alphabetical or a digit.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int iswalnum(wint_t c)
+{
+ return iswalpha(c) || iswdigit(c);
+}
diff --git a/libc/wctype/iswalpha.cpp b/libc/wctype/iswalpha.cpp
new file mode 100644
index 00000000..ca2edb20
--- /dev/null
+++ b/libc/wctype/iswalpha.cpp
@@ -0,0 +1,30 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/iswalpha.cpp
+ Returns whether the wide character is alphabetical.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int iswalpha(wint_t c)
+{
+ return iswupper(c) || iswlower(c);
+}
diff --git a/libc/wctype/iswblank.cpp b/libc/wctype/iswblank.cpp
new file mode 100644
index 00000000..182230f9
--- /dev/null
+++ b/libc/wctype/iswblank.cpp
@@ -0,0 +1,30 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/iswblank.cpp
+ Returns whether the wide character is blank.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int iswblank(wint_t c)
+{
+ return c == L' ' || c == L'\t';
+}
diff --git a/libc/wctype/iswcntrl.cpp b/libc/wctype/iswcntrl.cpp
new file mode 100644
index 00000000..91b7e61f
--- /dev/null
+++ b/libc/wctype/iswcntrl.cpp
@@ -0,0 +1,30 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/iswcntrl.cpp
+ Returns whether the wide character is a control character.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int iswcntrl(wint_t c)
+{
+ return 0 <= c && c < 32;
+}
diff --git a/libc/wctype/iswctype.cpp b/libc/wctype/iswctype.cpp
new file mode 100644
index 00000000..a4b99474
--- /dev/null
+++ b/libc/wctype/iswctype.cpp
@@ -0,0 +1,30 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/iswctype.cpp
+ Returns whether the wide character belongs to the character class.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int iswctype(wint_t c, wctype_t wct)
+{
+ return wct(c);
+}
diff --git a/libc/wctype/iswdigit.cpp b/libc/wctype/iswdigit.cpp
new file mode 100644
index 00000000..8f60e056
--- /dev/null
+++ b/libc/wctype/iswdigit.cpp
@@ -0,0 +1,30 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/iswdigit.cpp
+ Returns whether the wide character is a digit.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int iswdigit(wint_t c)
+{
+ return L'0' <= c && c <= L'9';
+}
diff --git a/libc/wctype/iswgraph.cpp b/libc/wctype/iswgraph.cpp
new file mode 100644
index 00000000..e18c4c84
--- /dev/null
+++ b/libc/wctype/iswgraph.cpp
@@ -0,0 +1,30 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/iswgraph.cpp
+ Returns whether the wide character is graphical.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int iswgraph(wint_t c)
+{
+ return L'!' <= c && c <= L'~';
+}
diff --git a/libc/wctype/iswlower.cpp b/libc/wctype/iswlower.cpp
new file mode 100644
index 00000000..d744facd
--- /dev/null
+++ b/libc/wctype/iswlower.cpp
@@ -0,0 +1,30 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/iswlower.cpp
+ Returns whether the wide character is lower-case.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int iswlower(wint_t c)
+{
+ return L'a' <= c && c <= L'z';
+}
diff --git a/libc/wctype/iswprint.cpp b/libc/wctype/iswprint.cpp
new file mode 100644
index 00000000..009f6c0a
--- /dev/null
+++ b/libc/wctype/iswprint.cpp
@@ -0,0 +1,30 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/iswprint.cpp
+ Returns whether the wide character is printable.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int iswprint(wint_t c)
+{
+ return iswgraph(c) || c == L' ';
+}
diff --git a/libc/wctype/iswpunct.cpp b/libc/wctype/iswpunct.cpp
new file mode 100644
index 00000000..ca3dfaba
--- /dev/null
+++ b/libc/wctype/iswpunct.cpp
@@ -0,0 +1,30 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/iswpunct.cpp
+ Returns whether the wide character is punctuational.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int iswpunct(wint_t c)
+{
+ return iswprint(c) && c != L' ' && !iswalnum(c);
+}
diff --git a/libc/wctype/iswspace.cpp b/libc/wctype/iswspace.cpp
new file mode 100644
index 00000000..69bc763c
--- /dev/null
+++ b/libc/wctype/iswspace.cpp
@@ -0,0 +1,31 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/iswspace.cpp
+ Returns whether the wide character is white-space.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int iswspace(wint_t c)
+{
+ return c == L'\t' || c == L'\n' || c == L'\v' ||
+ c == L'\f' || c == L'\r' || c == L' ';
+}
diff --git a/libc/wctype/iswupper.cpp b/libc/wctype/iswupper.cpp
new file mode 100644
index 00000000..d46ff826
--- /dev/null
+++ b/libc/wctype/iswupper.cpp
@@ -0,0 +1,30 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/iswupper.cpp
+ Returns whether the wide character is upper-case.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int iswupper(wint_t c)
+{
+ return L'A' <= c && c <= L'Z';
+}
diff --git a/libc/wctype/iswxdigit.cpp b/libc/wctype/iswxdigit.cpp
new file mode 100644
index 00000000..240a816f
--- /dev/null
+++ b/libc/wctype/iswxdigit.cpp
@@ -0,0 +1,36 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/iswxdigit.cpp
+ Returns whether the wide character is a hexadecimal digit.
+
+*******************************************************************************/
+
+#include
+
+extern "C" int iswxdigit(wint_t c)
+{
+ if ( iswdigit(c) )
+ return 1;
+ if ( L'a' <= c && c <= L'f' )
+ return 1;
+ if ( L'A' <= c && c <= L'F' )
+ return 1;
+ return 0;
+}
diff --git a/libc/wctype/towlower.cpp b/libc/wctype/towlower.cpp
new file mode 100644
index 00000000..b8aa889e
--- /dev/null
+++ b/libc/wctype/towlower.cpp
@@ -0,0 +1,32 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/towlower.cpp
+ Converts the wide character to lower-case if it is upper-case.
+
+*******************************************************************************/
+
+#include
+
+extern "C" wint_t towlower(wint_t c)
+{
+ if ( L'A' <= c && c <= L'Z' )
+ return L'a' + c - L'A';
+ return c;
+}
diff --git a/libc/wctype/towupper.cpp b/libc/wctype/towupper.cpp
new file mode 100644
index 00000000..e2308492
--- /dev/null
+++ b/libc/wctype/towupper.cpp
@@ -0,0 +1,32 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wctype/towupper.cpp
+ Converts the wide character to upper-case if it is lower-case.
+
+*******************************************************************************/
+
+#include
+
+extern "C" wint_t towupper(wint_t c)
+{
+ if ( L'a' <= c && c <= L'z' )
+ return L'A' + c - L'a';
+ return c;
+}
diff --git a/libc/wctype/wctype.cpp b/libc/wctype/wctype.cpp
index 03491eff..24a63205 100644
--- a/libc/wctype/wctype.cpp
+++ b/libc/wctype/wctype.cpp
@@ -18,95 +18,13 @@
along with the Sortix C Library. If not, see .
wctype/wctype.cpp
- Character types.
+ Returns the character class description with the given name.
*******************************************************************************/
#include
#include
-// TODO: Support other locales than ASCII.
-
-extern "C" int iswalnum(wint_t c)
-{
- return iswalpha(c) || iswdigit(c);
-}
-
-extern "C" int iswalpha(wint_t c)
-{
- return iswupper(c) || iswlower(c);
-}
-
-extern "C" int iswblank(wint_t c)
-{
- return c == L' ' || c == L'\t';
-}
-
-extern "C" int iswcntrl(wint_t c)
-{
- return 0 <= c && c < 32;
-}
-
-extern "C" int iswdigit(wint_t c)
-{
- return L'0' <= c && c <= L'9';
-}
-
-extern "C" int iswgraph(wint_t c)
-{
- return L'!' <= c && c <= L'~';
-}
-
-extern "C" int iswlower(wint_t c)
-{
- return L'a' <= c && c <= L'z';
-}
-
-extern "C" int iswprint(wint_t c)
-{
- return iswgraph(c) || c == L' ';
-}
-
-extern "C" int iswpunct(wint_t c)
-{
- return iswprint(c) && c != L' ' && !iswalnum(c);
-}
-
-extern "C" int iswspace(wint_t c)
-{
- return c == L'\t' || c == L'\n' || c == L'\v' || c == L'\f' || c == L'\r' || c == L' ';
-}
-
-extern "C" int iswupper(wint_t c)
-{
- return L'A' <= c && c <= L'Z';
-}
-
-extern "C" int iswxdigit(wint_t c)
-{
- if ( iswdigit(c) ) { return 1; }
- if ( L'a' <= c && c <= L'f' ) { return 1; }
- if ( L'A' <= c && c <= L'F' ) { return 1; }
- return 0;
-}
-
-extern "C" wint_t towlower(wint_t c)
-{
- if ( L'A' <= c && c <= L'Z' ) { return L'a' + c - L'A'; }
- return c;
-}
-
-extern "C" wint_t towupper(wint_t c)
-{
- if ( L'a' <= c && c <= L'z' ) { return L'A' + c - L'a'; }
- return c;
-}
-
-extern "C" int iswctype(wint_t c, wctype_t wct)
-{
- return wct(c);
-}
-
extern "C" wctype_t wctype(const char *name)
{
if ( !strcmp(name, "alnum") ) return (wctype_t) iswalnum;
@@ -121,5 +39,5 @@ extern "C" wctype_t wctype(const char *name)
if ( !strcmp(name, "space") ) return (wctype_t) iswspace;
if ( !strcmp(name, "upper") ) return (wctype_t) iswupper;
if ( !strcmp(name, "xdigit") ) return (wctype_t) iswxdigit;
- return (wctype_t) 0;
+ return (wctype_t) NULL;
}