summaryrefslogtreecommitdiff
path: root/src/libc/ctype.c
diff options
context:
space:
mode:
authordzwdz2023-08-14 18:51:07 +0200
committerdzwdz2023-08-14 18:51:07 +0200
commit642b5fb0007b64c77d186fcb018d571152ee1d47 (patch)
tree1c466461f3602d306be309a053edae558ef2568e /src/libc/ctype.c
parent8050069c57b729c18c19b1a03ab6e4bf63b4735e (diff)
reorganization: first steps
Diffstat (limited to 'src/libc/ctype.c')
-rw-r--r--src/libc/ctype.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/libc/ctype.c b/src/libc/ctype.c
new file mode 100644
index 0000000..fa49a07
--- /dev/null
+++ b/src/libc/ctype.c
@@ -0,0 +1,65 @@
+#include <ctype.h>
+
+int isalnum(int c) {
+ return isalpha(c) || isdigit(c);
+}
+
+int isalpha(int c) {
+ return islower(c) || isupper(c);
+}
+
+int iscntrl(int c) {
+ return c <= 0x1f || c == 0x7f;
+}
+
+int isdigit(int c) {
+ return '0' <= c && c <= '9';
+}
+
+int isgraph(int c) {
+ return isalpha(c) || isdigit(c) || ispunct(c);
+}
+
+int islower(int c) {
+ return 'a' <= c && c <= 'z';
+}
+
+int isprint(int c) {
+ return isgraph(c) || c == ' ';
+}
+
+int ispunct(int c) {
+ return ('!' <= c && c <= '/')
+ || (':' <= c && c <= '@')
+ || ('[' <= c && c <= '`')
+ || ('{' <= c && c <= '~');
+}
+
+int isspace(int c) {
+ return c == ' '
+ || c == '\f'
+ || c == '\n'
+ || c == '\r'
+ || c == '\t'
+ || c == '\v';
+}
+
+int isupper(int c) {
+ return 'A' <= c && c <= 'Z';
+}
+
+int isxdigit(int c) {
+ return ('0' <= c && c <= '9')
+ || ('A' <= c && c <= 'F')
+ || ('a' <= c && c <= 'f');
+}
+
+int tolower(int c) {
+ if (isupper(c)) return c - 'A' + 'a';
+ return c;
+}
+
+int toupper(int c) {
+ if (islower(c)) return c - 'a' + 'A';
+ return c;
+}