mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:37:44 +00:00
LibC: Implement wctype
This commit is contained in:
parent
ac406c8d0e
commit
7b17230d7a
3 changed files with 86 additions and 3 deletions
|
@ -15,6 +15,7 @@ set(TEST_SOURCES
|
||||||
TestStackSmash.cpp
|
TestStackSmash.cpp
|
||||||
TestStrlcpy.cpp
|
TestStrlcpy.cpp
|
||||||
TestStrtodAccuracy.cpp
|
TestStrtodAccuracy.cpp
|
||||||
|
TestWctype.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set_source_files_properties(TestStrtodAccuracy.cpp PROPERTIES COMPILE_FLAGS "-fno-builtin-strtod")
|
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 <AK/Format.h>
|
||||||
|
#include <string.h>
|
||||||
#include <wctype.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" {
|
extern "C" {
|
||||||
|
|
||||||
int iswalnum(wint_t wc)
|
int iswalnum(wint_t wc)
|
||||||
|
@ -75,10 +92,45 @@ int iswctype(wint_t, wctype_t)
|
||||||
TODO();
|
TODO();
|
||||||
}
|
}
|
||||||
|
|
||||||
wctype_t wctype(const char*)
|
wctype_t wctype(const char* property)
|
||||||
{
|
{
|
||||||
dbgln("FIXME: Implement wctype()");
|
if (strcmp(property, "alnum") == 0)
|
||||||
TODO();
|
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)
|
wint_t towlower(wint_t wc)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue