diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-09-02 21:49:24 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-09-04 13:51:40 +0100 |
commit | ca90231794e4e230ae6a0d8c428c0ef5ea289425 (patch) | |
tree | 811b4de2cefd36d3927515ac22ec0cb123156cc5 /Userland | |
parent | 74ce098d580c9751897fc6d76de411c8a7a1e231 (diff) | |
download | serenity-ca90231794e4e230ae6a0d8c428c0ef5ea289425.zip |
LibUnicode: Define is_unicode_*_subtag helpers inline in their header
The UnicodeLocale generator will need to parse canonicalized locale
strings, and will require using these methods. However, the generator
cannot depend on LibUnicode because Locale.cpp within LibUnicode already
depends on the generated file. Instead, defining the methods that the
generator needs inline allows the generator to use them without linking
against LibUnicode.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibUnicode/Locale.cpp | 37 | ||||
-rw-r--r-- | Userland/Libraries/LibUnicode/Locale.h | 41 |
2 files changed, 37 insertions, 41 deletions
diff --git a/Userland/Libraries/LibUnicode/Locale.cpp b/Userland/Libraries/LibUnicode/Locale.cpp index 4794523977..8990f65e04 100644 --- a/Userland/Libraries/LibUnicode/Locale.cpp +++ b/Userland/Libraries/LibUnicode/Locale.cpp @@ -5,7 +5,6 @@ */ #include <AK/AllOf.h> -#include <AK/CharacterTypes.h> #include <AK/GenericLexer.h> #include <AK/QuickSort.h> #include <AK/StringBuilder.h> @@ -17,42 +16,6 @@ namespace Unicode { -bool is_unicode_language_subtag(StringView subtag) -{ - // unicode_language_subtag = alpha{2,3} | alpha{5,8} - if ((subtag.length() < 2) || (subtag.length() == 4) || (subtag.length() > 8)) - return false; - return all_of(subtag, is_ascii_alpha); -} - -bool is_unicode_script_subtag(StringView subtag) -{ - // unicode_script_subtag = alpha{4} - if (subtag.length() != 4) - return false; - return all_of(subtag, is_ascii_alpha); -} - -bool is_unicode_region_subtag(StringView subtag) -{ - // unicode_region_subtag = (alpha{2} | digit{3}) - if (subtag.length() == 2) - return all_of(subtag, is_ascii_alpha); - if (subtag.length() == 3) - return all_of(subtag, is_ascii_digit); - return false; -} - -bool is_unicode_variant_subtag(StringView subtag) -{ - // unicode_variant_subtag = (alphanum{5,8} | digit alphanum{3}) - if ((subtag.length() >= 5) && (subtag.length() <= 8)) - return all_of(subtag, is_ascii_alphanumeric); - if (subtag.length() == 4) - return is_ascii_digit(subtag[0]) && all_of(subtag.substring_view(1), is_ascii_alphanumeric); - return false; -} - static bool is_key(StringView key) { // key = alphanum alpha diff --git a/Userland/Libraries/LibUnicode/Locale.h b/Userland/Libraries/LibUnicode/Locale.h index 72eebf2e3d..7435ba8ca2 100644 --- a/Userland/Libraries/LibUnicode/Locale.h +++ b/Userland/Libraries/LibUnicode/Locale.h @@ -6,6 +6,7 @@ #pragma once +#include <AK/CharacterTypes.h> #include <AK/Optional.h> #include <AK/String.h> #include <AK/StringView.h> @@ -73,10 +74,42 @@ struct LocaleID { // Note: These methods only verify that the provided strings match the EBNF grammar of the // Unicode identifier subtag (i.e. no validation is done that the tags actually exist). -bool is_unicode_language_subtag(StringView); -bool is_unicode_script_subtag(StringView); -bool is_unicode_region_subtag(StringView); -bool is_unicode_variant_subtag(StringView); +constexpr bool is_unicode_language_subtag(StringView subtag) +{ + // unicode_language_subtag = alpha{2,3} | alpha{5,8} + if ((subtag.length() < 2) || (subtag.length() == 4) || (subtag.length() > 8)) + return false; + return all_of(subtag, is_ascii_alpha); +} + +constexpr bool is_unicode_script_subtag(StringView subtag) +{ + // unicode_script_subtag = alpha{4} + if (subtag.length() != 4) + return false; + return all_of(subtag, is_ascii_alpha); +} + +constexpr bool is_unicode_region_subtag(StringView subtag) +{ + // unicode_region_subtag = (alpha{2} | digit{3}) + if (subtag.length() == 2) + return all_of(subtag, is_ascii_alpha); + if (subtag.length() == 3) + return all_of(subtag, is_ascii_digit); + return false; +} + +constexpr bool is_unicode_variant_subtag(StringView subtag) +{ + // unicode_variant_subtag = (alphanum{5,8} | digit alphanum{3}) + if ((subtag.length() >= 5) && (subtag.length() <= 8)) + return all_of(subtag, is_ascii_alphanumeric); + if (subtag.length() == 4) + return is_ascii_digit(subtag[0]) && all_of(subtag.substring_view(1), is_ascii_alphanumeric); + return false; +} + bool is_type_identifier(StringView); Optional<LanguageID> parse_unicode_language_id(StringView); |