mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-11 05:32:59 +00:00
LibUnicode: Add public methods to compare and lookup Unicode properties
Adds methods to retrieve a Unicode property from a string and to check if a code point matches a Unicode property. Also adds a <LibUnicode/Forward.h> header.
This commit is contained in:
parent
3f80791ed5
commit
f1809db994
Notes:
sideshowbarker
2024-07-18 07:43:51 +09:00
Author: https://github.com/trflynn89
Commit: f1809db994
Pull-request: https://github.com/SerenityOS/serenity/pull/9090
Reviewed-by: https://github.com/Dexesttp
Reviewed-by: https://github.com/davidot
Reviewed-by: https://github.com/linusg
4 changed files with 92 additions and 9 deletions
|
@ -404,6 +404,7 @@ constexpr @name@ operator|(@name@ value1, @name@ value2)
|
|||
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibUnicode/Forward.h>
|
||||
|
||||
namespace Unicode {
|
||||
)~~~");
|
||||
|
@ -411,7 +412,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, {}, move(unicode_data.general_categories));
|
||||
generate_enum("Property"sv, "Assigned"sv, unicode_data.prop_list.keys(), move(unicode_data.prop_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());
|
||||
|
||||
generator.append(R"~~~(
|
||||
|
@ -469,7 +470,12 @@ struct UnicodeData {
|
|||
WordBreakProperty word_break_property { WordBreakProperty::Other };
|
||||
};
|
||||
|
||||
namespace Detail {
|
||||
|
||||
Optional<UnicodeData> unicode_data_for_code_point(u32 code_point);
|
||||
Optional<Property> property_from_string(StringView const& property);
|
||||
|
||||
}
|
||||
|
||||
})~~~");
|
||||
|
||||
|
@ -489,6 +495,7 @@ static void generate_unicode_data_implementation(UnicodeData unicode_data)
|
|||
#include <AK/Array.h>
|
||||
#include <AK/CharacterTypes.h>
|
||||
#include <AK/Find.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibUnicode/UnicodeData.h>
|
||||
|
||||
namespace Unicode {
|
||||
|
@ -597,6 +604,8 @@ static Optional<u32> index_of_code_point_in_range(u32 code_point)
|
|||
return {};
|
||||
}
|
||||
|
||||
namespace Detail {
|
||||
|
||||
Optional<UnicodeData> unicode_data_for_code_point(u32 code_point)
|
||||
{
|
||||
VERIFY(is_unicode(code_point));
|
||||
|
@ -618,6 +627,30 @@ Optional<UnicodeData> unicode_data_for_code_point(u32 code_point)
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<Property> property_from_string(StringView const& property)
|
||||
{
|
||||
if (property == "Assigned"sv)
|
||||
return Property::Assigned;)~~~");
|
||||
|
||||
for (auto const& property : unicode_data.prop_list) {
|
||||
generator.set("property", property.key);
|
||||
generator.append(R"~~~(
|
||||
if (property == "@property@"sv)
|
||||
return Property::@property@;)~~~");
|
||||
}
|
||||
for (auto const& alias : unicode_data.prop_aliases) {
|
||||
generator.set("property", alias.alias);
|
||||
generator.append(R"~~~(
|
||||
if (property == "@property@"sv)
|
||||
return Property::@property@;)~~~");
|
||||
}
|
||||
|
||||
generator.append(R"~~~(
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})~~~");
|
||||
|
||||
outln("{}", generator.as_string_view());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue