diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-07-31 16:38:24 -0400 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-08-02 21:02:09 +0430 |
commit | 5de6d3dd9050fca8c68851d125efb4737aba18cd (patch) | |
tree | 64b19a2fbbbb159a26265ae303279459191ef62d /Userland/Libraries/LibUnicode/CodeGenerators | |
parent | f63287cd63a9c713b369248f22214fa1345fdf70 (diff) | |
download | serenity-5de6d3dd9050fca8c68851d125efb4737aba18cd.zip |
LibUnicode: Add public methods to compare and lookup General Categories
Adds methods to retrieve a General Category from a string and to check
if a code point matches a General Category.
Diffstat (limited to 'Userland/Libraries/LibUnicode/CodeGenerators')
-rw-r--r-- | Userland/Libraries/LibUnicode/CodeGenerators/GenerateUnicodeData.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/Userland/Libraries/LibUnicode/CodeGenerators/GenerateUnicodeData.cpp b/Userland/Libraries/LibUnicode/CodeGenerators/GenerateUnicodeData.cpp index de18f2adba..f18dec6518 100644 --- a/Userland/Libraries/LibUnicode/CodeGenerators/GenerateUnicodeData.cpp +++ b/Userland/Libraries/LibUnicode/CodeGenerators/GenerateUnicodeData.cpp @@ -478,7 +478,7 @@ namespace Unicode { generate_enum("Locale"sv, "None"sv, move(unicode_data.locales)); generate_enum("Condition"sv, "None"sv, move(unicode_data.conditions)); - generate_enum("GeneralCategory"sv, "None"sv, move(unicode_data.general_categories), move(unicode_data.general_category_unions), move(unicode_data.general_category_aliases), true); + generate_enum("GeneralCategory"sv, "None"sv, unicode_data.general_categories, unicode_data.general_category_unions, unicode_data.general_category_aliases, true); generate_enum("Property"sv, "Assigned"sv, unicode_data.prop_list.keys(), {}, unicode_data.prop_aliases, true); generate_enum("WordBreakProperty"sv, "Other"sv, unicode_data.word_break_prop_list.keys()); @@ -541,6 +541,7 @@ namespace Detail { Optional<UnicodeData> unicode_data_for_code_point(u32 code_point); Optional<Property> property_from_string(StringView const& property); +Optional<GeneralCategory> general_category_from_string(StringView const& general_category); } @@ -716,6 +717,32 @@ Optional<Property> property_from_string(StringView const& property) return {}; } +Optional<GeneralCategory> general_category_from_string(StringView const& general_category) +{)~~~"); + + for (auto const& general_category : unicode_data.general_categories) { + generator.set("general_category", general_category); + generator.append(R"~~~( + if (general_category == "@general_category@"sv) + return GeneralCategory::@general_category@;)~~~"); + } + for (auto const& union_ : unicode_data.general_category_unions) { + generator.set("general_category", union_.alias); + generator.append(R"~~~( + if (general_category == "@general_category@"sv) + return GeneralCategory::@general_category@;)~~~"); + } + for (auto const& alias : unicode_data.general_category_aliases) { + generator.set("general_category", alias.alias); + generator.append(R"~~~( + if (general_category == "@general_category@"sv) + return GeneralCategory::@general_category@;)~~~"); + } + + generator.append(R"~~~( + return {}; +} + } })~~~"); |