1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 13:57:36 +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:
Benoît Lormeau 2020-09-27 12:44:03 +02:00 committed by Andreas Kling
parent f158cb27ea
commit f0f6b09acb
8 changed files with 33 additions and 125 deletions

View file

@ -35,6 +35,7 @@
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
#include <LibCore/ProcessStatisticsReader.h>
#include <ctype.h>
#include <stdio.h>
struct OpenFile {
@ -56,8 +57,8 @@ static bool parse_name(StringView name, OpenFile& file)
return true;
} else {
file.type = component1;
auto component2 = lexer.consume_while([](char c) { return is_printable(c) && !is_whitespace(c) && c != '('; });
lexer.ignore_while(is_whitespace);
auto component2 = lexer.consume_while([](char c) { return isprint(c) && !isspace(c) && c != '('; });
lexer.ignore_while(isspace);
file.name = component2;
if (lexer.tell_remaining() == 0) {

View file

@ -34,6 +34,7 @@
#include <LibCore/File.h>
#include <LibProtocol/Client.h>
#include <LibProtocol/Download.h>
#include <ctype.h>
#include <stdio.h>
// FIXME: Move this somewhere else when it's needed (e.g. in the Browser)
@ -43,7 +44,7 @@ public:
{
GenericLexer lexer(value);
lexer.ignore_while(is_whitespace);
lexer.ignore_while(isspace);
if (lexer.consume_specific("inline")) {
m_kind = Kind::Inline;
@ -55,7 +56,7 @@ public:
if (lexer.consume_specific("attachment")) {
m_kind = Kind::Attachment;
if (lexer.consume_specific(";")) {
lexer.ignore_while(is_whitespace);
lexer.ignore_while(isspace);
if (lexer.consume_specific("filename=")) {
// RFC 2183: "A short (length <= 78 characters)
// parameter value containing only non-`tspecials' characters SHOULD be
@ -77,7 +78,7 @@ public:
if (lexer.consume_specific("form-data")) {
m_kind = Kind::FormData;
while (lexer.consume_specific(";")) {
lexer.ignore_while(is_whitespace);
lexer.ignore_while(isspace);
if (lexer.consume_specific("name=")) {
m_name = lexer.consume_quoted_string();
} else if (lexer.consume_specific("filename=")) {