From ff0ab8b9a96ab784d9cd077b5f8e105492e55b9b Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Fri, 17 Sep 2021 18:19:09 +0200 Subject: [PATCH] LibC: Implement wctrans --- Tests/LibC/TestWctype.cpp | 11 +++++++++++ Userland/Libraries/LibC/wctype.cpp | 17 ++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Tests/LibC/TestWctype.cpp b/Tests/LibC/TestWctype.cpp index 190d152f6d..401ce66635 100644 --- a/Tests/LibC/TestWctype.cpp +++ b/Tests/LibC/TestWctype.cpp @@ -28,3 +28,14 @@ TEST_CASE(wctype) EXPECT(wctype("") == 0); EXPECT(wctype("abc") == 0); } + +TEST_CASE(wctrans) +{ + // Test that existing character mappings return non-zero wctrans values. + EXPECT(wctrans("tolower") != 0); + EXPECT(wctrans("toupper") != 0); + + // Test that invalid character mappings return the "invalid" wctrans value (0). + EXPECT(wctrans("") == 0); + EXPECT(wctrans("abc") == 0); +} diff --git a/Userland/Libraries/LibC/wctype.cpp b/Userland/Libraries/LibC/wctype.cpp index 10830c0c00..083e8e75da 100644 --- a/Userland/Libraries/LibC/wctype.cpp +++ b/Userland/Libraries/LibC/wctype.cpp @@ -24,6 +24,12 @@ enum { WCTYPE_XDIGIT, }; +enum { + WCTRANS_INVALID = 0, + WCTRANS_TOLOWER, + WCTRANS_TOUPPER, +}; + extern "C" { int iswalnum(wint_t wc) @@ -149,9 +155,14 @@ wint_t towctrans(wint_t, wctrans_t) TODO(); } -wctrans_t wctrans(const char*) +wctrans_t wctrans(const char* charclass) { - dbgln("FIXME: Implement wctrans()"); - TODO(); + if (strcmp(charclass, "tolower") == 0) + return WCTRANS_TOLOWER; + + if (strcmp(charclass, "toupper") == 0) + return WCTRANS_TOUPPER; + + return WCTRANS_INVALID; } }