summaryrefslogtreecommitdiff
path: root/userland/libc/ctype
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-22 19:50:38 +0200
committerAnton Kling <anton@kling.gg>2023-10-22 19:50:38 +0200
commit4e09bca9e34c226b6d7e34b4fa11248405fd988e (patch)
tree80f156b7940d9d19971395f335530170c69516c7 /userland/libc/ctype
Move everything into a new repo.
Diffstat (limited to 'userland/libc/ctype')
-rw-r--r--userland/libc/ctype/isalnum.c6
-rw-r--r--userland/libc/ctype/isalpha.c4
-rw-r--r--userland/libc/ctype/isascii.c4
-rw-r--r--userland/libc/ctype/isdigit.c6
-rw-r--r--userland/libc/ctype/isprint.c3
-rw-r--r--userland/libc/ctype/ispunct.c6
-rw-r--r--userland/libc/ctype/isxdigit.c6
-rw-r--r--userland/libc/ctype/tolower.c7
-rw-r--r--userland/libc/ctype/toupper.c7
9 files changed, 49 insertions, 0 deletions
diff --git a/userland/libc/ctype/isalnum.c b/userland/libc/ctype/isalnum.c
new file mode 100644
index 0000000..870728d
--- /dev/null
+++ b/userland/libc/ctype/isalnum.c
@@ -0,0 +1,6 @@
+#include <ctype.h>
+
+// This is probably the most useless libc function I have seen so far.
+int isalnum(int c) {
+ return isalpha(c) || isdigit(c);
+}
diff --git a/userland/libc/ctype/isalpha.c b/userland/libc/ctype/isalpha.c
new file mode 100644
index 0000000..130f493
--- /dev/null
+++ b/userland/libc/ctype/isalpha.c
@@ -0,0 +1,4 @@
+#include <ctype.h>
+
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/isalpha.html
+int isalpha(int c) { return (('A' <= toupper(c)) && ('Z' >= toupper(c))); }
diff --git a/userland/libc/ctype/isascii.c b/userland/libc/ctype/isascii.c
new file mode 100644
index 0000000..660c8bb
--- /dev/null
+++ b/userland/libc/ctype/isascii.c
@@ -0,0 +1,4 @@
+#include <ctype.h>
+
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/isascii.html
+int isascii(int c) { return (c < 128); }
diff --git a/userland/libc/ctype/isdigit.c b/userland/libc/ctype/isdigit.c
new file mode 100644
index 0000000..790b9f1
--- /dev/null
+++ b/userland/libc/ctype/isdigit.c
@@ -0,0 +1,6 @@
+#include <ctype.h>
+
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/isdigit.html
+int isdigit(int c) {
+ return ('0' <= c && c <= '9');
+}
diff --git a/userland/libc/ctype/isprint.c b/userland/libc/ctype/isprint.c
new file mode 100644
index 0000000..e6a3d0e
--- /dev/null
+++ b/userland/libc/ctype/isprint.c
@@ -0,0 +1,3 @@
+#include <ctype.h>
+
+int isprint(int c) { return c > 0x20 && 0x7F != c; }
diff --git a/userland/libc/ctype/ispunct.c b/userland/libc/ctype/ispunct.c
new file mode 100644
index 0000000..18dc7d8
--- /dev/null
+++ b/userland/libc/ctype/ispunct.c
@@ -0,0 +1,6 @@
+#include <ctype.h>
+
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/ispunct.html
+int ispunct(int c) {
+ return (c == '.');
+}
diff --git a/userland/libc/ctype/isxdigit.c b/userland/libc/ctype/isxdigit.c
new file mode 100644
index 0000000..c843725
--- /dev/null
+++ b/userland/libc/ctype/isxdigit.c
@@ -0,0 +1,6 @@
+#include <ctype.h>
+
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/isxdigit.html
+int isxdigit(int c) {
+ return isdigit(c) || ('A' >= toupper(c) && 'Z' <= toupper(c));
+}
diff --git a/userland/libc/ctype/tolower.c b/userland/libc/ctype/tolower.c
new file mode 100644
index 0000000..f1bb163
--- /dev/null
+++ b/userland/libc/ctype/tolower.c
@@ -0,0 +1,7 @@
+#include <ctype.h>
+
+int tolower(int c) {
+ if (c >= 'A' && c <= 'Z')
+ return c - 'A' + 'a';
+ return c;
+}
diff --git a/userland/libc/ctype/toupper.c b/userland/libc/ctype/toupper.c
new file mode 100644
index 0000000..0f33886
--- /dev/null
+++ b/userland/libc/ctype/toupper.c
@@ -0,0 +1,7 @@
+#include <ctype.h>
+
+int toupper(int c) {
+ if (c >= 'a' && c <= 'z')
+ return c - 'a' + 'A';
+ return c;
+}