diff options
4 files changed, 45 insertions, 36 deletions
diff --git a/Meta/CMake/unicode_data.cmake b/Meta/CMake/unicode_data.cmake index 123fbfb7f0..4b4a377b31 100644 --- a/Meta/CMake/unicode_data.cmake +++ b/Meta/CMake/unicode_data.cmake @@ -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 diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp index b8d2d1cb5f..f1c1e7994d 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp @@ -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); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp index b54b423616..dcebeb0c9a 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp @@ -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); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h index a512d1b674..532d8d9fbc 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h @@ -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; |