mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
AK: Add CharacterTypes::is_ascii_base36_digit()
This can be used to validate the string passed to `parse_ascii_base36_digit()`.
This commit is contained in:
parent
bbdbd71439
commit
65827826fe
Notes:
sideshowbarker
2024-07-17 05:58:46 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/65827826fe Pull-request: https://github.com/SerenityOS/serenity/pull/22726 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/LucasChollet ✅
@ -45,6 +45,11 @@ constexpr bool is_ascii_alphanumeric(u32 code_point)
|
||||
return is_ascii_alpha(code_point) || is_ascii_digit(code_point);
|
||||
}
|
||||
|
||||
constexpr bool is_ascii_base36_digit(u32 code_point)
|
||||
{
|
||||
return is_ascii_digit(code_point) || (code_point >= 'A' && code_point <= 'Z') || (code_point >= 'a' && code_point <= 'z');
|
||||
}
|
||||
|
||||
constexpr bool is_ascii_binary_digit(u32 code_point)
|
||||
{
|
||||
return code_point == '0' || code_point == '1';
|
||||
@ -176,6 +181,7 @@ constexpr u32 to_ascii_base36_digit(u32 digit)
|
||||
using AK::is_ascii;
|
||||
using AK::is_ascii_alpha;
|
||||
using AK::is_ascii_alphanumeric;
|
||||
using AK::is_ascii_base36_digit;
|
||||
using AK::is_ascii_binary_digit;
|
||||
using AK::is_ascii_blank;
|
||||
using AK::is_ascii_c0_control;
|
||||
|
@ -67,6 +67,17 @@ TEST_CASE(is_ascii_alphanumeric)
|
||||
compare_bool_output_over(ASCII, isalnum, is_ascii_alphanumeric);
|
||||
}
|
||||
|
||||
TEST_CASE(is_ascii_base36_digit)
|
||||
{
|
||||
constexpr Array valid_base36_digits { '0', '9', 'A', 'Z', 'a', 'z' };
|
||||
for (auto valid_base36_digit : valid_base36_digits)
|
||||
EXPECT_EQ(is_ascii_base36_digit(valid_base36_digit), true);
|
||||
|
||||
constexpr Array invalid_base36_digits { '/', ':', '@', '[', '`', '{' };
|
||||
for (auto invalid_base36_digit : invalid_base36_digits)
|
||||
EXPECT_EQ(is_ascii_base36_digit(invalid_base36_digit), false);
|
||||
}
|
||||
|
||||
TEST_CASE(is_ascii_blank)
|
||||
{
|
||||
compare_bool_output_over(ASCII, isblank, is_ascii_blank);
|
||||
|
Loading…
Reference in New Issue
Block a user