1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:34:57 +00:00

Everywhere: Replace ctype.h to avoid narrowing conversions

This replaces ctype.h with CharacterType.h everywhere I could find
issues with narrowing conversions. While using it will probably make
sense almost everywhere in the future, the most critical places should
have been addressed.
This commit is contained in:
Max Wipfli 2021-06-01 21:18:08 +02:00 committed by Andreas Kling
parent 1c9d87c455
commit bc8d16ad28
16 changed files with 153 additions and 266 deletions

View file

@ -5,6 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/CharacterTypes.h>
#include <AK/Debug.h>
#include <AK/LexicalPath.h>
#include <AK/StringBuilder.h>
@ -14,26 +15,6 @@
namespace AK {
constexpr bool is_ascii_alpha(u32 code_point)
{
return ('a' <= code_point && code_point <= 'z') || ('A' <= code_point && code_point <= 'Z');
}
constexpr bool is_ascii_digit(u32 code_point)
{
return '0' <= code_point && code_point <= '9';
}
constexpr bool is_ascii_alphanumeric(u32 code_point)
{
return is_ascii_alpha(code_point) || is_ascii_digit(code_point);
}
constexpr bool is_ascii_hex_digit(u32 code_point)
{
return is_ascii_digit(code_point) || (code_point >= 'a' && code_point <= 'f') || (code_point >= 'A' && code_point <= 'F');
}
// FIXME: It could make sense to force users of URL to use URLParser::parse() explicitly instead of using a constructor.
URL::URL(StringView const& string)
: URL(URLParser::parse({}, string))
@ -403,17 +384,6 @@ String URL::percent_encode(StringView const& input, URL::PercentEncodeSet set)
return builder.to_string();
}
constexpr u8 parse_hex_digit(u8 digit)
{
if (digit >= '0' && digit <= '9')
return digit - '0';
if (digit >= 'a' && digit <= 'f')
return digit - 'a' + 10;
if (digit >= 'A' && digit <= 'F')
return digit - 'A' + 10;
VERIFY_NOT_REACHED();
}
String URL::percent_decode(StringView const& input)
{
if (!input.contains('%'))
@ -427,9 +397,9 @@ String URL::percent_decode(StringView const& input)
builder.append_code_point(*it);
} else {
++it;
u8 byte = parse_hex_digit(*it) << 4;
u8 byte = parse_ascii_hex_digit(*it) << 4;
++it;
byte += parse_hex_digit(*it);
byte += parse_ascii_hex_digit(*it);
builder.append(byte);
}
}