From 926aa238ab315aedc713e21ee234f4e18bce6f6d Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 10 May 2023 23:13:56 +0300 Subject: [PATCH] LibC: add toupper, tolower in ctype.h --- libc/ctype.cpp | 14 ++++++++++++++ libc/include/ctype.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/libc/ctype.cpp b/libc/ctype.cpp index db096439..67744fa4 100644 --- a/libc/ctype.cpp +++ b/libc/ctype.cpp @@ -64,3 +64,17 @@ int isxdigit(int c) { return isdigit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F'); } + +int toupper(int c) +{ + if (!islower(c)) + return c; + return 'A' + (c - 'a'); +} + +int tolower(int c) +{ + if (!isupper(c)) + return c; + return 'a' + (c - 'A'); +} diff --git a/libc/include/ctype.h b/libc/include/ctype.h index d2672fae..e569165c 100644 --- a/libc/include/ctype.h +++ b/libc/include/ctype.h @@ -18,4 +18,7 @@ int isspace(int); int isupper(int); int isxdigit(int); +int toupper(int); +int tolower(int); + __END_DECLS \ No newline at end of file