mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibC: Implement wctype
This commit is contained in:
parent
ac406c8d0e
commit
7b17230d7a
Notes:
sideshowbarker
2024-07-18 03:44:57 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/7b17230d7ae Pull-request: https://github.com/SerenityOS/serenity/pull/10097 Reviewed-by: https://github.com/bgianfo ✅
3 changed files with 86 additions and 3 deletions
|
@ -15,6 +15,7 @@ set(TEST_SOURCES
|
|||
TestStackSmash.cpp
|
||||
TestStrlcpy.cpp
|
||||
TestStrtodAccuracy.cpp
|
||||
TestWctype.cpp
|
||||
)
|
||||
|
||||
set_source_files_properties(TestStrtodAccuracy.cpp PROPERTIES COMPILE_FLAGS "-fno-builtin-strtod")
|
||||
|
|
30
Tests/LibC/TestWctype.cpp
Normal file
30
Tests/LibC/TestWctype.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2021, the SerenityOS developers
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestCase.h>
|
||||
|
||||
#include <wctype.h>
|
||||
|
||||
TEST_CASE(wctype)
|
||||
{
|
||||
// Test that existing properties return non-zero wctypes.
|
||||
EXPECT(wctype("alnum") != 0);
|
||||
EXPECT(wctype("alpha") != 0);
|
||||
EXPECT(wctype("blank") != 0);
|
||||
EXPECT(wctype("cntrl") != 0);
|
||||
EXPECT(wctype("digit") != 0);
|
||||
EXPECT(wctype("graph") != 0);
|
||||
EXPECT(wctype("lower") != 0);
|
||||
EXPECT(wctype("print") != 0);
|
||||
EXPECT(wctype("punct") != 0);
|
||||
EXPECT(wctype("space") != 0);
|
||||
EXPECT(wctype("upper") != 0);
|
||||
EXPECT(wctype("xdigit") != 0);
|
||||
|
||||
// Test that invalid properties return the "invalid" wctype (0).
|
||||
EXPECT(wctype("") == 0);
|
||||
EXPECT(wctype("abc") == 0);
|
||||
}
|
|
@ -5,8 +5,25 @@
|
|||
*/
|
||||
|
||||
#include <AK/Format.h>
|
||||
#include <string.h>
|
||||
#include <wctype.h>
|
||||
|
||||
enum {
|
||||
WCTYPE_INVALID = 0,
|
||||
WCTYPE_ALNUM,
|
||||
WCTYPE_ALPHA,
|
||||
WCTYPE_BLANK,
|
||||
WCTYPE_CNTRL,
|
||||
WCTYPE_DIGIT,
|
||||
WCTYPE_GRAPH,
|
||||
WCTYPE_LOWER,
|
||||
WCTYPE_PRINT,
|
||||
WCTYPE_PUNCT,
|
||||
WCTYPE_SPACE,
|
||||
WCTYPE_UPPER,
|
||||
WCTYPE_XDIGIT,
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
||||
int iswalnum(wint_t wc)
|
||||
|
@ -75,10 +92,45 @@ int iswctype(wint_t, wctype_t)
|
|||
TODO();
|
||||
}
|
||||
|
||||
wctype_t wctype(const char*)
|
||||
wctype_t wctype(const char* property)
|
||||
{
|
||||
dbgln("FIXME: Implement wctype()");
|
||||
TODO();
|
||||
if (strcmp(property, "alnum") == 0)
|
||||
return WCTYPE_ALNUM;
|
||||
|
||||
if (strcmp(property, "alpha") == 0)
|
||||
return WCTYPE_ALPHA;
|
||||
|
||||
if (strcmp(property, "blank") == 0)
|
||||
return WCTYPE_BLANK;
|
||||
|
||||
if (strcmp(property, "cntrl") == 0)
|
||||
return WCTYPE_CNTRL;
|
||||
|
||||
if (strcmp(property, "digit") == 0)
|
||||
return WCTYPE_DIGIT;
|
||||
|
||||
if (strcmp(property, "graph") == 0)
|
||||
return WCTYPE_GRAPH;
|
||||
|
||||
if (strcmp(property, "lower") == 0)
|
||||
return WCTYPE_LOWER;
|
||||
|
||||
if (strcmp(property, "print") == 0)
|
||||
return WCTYPE_PRINT;
|
||||
|
||||
if (strcmp(property, "punct") == 0)
|
||||
return WCTYPE_PUNCT;
|
||||
|
||||
if (strcmp(property, "space") == 0)
|
||||
return WCTYPE_SPACE;
|
||||
|
||||
if (strcmp(property, "upper") == 0)
|
||||
return WCTYPE_UPPER;
|
||||
|
||||
if (strcmp(property, "xdigit") == 0)
|
||||
return WCTYPE_XDIGIT;
|
||||
|
||||
return WCTYPE_INVALID;
|
||||
}
|
||||
|
||||
wint_t towlower(wint_t wc)
|
||||
|
|
Loading…
Reference in a new issue