diff options
author | Tim Schumacher <timschumi@gmx.de> | 2021-09-17 18:30:25 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-09-17 22:59:51 +0000 |
commit | 42031f026a06e4aa3b9bbfca8cfe451a6e0f1e4a (patch) | |
tree | c26242164b9e88470cd62803fee11a46f36307cb | |
parent | 8c7b566629e3f8706580a73cc8da152879c9f9ef (diff) | |
download | serenity-42031f026a06e4aa3b9bbfca8cfe451a6e0f1e4a.zip |
LibC: Implement towctrans
-rw-r--r-- | Tests/LibC/TestWctype.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibC/wctype.cpp | 14 |
2 files changed, 28 insertions, 3 deletions
diff --git a/Tests/LibC/TestWctype.cpp b/Tests/LibC/TestWctype.cpp index ed1d7d0028..773cf5bc5c 100644 --- a/Tests/LibC/TestWctype.cpp +++ b/Tests/LibC/TestWctype.cpp @@ -66,3 +66,20 @@ TEST_CASE(iswctype) EXPECT(iswctype(test_chars[i], -1) == 0); } } + +TEST_CASE(towctrans) +{ + const wint_t test_chars[] = { L'A', L'a', L'F', L'f', L'Z', L'z', L'0', L'\n', L'.', L'\x00' }; + + // Test that valid mappings are wired to the correct implementation. + for (unsigned int i = 0; i < sizeof(test_chars) / sizeof(test_chars[0]); i++) { + EXPECT(towctrans(test_chars[i], wctrans("tolower")) == towlower(test_chars[i])); + EXPECT(towctrans(test_chars[i], wctrans("toupper")) == towupper(test_chars[i])); + } + + // Test that invalid mappings always return the character unchanged. + for (unsigned int i = 0; i < sizeof(test_chars) / sizeof(test_chars[0]); i++) { + EXPECT(towctrans(test_chars[i], 0) == test_chars[i]); + EXPECT(towctrans(test_chars[i], -1) == test_chars[i]); + } +} diff --git a/Userland/Libraries/LibC/wctype.cpp b/Userland/Libraries/LibC/wctype.cpp index 9bb3e4fc03..a43263bcf2 100644 --- a/Userland/Libraries/LibC/wctype.cpp +++ b/Userland/Libraries/LibC/wctype.cpp @@ -187,10 +187,18 @@ wint_t towupper(wint_t wc) return __inline_toupper(wc); } -wint_t towctrans(wint_t, wctrans_t) +wint_t towctrans(wint_t wc, wctrans_t desc) { - dbgln("FIXME: Implement towctrans()"); - TODO(); + switch (desc) { + case WCTRANS_TOLOWER: + return towlower(wc); + + case WCTRANS_TOUPPER: + return towupper(wc); + + default: + return wc; + } } wctrans_t wctrans(const char* charclass) |