ソースを参照

LibC: Implement wctrans

Tim Schumacher 3 年 前
コミット
ff0ab8b9a9
2 ファイル変更25 行追加3 行削除
  1. 11 0
      Tests/LibC/TestWctype.cpp
  2. 14 3
      Userland/Libraries/LibC/wctype.cpp

+ 11 - 0
Tests/LibC/TestWctype.cpp

@@ -28,3 +28,14 @@ TEST_CASE(wctype)
     EXPECT(wctype("") == 0);
     EXPECT(wctype("") == 0);
     EXPECT(wctype("abc") == 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);
+}

+ 14 - 3
Userland/Libraries/LibC/wctype.cpp

@@ -24,6 +24,12 @@ enum {
     WCTYPE_XDIGIT,
     WCTYPE_XDIGIT,
 };
 };
 
 
+enum {
+    WCTRANS_INVALID = 0,
+    WCTRANS_TOLOWER,
+    WCTRANS_TOUPPER,
+};
+
 extern "C" {
 extern "C" {
 
 
 int iswalnum(wint_t wc)
 int iswalnum(wint_t wc)
@@ -149,9 +155,14 @@ wint_t towctrans(wint_t, wctrans_t)
     TODO();
     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;
 }
 }
 }
 }