mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +03:00
LibUnicode: Ensure UnicodeNumberFormat is aware of default content
For example, there isn't a unique set of data for the en-US locale;
rather, it defaults to the data for the en locale. See this commit for
much more detail: 357c97dfa8
This commit is contained in:
parent
9421d5c0cf
commit
e9493a2cd5
Notes:
sideshowbarker
2024-07-18 01:12:00 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/e9493a2cd54 Pull-request: https://github.com/SerenityOS/serenity/pull/10894 Reviewed-by: https://github.com/linusg ✅
@ -170,7 +170,7 @@ if (ENABLE_UNICODE_DATABASE_DOWNLOAD)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${UNICODE_NUMBER_FORMAT_HEADER} ${UNICODE_NUMBER_FORMAT_IMPLEMENTATION}
|
||||
COMMAND $<TARGET_FILE:Lagom::GenerateUnicodeNumberFormat> -h ${UNICODE_NUMBER_FORMAT_HEADER}.tmp -c ${UNICODE_NUMBER_FORMAT_IMPLEMENTATION}.tmp -n ${CLDR_NUMBERS_PATH}
|
||||
COMMAND $<TARGET_FILE:Lagom::GenerateUnicodeNumberFormat> -h ${UNICODE_NUMBER_FORMAT_HEADER}.tmp -c ${UNICODE_NUMBER_FORMAT_IMPLEMENTATION}.tmp -r ${CLDR_CORE_PATH} -n ${CLDR_NUMBERS_PATH}
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${UNICODE_NUMBER_FORMAT_HEADER}.tmp ${UNICODE_NUMBER_FORMAT_HEADER}
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${UNICODE_NUMBER_FORMAT_IMPLEMENTATION}.tmp ${UNICODE_NUMBER_FORMAT_IMPLEMENTATION}
|
||||
COMMAND "${CMAKE_COMMAND}" -E remove ${UNICODE_NUMBER_FORMAT_HEADER}.tmp ${UNICODE_NUMBER_FORMAT_IMPLEMENTATION}.tmp
|
||||
|
@ -401,39 +401,6 @@ static void parse_numeric_keywords(String locale_numbers_path, UnicodeLocaleData
|
||||
locale_data.keywords.append(key);
|
||||
}
|
||||
|
||||
static void parse_default_content_locales(String core_path, UnicodeLocaleData& locale_data)
|
||||
{
|
||||
LexicalPath default_content_path(move(core_path));
|
||||
default_content_path = default_content_path.append("defaultContent.json"sv);
|
||||
VERIFY(Core::File::exists(default_content_path.string()));
|
||||
|
||||
auto default_content_file_or_error = Core::File::open(default_content_path.string(), Core::OpenMode::ReadOnly);
|
||||
VERIFY(!default_content_file_or_error.is_error());
|
||||
|
||||
auto default_content = JsonParser(default_content_file_or_error.value()->read_all()).parse();
|
||||
VERIFY(default_content.has_value());
|
||||
|
||||
auto const& default_content_array = default_content->as_object().get("defaultContent"sv);
|
||||
|
||||
default_content_array.as_array().for_each([&](JsonValue const& value) {
|
||||
auto locale = value.as_string();
|
||||
StringView default_locale = locale;
|
||||
|
||||
while (true) {
|
||||
if (locale_data.locales.contains(default_locale))
|
||||
break;
|
||||
|
||||
auto pos = default_locale.find_last('-');
|
||||
if (!pos.has_value())
|
||||
return;
|
||||
|
||||
default_locale = default_locale.substring_view(0, *pos);
|
||||
}
|
||||
|
||||
locale_data.locales.set(locale, locale_data.locales.get(default_locale).value());
|
||||
});
|
||||
}
|
||||
|
||||
static void parse_all_locales(String core_path, String locale_names_path, String misc_path, String numbers_path, UnicodeLocaleData& locale_data)
|
||||
{
|
||||
auto identity_iterator = path_to_dir_iterator(locale_names_path);
|
||||
|
@ -247,7 +247,7 @@ static void parse_number_systems(String locale_numbers_path, UnicodeLocaleData&
|
||||
});
|
||||
}
|
||||
|
||||
static void parse_all_locales(String numbers_path, UnicodeLocaleData& locale_data)
|
||||
static void parse_all_locales(String core_path, String numbers_path, UnicodeLocaleData& locale_data)
|
||||
{
|
||||
auto numbers_iterator = path_to_dir_iterator(move(numbers_path));
|
||||
|
||||
@ -277,6 +277,8 @@ static void parse_all_locales(String numbers_path, UnicodeLocaleData& locale_dat
|
||||
auto& locale = locale_data.locales.ensure(*language);
|
||||
parse_number_systems(numbers_path, locale_data, locale);
|
||||
}
|
||||
|
||||
parse_default_content_locales(move(core_path), locale_data);
|
||||
}
|
||||
|
||||
static String format_identifier(StringView owner, String identifier)
|
||||
@ -576,11 +578,13 @@ int main(int argc, char** argv)
|
||||
{
|
||||
char const* generated_header_path = nullptr;
|
||||
char const* generated_implementation_path = nullptr;
|
||||
char const* core_path = nullptr;
|
||||
char const* numbers_path = nullptr;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(generated_header_path, "Path to the Unicode locale header file to generate", "generated-header-path", 'h', "generated-header-path");
|
||||
args_parser.add_option(generated_implementation_path, "Path to the Unicode locale implementation file to generate", "generated-implementation-path", 'c', "generated-implementation-path");
|
||||
args_parser.add_option(core_path, "Path to cldr-core directory", "core-path", 'r', "core-path");
|
||||
args_parser.add_option(numbers_path, "Path to cldr-numbers directory", "numbers-path", 'n', "numbers-path");
|
||||
args_parser.parse(argc, argv);
|
||||
|
||||
@ -604,7 +608,7 @@ int main(int argc, char** argv)
|
||||
auto generated_implementation_file = open_file(generated_implementation_path, "-c/--generated-implementation-path", Core::OpenMode::ReadWrite);
|
||||
|
||||
UnicodeLocaleData locale_data;
|
||||
parse_all_locales(numbers_path, locale_data);
|
||||
parse_all_locales(core_path, numbers_path, locale_data);
|
||||
|
||||
generate_unicode_locale_header(generated_header_file, locale_data);
|
||||
generate_unicode_locale_implementation(generated_implementation_file, locale_data);
|
||||
|
@ -8,6 +8,10 @@
|
||||
|
||||
#include <AK/Format.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/JsonArray.h>
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/JsonParser.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/QuickSort.h>
|
||||
@ -147,6 +151,40 @@ inline Core::DirIterator path_to_dir_iterator(String path)
|
||||
return iterator;
|
||||
}
|
||||
|
||||
template<typename LocaleDataType>
|
||||
void parse_default_content_locales(String core_path, LocaleDataType& locale_data)
|
||||
{
|
||||
LexicalPath default_content_path(move(core_path));
|
||||
default_content_path = default_content_path.append("defaultContent.json"sv);
|
||||
VERIFY(Core::File::exists(default_content_path.string()));
|
||||
|
||||
auto default_content_file_or_error = Core::File::open(default_content_path.string(), Core::OpenMode::ReadOnly);
|
||||
VERIFY(!default_content_file_or_error.is_error());
|
||||
|
||||
auto default_content = JsonParser(default_content_file_or_error.value()->read_all()).parse();
|
||||
VERIFY(default_content.has_value());
|
||||
|
||||
auto const& default_content_array = default_content->as_object().get("defaultContent"sv);
|
||||
|
||||
default_content_array.as_array().for_each([&](JsonValue const& value) {
|
||||
auto locale = value.as_string();
|
||||
StringView default_locale = locale;
|
||||
|
||||
while (true) {
|
||||
if (locale_data.locales.contains(default_locale))
|
||||
break;
|
||||
|
||||
auto pos = default_locale.find_last('-');
|
||||
if (!pos.has_value())
|
||||
return;
|
||||
|
||||
default_locale = default_locale.substring_view(0, *pos);
|
||||
}
|
||||
|
||||
locale_data.locales.set(locale, locale_data.locales.get(default_locale).value());
|
||||
});
|
||||
}
|
||||
|
||||
inline void ensure_from_string_types_are_generated(SourceGenerator& generator)
|
||||
{
|
||||
static bool generated_from_string_types = false;
|
||||
|
Loading…
Reference in New Issue
Block a user