mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:24:57 +00:00
AK: Remove the ctype adapters and use the actual ctype functions instead
This finally takes care of the kind-of excessive boilerplate code that were the ctype adapters. On the other hand, I had to link `LibC/ctype.cpp` to the Kernel (for `AK/JsonParser.cpp` and `AK/Format.cpp`). The previous commit actually makes sense now: the `string.h` includes in `ctype.{h,cpp}` would require to link more LibC stuff to the Kernel when it only needs the `_ctype_` array of `ctype.cpp`, and there wasn't any string stuff used in ctype. Instead of all this I could have put static derivatives of `is_any_of()` in the concerned AK files, however that would have meant more boilerplate and workarounds; so I went for the Kernel approach.
This commit is contained in:
parent
f158cb27ea
commit
f0f6b09acb
8 changed files with 33 additions and 125 deletions
|
@ -188,7 +188,7 @@ StringView GenericLexer::consume_until(const char* stop)
|
|||
*/
|
||||
StringView GenericLexer::consume_quoted_string(char escape_char)
|
||||
{
|
||||
if (!is_quote(peek()))
|
||||
if (!next_is(is_quote))
|
||||
return {};
|
||||
|
||||
char quote_char = consume();
|
||||
|
@ -264,75 +264,4 @@ void GenericLexer::ignore_until(const char* stop)
|
|||
ignore(__builtin_strlen(stop));
|
||||
}
|
||||
|
||||
// CType adapters
|
||||
bool is_alpha(char c)
|
||||
{
|
||||
return is_lowercase(c) || is_uppercase(c);
|
||||
}
|
||||
|
||||
bool is_alphanum(char c)
|
||||
{
|
||||
return is_alpha(c) || is_digit(c);
|
||||
}
|
||||
|
||||
bool is_control(char c)
|
||||
{
|
||||
return (c >= 0 && c <= 31) || c == 127;
|
||||
}
|
||||
|
||||
bool is_digit(char c)
|
||||
{
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
bool is_graphic(char c)
|
||||
{
|
||||
return c > ' ' && c <= '~';
|
||||
}
|
||||
|
||||
bool is_hex_digit(char c)
|
||||
{
|
||||
return is_digit(c)
|
||||
|| (c >= 'A' && c <= 'F')
|
||||
|| (c >= 'a' && c <= 'f');
|
||||
}
|
||||
|
||||
bool is_lowercase(char c)
|
||||
{
|
||||
return c >= 'a' && c <= 'z';
|
||||
}
|
||||
|
||||
bool is_path_separator(char c)
|
||||
{
|
||||
return c == '/' || c == '\\';
|
||||
}
|
||||
|
||||
bool is_printable(char c)
|
||||
{
|
||||
return c >= ' ' && c <= '~';
|
||||
}
|
||||
|
||||
bool is_punctuation(char c)
|
||||
{
|
||||
return (c >= '!' && c <= '/')
|
||||
|| (c >= ':' && c <= '@')
|
||||
|| (c >= '[' && c <= '`')
|
||||
|| (c >= '{' && c <= '~');
|
||||
}
|
||||
|
||||
bool is_quote(char c)
|
||||
{
|
||||
return c == '\'' || c == '"';
|
||||
}
|
||||
|
||||
bool is_uppercase(char c)
|
||||
{
|
||||
return c >= 'A' && c <= 'Z';
|
||||
}
|
||||
|
||||
bool is_whitespace(char c)
|
||||
{
|
||||
return (c >= '\t' && c <= '\r') || c == ' ';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue