GenerateUnicodeNumberFormat.cpp 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  1. /*
  2. * Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "GeneratorUtil.h"
  7. #include <AK/AllOf.h>
  8. #include <AK/Array.h>
  9. #include <AK/CharacterTypes.h>
  10. #include <AK/Find.h>
  11. #include <AK/Format.h>
  12. #include <AK/HashFunctions.h>
  13. #include <AK/HashMap.h>
  14. #include <AK/JsonObject.h>
  15. #include <AK/JsonParser.h>
  16. #include <AK/JsonValue.h>
  17. #include <AK/LexicalPath.h>
  18. #include <AK/QuickSort.h>
  19. #include <AK/SourceGenerator.h>
  20. #include <AK/String.h>
  21. #include <AK/StringBuilder.h>
  22. #include <AK/Traits.h>
  23. #include <AK/Utf8View.h>
  24. #include <LibCore/ArgsParser.h>
  25. #include <LibCore/DirIterator.h>
  26. #include <LibCore/File.h>
  27. #include <LibCore/Stream.h>
  28. #include <LibJS/Runtime/Intl/AbstractOperations.h>
  29. #include <LibUnicode/Locale.h>
  30. #include <LibUnicode/NumberFormat.h>
  31. #include <LibUnicode/PluralRules.h>
  32. #include <math.h>
  33. using StringIndexType = u16;
  34. constexpr auto s_string_index_type = "u16"sv;
  35. using NumberFormatIndexType = u16;
  36. constexpr auto s_number_format_index_type = "u16"sv;
  37. using NumberFormatListIndexType = u16;
  38. constexpr auto s_number_format_list_index_type = "u16"sv;
  39. using NumericSymbolListIndexType = u8;
  40. constexpr auto s_numeric_symbol_list_index_type = "u8"sv;
  41. using NumberSystemIndexType = u8;
  42. constexpr auto s_number_system_index_type = "u8"sv;
  43. using UnitIndexType = u16;
  44. constexpr auto s_unit_index_type = "u16"sv;
  45. enum class NumberFormatType {
  46. Standard,
  47. Compact,
  48. };
  49. struct NumberFormat : public Unicode::NumberFormat {
  50. using Base = Unicode::NumberFormat;
  51. unsigned hash() const
  52. {
  53. auto hash = pair_int_hash(magnitude, exponent);
  54. hash = pair_int_hash(hash, to_underlying(plurality));
  55. hash = pair_int_hash(hash, zero_format_index);
  56. hash = pair_int_hash(hash, positive_format_index);
  57. hash = pair_int_hash(hash, negative_format_index);
  58. for (auto index : identifier_indices)
  59. hash = pair_int_hash(hash, index);
  60. return hash;
  61. }
  62. bool operator==(NumberFormat const& other) const
  63. {
  64. return (magnitude == other.magnitude)
  65. && (exponent == other.exponent)
  66. && (plurality == other.plurality)
  67. && (zero_format_index == other.zero_format_index)
  68. && (positive_format_index == other.positive_format_index)
  69. && (negative_format_index == other.negative_format_index)
  70. && (identifier_indices == other.identifier_indices);
  71. }
  72. StringIndexType zero_format_index { 0 };
  73. StringIndexType positive_format_index { 0 };
  74. StringIndexType negative_format_index { 0 };
  75. Vector<StringIndexType> identifier_indices {};
  76. };
  77. template<>
  78. struct AK::Formatter<NumberFormat> : Formatter<FormatString> {
  79. ErrorOr<void> format(FormatBuilder& builder, NumberFormat const& format)
  80. {
  81. StringBuilder identifier_indices;
  82. identifier_indices.join(", "sv, format.identifier_indices);
  83. return Formatter<FormatString>::format(builder,
  84. "{{ {}, {}, {}, {}, {}, {}, {{ {} }} }}"sv,
  85. format.magnitude,
  86. format.exponent,
  87. to_underlying(format.plurality),
  88. format.zero_format_index,
  89. format.positive_format_index,
  90. format.negative_format_index,
  91. identifier_indices.build());
  92. }
  93. };
  94. template<>
  95. struct AK::Traits<NumberFormat> : public GenericTraits<NumberFormat> {
  96. static unsigned hash(NumberFormat const& f) { return f.hash(); }
  97. };
  98. using NumberFormatList = Vector<NumberFormatIndexType>;
  99. using NumericSymbolList = Vector<StringIndexType>;
  100. struct NumberSystem {
  101. unsigned hash() const
  102. {
  103. auto hash = int_hash(symbols);
  104. hash = pair_int_hash(hash, primary_grouping_size);
  105. hash = pair_int_hash(hash, secondary_grouping_size);
  106. hash = pair_int_hash(hash, decimal_format);
  107. hash = pair_int_hash(hash, decimal_long_formats);
  108. hash = pair_int_hash(hash, decimal_short_formats);
  109. hash = pair_int_hash(hash, currency_format);
  110. hash = pair_int_hash(hash, accounting_format);
  111. hash = pair_int_hash(hash, currency_unit_formats);
  112. hash = pair_int_hash(hash, currency_short_formats);
  113. hash = pair_int_hash(hash, percent_format);
  114. hash = pair_int_hash(hash, scientific_format);
  115. return hash;
  116. }
  117. bool operator==(NumberSystem const& other) const
  118. {
  119. return (symbols == other.symbols)
  120. && (primary_grouping_size == other.primary_grouping_size)
  121. && (secondary_grouping_size == other.secondary_grouping_size)
  122. && (decimal_format == other.decimal_format)
  123. && (decimal_long_formats == other.decimal_long_formats)
  124. && (decimal_short_formats == other.decimal_short_formats)
  125. && (currency_format == other.currency_format)
  126. && (accounting_format == other.accounting_format)
  127. && (currency_unit_formats == other.currency_unit_formats)
  128. && (currency_short_formats == other.currency_short_formats)
  129. && (percent_format == other.percent_format)
  130. && (scientific_format == other.scientific_format);
  131. }
  132. NumericSymbolListIndexType symbols { 0 };
  133. u8 primary_grouping_size { 0 };
  134. u8 secondary_grouping_size { 0 };
  135. NumberFormatIndexType decimal_format { 0 };
  136. NumberFormatListIndexType decimal_long_formats { 0 };
  137. NumberFormatListIndexType decimal_short_formats { 0 };
  138. NumberFormatIndexType currency_format { 0 };
  139. NumberFormatIndexType accounting_format { 0 };
  140. NumberFormatListIndexType currency_unit_formats { 0 };
  141. NumberFormatListIndexType currency_short_formats { 0 };
  142. NumberFormatIndexType percent_format { 0 };
  143. NumberFormatIndexType scientific_format { 0 };
  144. };
  145. template<>
  146. struct AK::Formatter<NumberSystem> : Formatter<FormatString> {
  147. ErrorOr<void> format(FormatBuilder& builder, NumberSystem const& system)
  148. {
  149. return Formatter<FormatString>::format(builder,
  150. "{{ {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {} }}"sv,
  151. system.symbols,
  152. system.primary_grouping_size,
  153. system.secondary_grouping_size,
  154. system.decimal_format,
  155. system.decimal_long_formats,
  156. system.decimal_short_formats,
  157. system.currency_format,
  158. system.accounting_format,
  159. system.currency_unit_formats,
  160. system.currency_short_formats,
  161. system.percent_format,
  162. system.scientific_format);
  163. }
  164. };
  165. template<>
  166. struct AK::Traits<NumberSystem> : public GenericTraits<NumberSystem> {
  167. static unsigned hash(NumberSystem const& s) { return s.hash(); }
  168. };
  169. struct Unit {
  170. unsigned hash() const
  171. {
  172. auto hash = int_hash(unit);
  173. hash = pair_int_hash(hash, long_formats);
  174. hash = pair_int_hash(hash, short_formats);
  175. hash = pair_int_hash(hash, narrow_formats);
  176. return hash;
  177. }
  178. bool operator==(Unit const& other) const
  179. {
  180. return (unit == other.unit)
  181. && (long_formats == other.long_formats)
  182. && (short_formats == other.short_formats)
  183. && (narrow_formats == other.narrow_formats);
  184. }
  185. StringIndexType unit { 0 };
  186. NumberFormatListIndexType long_formats { 0 };
  187. NumberFormatListIndexType short_formats { 0 };
  188. NumberFormatListIndexType narrow_formats { 0 };
  189. };
  190. template<>
  191. struct AK::Formatter<Unit> : Formatter<FormatString> {
  192. ErrorOr<void> format(FormatBuilder& builder, Unit const& system)
  193. {
  194. return Formatter<FormatString>::format(builder,
  195. "{{ {}, {}, {}, {} }}"sv,
  196. system.unit,
  197. system.long_formats,
  198. system.short_formats,
  199. system.narrow_formats);
  200. }
  201. };
  202. template<>
  203. struct AK::Traits<Unit> : public GenericTraits<Unit> {
  204. static unsigned hash(Unit const& u) { return u.hash(); }
  205. };
  206. struct Locale {
  207. Vector<NumberSystemIndexType> number_systems;
  208. HashMap<String, UnitIndexType> units {};
  209. u8 minimum_grouping_digits { 0 };
  210. };
  211. struct UnicodeLocaleData {
  212. UniqueStringStorage<StringIndexType> unique_strings;
  213. UniqueStorage<NumberFormat, NumberFormatIndexType> unique_formats;
  214. UniqueStorage<NumberFormatList, NumberFormatListIndexType> unique_format_lists;
  215. UniqueStorage<NumericSymbolList, NumericSymbolListIndexType> unique_symbols;
  216. UniqueStorage<NumberSystem, NumberSystemIndexType> unique_systems;
  217. UniqueStorage<Unit, UnitIndexType> unique_units;
  218. HashMap<String, Array<u32, 10>> number_system_digits;
  219. Vector<String> number_systems;
  220. HashMap<String, Locale> locales;
  221. size_t max_identifier_count { 0 };
  222. };
  223. static ErrorOr<void> parse_number_system_digits(String core_supplemental_path, UnicodeLocaleData& locale_data)
  224. {
  225. LexicalPath number_systems_path(move(core_supplemental_path));
  226. number_systems_path = number_systems_path.append("numberingSystems.json"sv);
  227. auto number_systems = TRY(read_json_file(number_systems_path.string()));
  228. auto const& supplemental_object = number_systems.as_object().get("supplemental"sv);
  229. auto const& number_systems_object = supplemental_object.as_object().get("numberingSystems"sv);
  230. number_systems_object.as_object().for_each_member([&](auto const& number_system, auto const& digits_object) {
  231. auto type = digits_object.as_object().get("_type"sv).as_string();
  232. if (type != "numeric"sv)
  233. return;
  234. auto digits = digits_object.as_object().get("_digits"sv).as_string();
  235. Utf8View utf8_digits { digits };
  236. VERIFY(utf8_digits.length() == 10);
  237. auto& number_system_digits = locale_data.number_system_digits.ensure(number_system);
  238. size_t index = 0;
  239. for (u32 digit : utf8_digits)
  240. number_system_digits[index++] = digit;
  241. if (!locale_data.number_systems.contains_slow(number_system))
  242. locale_data.number_systems.append(number_system);
  243. });
  244. return {};
  245. }
  246. static String parse_identifiers(String pattern, StringView replacement, UnicodeLocaleData& locale_data, NumberFormat& format)
  247. {
  248. static constexpr Utf8View whitespace { "\u0020\u00a0\u200f"sv };
  249. while (true) {
  250. Utf8View utf8_pattern { pattern };
  251. Optional<size_t> start_index;
  252. Optional<size_t> end_index;
  253. bool inside_replacement = false;
  254. for (auto it = utf8_pattern.begin(); it != utf8_pattern.end(); ++it) {
  255. if (*it == '{') {
  256. if (start_index.has_value()) {
  257. end_index = utf8_pattern.byte_offset_of(it);
  258. break;
  259. }
  260. inside_replacement = true;
  261. } else if (*it == '}') {
  262. inside_replacement = false;
  263. } else if (!inside_replacement && !start_index.has_value() && !whitespace.contains(*it)) {
  264. start_index = utf8_pattern.byte_offset_of(it);
  265. }
  266. }
  267. if (!start_index.has_value())
  268. return pattern;
  269. end_index = end_index.value_or(pattern.length());
  270. utf8_pattern = utf8_pattern.substring_view(*start_index, *end_index - *start_index);
  271. utf8_pattern = utf8_pattern.trim(whitespace);
  272. auto identifier = utf8_pattern.as_string().replace("'.'"sv, "."sv, ReplaceMode::FirstOnly);
  273. auto identifier_index = locale_data.unique_strings.ensure(move(identifier));
  274. size_t replacement_index = 0;
  275. if (auto index = format.identifier_indices.find_first_index(identifier_index); index.has_value()) {
  276. replacement_index = *index;
  277. } else {
  278. replacement_index = format.identifier_indices.size();
  279. format.identifier_indices.append(identifier_index);
  280. locale_data.max_identifier_count = max(locale_data.max_identifier_count, format.identifier_indices.size());
  281. }
  282. pattern = String::formatted("{}{{{}:{}}}{}",
  283. *start_index > 0 ? pattern.substring_view(0, *start_index) : ""sv,
  284. replacement,
  285. replacement_index,
  286. pattern.substring_view(*start_index + utf8_pattern.byte_length()));
  287. }
  288. }
  289. static void parse_number_pattern(Vector<String> patterns, UnicodeLocaleData& locale_data, NumberFormatType type, NumberFormat& format, NumberSystem* number_system_for_groupings = nullptr)
  290. {
  291. // https://unicode.org/reports/tr35/tr35-numbers.html#Number_Format_Patterns
  292. // https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns
  293. VERIFY((patterns.size() == 1) || (patterns.size() == 2));
  294. auto replace_patterns = [&](String pattern) {
  295. static HashMap<StringView, StringView> replacements = {
  296. { "{0}"sv, "{number}"sv },
  297. { "{1}"sv, "{currency}"sv },
  298. { "%"sv, "{percentSign}"sv },
  299. { "+"sv, "{plusSign}"sv },
  300. { "-"sv, "{minusSign}"sv },
  301. { "¤"sv, "{currency}"sv }, // U+00A4 Currency Sign
  302. { "E"sv, "{scientificSeparator}"sv },
  303. };
  304. for (auto const& replacement : replacements)
  305. pattern = pattern.replace(replacement.key, replacement.value, ReplaceMode::All);
  306. if (auto start_number_index = pattern.find_any_of("#0"sv, String::SearchDirection::Forward); start_number_index.has_value()) {
  307. auto end_number_index = *start_number_index + 1;
  308. for (; end_number_index < pattern.length(); ++end_number_index) {
  309. auto ch = pattern[end_number_index];
  310. if ((ch != '#') && (ch != '0') && (ch != ',') && (ch != '.'))
  311. break;
  312. }
  313. if (number_system_for_groupings) {
  314. auto number_pattern = pattern.substring_view(*start_number_index, end_number_index - *start_number_index);
  315. auto group_separators = number_pattern.find_all(","sv);
  316. VERIFY((group_separators.size() == 1) || (group_separators.size() == 2));
  317. auto decimal = number_pattern.find('.');
  318. VERIFY(decimal.has_value());
  319. if (group_separators.size() == 1) {
  320. number_system_for_groupings->primary_grouping_size = *decimal - group_separators[0] - 1;
  321. number_system_for_groupings->secondary_grouping_size = number_system_for_groupings->primary_grouping_size;
  322. } else {
  323. number_system_for_groupings->primary_grouping_size = *decimal - group_separators[1] - 1;
  324. number_system_for_groupings->secondary_grouping_size = group_separators[1] - group_separators[0] - 1;
  325. }
  326. }
  327. pattern = String::formatted("{}{{number}}{}",
  328. *start_number_index > 0 ? pattern.substring_view(0, *start_number_index) : ""sv,
  329. pattern.substring_view(end_number_index));
  330. // This is specifically handled here rather than in the replacements HashMap above so
  331. // that we do not errantly replace zeroes in number patterns.
  332. if (pattern.contains(*replacements.get("E"sv)))
  333. pattern = pattern.replace("0"sv, "{scientificExponent}"sv, ReplaceMode::FirstOnly);
  334. }
  335. if (type == NumberFormatType::Compact)
  336. return parse_identifiers(move(pattern), "compactIdentifier"sv, locale_data, format);
  337. return pattern;
  338. };
  339. auto zero_format = replace_patterns(move(patterns[0]));
  340. format.positive_format_index = locale_data.unique_strings.ensure(String::formatted("{{plusSign}}{}", zero_format));
  341. if (patterns.size() == 2) {
  342. auto negative_format = replace_patterns(move(patterns[1]));
  343. format.negative_format_index = locale_data.unique_strings.ensure(move(negative_format));
  344. } else {
  345. format.negative_format_index = locale_data.unique_strings.ensure(String::formatted("{{minusSign}}{}", zero_format));
  346. }
  347. format.zero_format_index = locale_data.unique_strings.ensure(move(zero_format));
  348. }
  349. static void parse_number_pattern(Vector<String> patterns, UnicodeLocaleData& locale_data, NumberFormatType type, NumberFormatIndexType& format_index, NumberSystem* number_system_for_groupings = nullptr)
  350. {
  351. NumberFormat format {};
  352. parse_number_pattern(move(patterns), locale_data, type, format, number_system_for_groupings);
  353. format_index = locale_data.unique_formats.ensure(move(format));
  354. }
  355. static ErrorOr<void> parse_number_systems(String locale_numbers_path, UnicodeLocaleData& locale_data, Locale& locale)
  356. {
  357. LexicalPath numbers_path(move(locale_numbers_path));
  358. numbers_path = numbers_path.append("numbers.json"sv);
  359. auto numbers = TRY(read_json_file(numbers_path.string()));
  360. auto const& main_object = numbers.as_object().get("main"sv);
  361. auto const& locale_object = main_object.as_object().get(numbers_path.parent().basename());
  362. auto const& locale_numbers_object = locale_object.as_object().get("numbers"sv);
  363. auto const& minimum_grouping_digits = locale_numbers_object.as_object().get("minimumGroupingDigits"sv);
  364. Vector<Optional<NumberSystem>> number_systems;
  365. number_systems.resize(locale_data.number_systems.size());
  366. auto ensure_number_system = [&](auto const& system) -> NumberSystem& {
  367. auto system_index = locale_data.number_systems.find_first_index(system).value();
  368. VERIFY(system_index < number_systems.size());
  369. auto& number_system = number_systems.at(system_index);
  370. if (!number_system.has_value())
  371. number_system = NumberSystem {};
  372. return number_system.value();
  373. };
  374. auto parse_number_format = [&](auto const& format_object) {
  375. Vector<NumberFormatIndexType> result;
  376. result.ensure_capacity(format_object.size());
  377. format_object.for_each_member([&](auto const& key, JsonValue const& value) {
  378. auto split_key = key.split_view('-');
  379. if (split_key.size() != 3)
  380. return;
  381. auto patterns = value.as_string().split(';');
  382. NumberFormat format {};
  383. if (auto type = split_key[0].template to_uint<u64>(); type.has_value()) {
  384. VERIFY(*type % 10 == 0);
  385. format.magnitude = static_cast<u8>(log10(*type));
  386. if (patterns[0] != "0"sv) {
  387. auto number_of_zeroes_in_pattern = patterns[0].count("0"sv);
  388. VERIFY(format.magnitude >= number_of_zeroes_in_pattern);
  389. format.exponent = format.magnitude + 1 - number_of_zeroes_in_pattern;
  390. }
  391. } else {
  392. VERIFY(split_key[0] == "unitPattern"sv);
  393. }
  394. format.plurality = Unicode::plural_category_from_string(split_key[2]);
  395. parse_number_pattern(move(patterns), locale_data, NumberFormatType::Compact, format);
  396. auto format_index = locale_data.unique_formats.ensure(move(format));
  397. result.append(format_index);
  398. });
  399. return locale_data.unique_format_lists.ensure(move(result));
  400. };
  401. auto numeric_symbol_from_string = [&](StringView numeric_symbol) -> Optional<Unicode::NumericSymbol> {
  402. if (numeric_symbol == "decimal"sv)
  403. return Unicode::NumericSymbol::Decimal;
  404. if (numeric_symbol == "exponential"sv)
  405. return Unicode::NumericSymbol::Exponential;
  406. if (numeric_symbol == "group"sv)
  407. return Unicode::NumericSymbol::Group;
  408. if (numeric_symbol == "infinity"sv)
  409. return Unicode::NumericSymbol::Infinity;
  410. if (numeric_symbol == "minusSign"sv)
  411. return Unicode::NumericSymbol::MinusSign;
  412. if (numeric_symbol == "nan"sv)
  413. return Unicode::NumericSymbol::NaN;
  414. if (numeric_symbol == "percentSign"sv)
  415. return Unicode::NumericSymbol::PercentSign;
  416. if (numeric_symbol == "plusSign"sv)
  417. return Unicode::NumericSymbol::PlusSign;
  418. if (numeric_symbol == "timeSeparator"sv)
  419. return Unicode::NumericSymbol::TimeSeparator;
  420. return {};
  421. };
  422. locale_numbers_object.as_object().for_each_member([&](auto const& key, JsonValue const& value) {
  423. constexpr auto symbols_prefix = "symbols-numberSystem-"sv;
  424. constexpr auto decimal_formats_prefix = "decimalFormats-numberSystem-"sv;
  425. constexpr auto currency_formats_prefix = "currencyFormats-numberSystem-"sv;
  426. constexpr auto percent_formats_prefix = "percentFormats-numberSystem-"sv;
  427. constexpr auto scientific_formats_prefix = "scientificFormats-numberSystem-"sv;
  428. if (key.starts_with(symbols_prefix)) {
  429. auto system = key.substring(symbols_prefix.length());
  430. auto& number_system = ensure_number_system(system);
  431. NumericSymbolList symbols;
  432. value.as_object().for_each_member([&](auto const& symbol, JsonValue const& localization) {
  433. auto numeric_symbol = numeric_symbol_from_string(symbol);
  434. if (!numeric_symbol.has_value())
  435. return;
  436. if (to_underlying(*numeric_symbol) >= symbols.size())
  437. symbols.resize(to_underlying(*numeric_symbol) + 1);
  438. auto symbol_index = locale_data.unique_strings.ensure(localization.as_string());
  439. symbols[to_underlying(*numeric_symbol)] = symbol_index;
  440. });
  441. number_system.symbols = locale_data.unique_symbols.ensure(move(symbols));
  442. } else if (key.starts_with(decimal_formats_prefix)) {
  443. auto system = key.substring(decimal_formats_prefix.length());
  444. auto& number_system = ensure_number_system(system);
  445. auto format_object = value.as_object().get("standard"sv);
  446. parse_number_pattern(format_object.as_string().split(';'), locale_data, NumberFormatType::Standard, number_system.decimal_format, &number_system);
  447. auto const& long_format = value.as_object().get("long"sv).as_object().get("decimalFormat"sv);
  448. number_system.decimal_long_formats = parse_number_format(long_format.as_object());
  449. auto const& short_format = value.as_object().get("short"sv).as_object().get("decimalFormat"sv);
  450. number_system.decimal_short_formats = parse_number_format(short_format.as_object());
  451. } else if (key.starts_with(currency_formats_prefix)) {
  452. auto system = key.substring(currency_formats_prefix.length());
  453. auto& number_system = ensure_number_system(system);
  454. auto format_object = value.as_object().get("standard"sv);
  455. parse_number_pattern(format_object.as_string().split(';'), locale_data, NumberFormatType::Standard, number_system.currency_format);
  456. format_object = value.as_object().get("accounting"sv);
  457. parse_number_pattern(format_object.as_string().split(';'), locale_data, NumberFormatType::Standard, number_system.accounting_format);
  458. number_system.currency_unit_formats = parse_number_format(value.as_object());
  459. if (value.as_object().has("short"sv)) {
  460. auto const& short_format = value.as_object().get("short"sv).as_object().get("standard"sv);
  461. number_system.currency_short_formats = parse_number_format(short_format.as_object());
  462. }
  463. } else if (key.starts_with(percent_formats_prefix)) {
  464. auto system = key.substring(percent_formats_prefix.length());
  465. auto& number_system = ensure_number_system(system);
  466. auto format_object = value.as_object().get("standard"sv);
  467. parse_number_pattern(format_object.as_string().split(';'), locale_data, NumberFormatType::Standard, number_system.percent_format);
  468. } else if (key.starts_with(scientific_formats_prefix)) {
  469. auto system = key.substring(scientific_formats_prefix.length());
  470. auto& number_system = ensure_number_system(system);
  471. auto format_object = value.as_object().get("standard"sv);
  472. parse_number_pattern(format_object.as_string().split(';'), locale_data, NumberFormatType::Standard, number_system.scientific_format);
  473. }
  474. });
  475. locale.number_systems.ensure_capacity(number_systems.size());
  476. for (auto& number_system : number_systems) {
  477. NumberSystemIndexType system_index = 0;
  478. if (number_system.has_value())
  479. system_index = locale_data.unique_systems.ensure(number_system.release_value());
  480. locale.number_systems.append(system_index);
  481. }
  482. locale.minimum_grouping_digits = minimum_grouping_digits.as_string().template to_uint<u8>().value();
  483. return {};
  484. }
  485. static ErrorOr<void> parse_units(String locale_units_path, UnicodeLocaleData& locale_data, Locale& locale)
  486. {
  487. LexicalPath units_path(move(locale_units_path));
  488. units_path = units_path.append("units.json"sv);
  489. auto locale_units = TRY(read_json_file(units_path.string()));
  490. auto const& main_object = locale_units.as_object().get("main"sv);
  491. auto const& locale_object = main_object.as_object().get(units_path.parent().basename());
  492. auto const& locale_units_object = locale_object.as_object().get("units"sv);
  493. auto const& long_object = locale_units_object.as_object().get("long"sv);
  494. auto const& short_object = locale_units_object.as_object().get("short"sv);
  495. auto const& narrow_object = locale_units_object.as_object().get("narrow"sv);
  496. HashMap<String, Unit> units;
  497. auto ensure_unit = [&](auto const& unit) -> Unit& {
  498. return units.ensure(unit, [&]() {
  499. auto unit_index = locale_data.unique_strings.ensure(unit);
  500. return Unit { .unit = unit_index };
  501. });
  502. };
  503. auto is_sanctioned_unit = [](StringView unit_name) {
  504. // LibUnicode generally tries to avoid being directly dependent on ECMA-402, but this rather significantly reduces the amount
  505. // of data generated here, and ECMA-402 is currently the only consumer of this data.
  506. constexpr auto sanctioned_units = JS::Intl::sanctioned_single_unit_identifiers();
  507. if (find(sanctioned_units.begin(), sanctioned_units.end(), unit_name) != sanctioned_units.end())
  508. return true;
  509. static constexpr auto extra_sanctioned_units = JS::Intl::extra_sanctioned_single_unit_identifiers();
  510. return find(extra_sanctioned_units.begin(), extra_sanctioned_units.end(), unit_name) != extra_sanctioned_units.end();
  511. };
  512. auto parse_units_object = [&](auto const& units_object, Unicode::Style style) {
  513. constexpr auto unit_pattern_prefix = "unitPattern-count-"sv;
  514. constexpr auto combined_unit_separator = "-per-"sv;
  515. units_object.for_each_member([&](auto const& key, JsonValue const& value) {
  516. auto end_of_category = key.find('-');
  517. if (!end_of_category.has_value())
  518. return;
  519. auto unit_name = key.substring(*end_of_category + 1);
  520. if (!is_sanctioned_unit(unit_name)) {
  521. auto indices = unit_name.find_all(combined_unit_separator);
  522. if (indices.size() != 1)
  523. return;
  524. auto numerator = unit_name.substring_view(0, indices[0]);
  525. auto denominator = unit_name.substring_view(indices[0] + combined_unit_separator.length());
  526. if (!is_sanctioned_unit(numerator) || !is_sanctioned_unit(denominator))
  527. return;
  528. }
  529. auto& unit = ensure_unit(unit_name);
  530. NumberFormatList formats;
  531. value.as_object().for_each_member([&](auto const& unit_key, JsonValue const& pattern_value) {
  532. if (!unit_key.starts_with(unit_pattern_prefix))
  533. return;
  534. NumberFormat format {};
  535. auto plurality = unit_key.substring_view(unit_pattern_prefix.length());
  536. format.plurality = Unicode::plural_category_from_string(plurality);
  537. auto zero_format = pattern_value.as_string().replace("{0}"sv, "{number}"sv, ReplaceMode::FirstOnly);
  538. zero_format = parse_identifiers(zero_format, "unitIdentifier"sv, locale_data, format);
  539. format.positive_format_index = locale_data.unique_strings.ensure(zero_format.replace("{number}"sv, "{plusSign}{number}"sv, ReplaceMode::FirstOnly));
  540. format.negative_format_index = locale_data.unique_strings.ensure(zero_format.replace("{number}"sv, "{minusSign}{number}"sv, ReplaceMode::FirstOnly));
  541. format.zero_format_index = locale_data.unique_strings.ensure(move(zero_format));
  542. formats.append(locale_data.unique_formats.ensure(move(format)));
  543. });
  544. auto number_format_list_index = locale_data.unique_format_lists.ensure(move(formats));
  545. switch (style) {
  546. case Unicode::Style::Long:
  547. unit.long_formats = number_format_list_index;
  548. break;
  549. case Unicode::Style::Short:
  550. unit.short_formats = number_format_list_index;
  551. break;
  552. case Unicode::Style::Narrow:
  553. unit.narrow_formats = number_format_list_index;
  554. break;
  555. default:
  556. VERIFY_NOT_REACHED();
  557. }
  558. });
  559. };
  560. parse_units_object(long_object.as_object(), Unicode::Style::Long);
  561. parse_units_object(short_object.as_object(), Unicode::Style::Short);
  562. parse_units_object(narrow_object.as_object(), Unicode::Style::Narrow);
  563. for (auto& unit : units) {
  564. auto unit_index = locale_data.unique_units.ensure(move(unit.value));
  565. locale.units.set(unit.key, unit_index);
  566. }
  567. return {};
  568. }
  569. static ErrorOr<void> parse_all_locales(String core_path, String numbers_path, String units_path, UnicodeLocaleData& locale_data)
  570. {
  571. auto numbers_iterator = TRY(path_to_dir_iterator(move(numbers_path)));
  572. auto units_iterator = TRY(path_to_dir_iterator(move(units_path)));
  573. LexicalPath core_supplemental_path(move(core_path));
  574. core_supplemental_path = core_supplemental_path.append("supplemental"sv);
  575. VERIFY(Core::File::is_directory(core_supplemental_path.string()));
  576. TRY(parse_number_system_digits(core_supplemental_path.string(), locale_data));
  577. auto remove_variants_from_path = [&](String path) -> ErrorOr<String> {
  578. auto parsed_locale = TRY(CanonicalLanguageID<StringIndexType>::parse(locale_data.unique_strings, LexicalPath::basename(path)));
  579. StringBuilder builder;
  580. builder.append(locale_data.unique_strings.get(parsed_locale.language));
  581. if (auto script = locale_data.unique_strings.get(parsed_locale.script); !script.is_empty())
  582. builder.appendff("-{}", script);
  583. if (auto region = locale_data.unique_strings.get(parsed_locale.region); !region.is_empty())
  584. builder.appendff("-{}", region);
  585. return builder.build();
  586. };
  587. while (numbers_iterator.has_next()) {
  588. auto numbers_path = TRY(next_path_from_dir_iterator(numbers_iterator));
  589. auto language = TRY(remove_variants_from_path(numbers_path));
  590. auto& locale = locale_data.locales.ensure(language);
  591. TRY(parse_number_systems(numbers_path, locale_data, locale));
  592. }
  593. while (units_iterator.has_next()) {
  594. auto units_path = TRY(next_path_from_dir_iterator(units_iterator));
  595. auto language = TRY(remove_variants_from_path(units_path));
  596. auto& locale = locale_data.locales.ensure(language);
  597. TRY(parse_units(units_path, locale_data, locale));
  598. }
  599. return {};
  600. }
  601. static String format_identifier(StringView, String identifier)
  602. {
  603. return identifier.to_titlecase();
  604. }
  605. static ErrorOr<void> generate_unicode_locale_header(Core::Stream::BufferedFile& file, UnicodeLocaleData& locale_data)
  606. {
  607. StringBuilder builder;
  608. SourceGenerator generator { builder };
  609. generator.append(R"~~~(
  610. #include <AK/Types.h>
  611. #pragma once
  612. namespace Unicode {
  613. )~~~");
  614. generate_enum(generator, format_identifier, "NumberSystem"sv, {}, locale_data.number_systems);
  615. generator.append(R"~~~(
  616. }
  617. )~~~");
  618. TRY(file.write(generator.as_string_view().bytes()));
  619. return {};
  620. }
  621. static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::BufferedFile& file, UnicodeLocaleData& locale_data)
  622. {
  623. StringBuilder builder;
  624. SourceGenerator generator { builder };
  625. generator.set("string_index_type"sv, s_string_index_type);
  626. generator.set("number_format_index_type"sv, s_number_format_index_type);
  627. generator.set("number_format_list_index_type"sv, s_number_format_list_index_type);
  628. generator.set("numeric_symbol_list_index_type"sv, s_numeric_symbol_list_index_type);
  629. generator.set("identifier_count", String::number(locale_data.max_identifier_count));
  630. generator.append(R"~~~(
  631. #include <AK/Array.h>
  632. #include <AK/BinarySearch.h>
  633. #include <AK/Optional.h>
  634. #include <AK/Span.h>
  635. #include <AK/StringView.h>
  636. #include <AK/Vector.h>
  637. #include <LibUnicode/Locale.h>
  638. #include <LibUnicode/NumberFormat.h>
  639. #include <LibUnicode/PluralRules.h>
  640. #include <LibUnicode/UnicodeLocale.h>
  641. #include <LibUnicode/UnicodeNumberFormat.h>
  642. namespace Unicode {
  643. )~~~");
  644. locale_data.unique_strings.generate(generator);
  645. generator.append(R"~~~(
  646. struct NumberFormatImpl {
  647. NumberFormat to_unicode_number_format() const {
  648. NumberFormat number_format {};
  649. number_format.magnitude = magnitude;
  650. number_format.exponent = exponent;
  651. number_format.plurality = static_cast<PluralCategory>(plurality);
  652. number_format.zero_format = s_string_list[zero_format];
  653. number_format.positive_format = s_string_list[positive_format];
  654. number_format.negative_format = s_string_list[negative_format];
  655. number_format.identifiers.ensure_capacity(identifiers.size());
  656. for (@string_index_type@ identifier : identifiers)
  657. number_format.identifiers.append(s_string_list[identifier]);
  658. return number_format;
  659. }
  660. u8 magnitude { 0 };
  661. u8 exponent { 0 };
  662. u8 plurality { 0 };
  663. @string_index_type@ zero_format { 0 };
  664. @string_index_type@ positive_format { 0 };
  665. @string_index_type@ negative_format { 0 };
  666. Array<@string_index_type@, @identifier_count@> identifiers {};
  667. };
  668. struct NumberSystemData {
  669. @numeric_symbol_list_index_type@ symbols { 0 };
  670. u8 primary_grouping_size { 0 };
  671. u8 secondary_grouping_size { 0 };
  672. @number_format_index_type@ decimal_format { 0 };
  673. @number_format_list_index_type@ decimal_long_formats { 0 };
  674. @number_format_list_index_type@ decimal_short_formats { 0 };
  675. @number_format_index_type@ currency_format { 0 };
  676. @number_format_index_type@ accounting_format { 0 };
  677. @number_format_list_index_type@ currency_unit_formats { 0 };
  678. @number_format_list_index_type@ currency_short_formats { 0 };
  679. @number_format_index_type@ percent_format { 0 };
  680. @number_format_index_type@ scientific_format { 0 };
  681. };
  682. struct Unit {
  683. @string_index_type@ unit { 0 };
  684. @number_format_list_index_type@ long_formats { 0 };
  685. @number_format_list_index_type@ short_formats { 0 };
  686. @number_format_list_index_type@ narrow_formats { 0 };
  687. };
  688. )~~~");
  689. locale_data.unique_formats.generate(generator, "NumberFormatImpl"sv, "s_number_formats"sv, 10);
  690. locale_data.unique_format_lists.generate(generator, s_number_format_index_type, "s_number_format_lists"sv);
  691. locale_data.unique_symbols.generate(generator, s_string_index_type, "s_numeric_symbol_lists"sv);
  692. locale_data.unique_systems.generate(generator, "NumberSystemData"sv, "s_number_systems"sv, 10);
  693. locale_data.unique_units.generate(generator, "Unit"sv, "s_units"sv, 10);
  694. auto locales = locale_data.locales.keys();
  695. quick_sort(locales);
  696. generator.set("size", String::number(locales.size()));
  697. generator.append(R"~~~(
  698. static constexpr Array<u8, @size@> s_minimum_grouping_digits { { )~~~");
  699. bool first = true;
  700. for (auto const& locale : locales) {
  701. generator.append(first ? " "sv : ", "sv);
  702. generator.append(String::number(locale_data.locales.find(locale)->value.minimum_grouping_digits));
  703. first = false;
  704. }
  705. generator.append(" } };\n");
  706. auto append_map = [&](String name, auto type, auto const& map) {
  707. generator.set("name", name);
  708. generator.set("type", type);
  709. generator.set("size", String::number(map.size()));
  710. generator.append(R"~~~(
  711. static constexpr Array<@type@, @size@> @name@ { {)~~~");
  712. bool first = true;
  713. for (auto const& item : map) {
  714. generator.append(first ? " "sv : ", "sv);
  715. if constexpr (requires { item.value; })
  716. generator.append(String::number(item.value));
  717. else
  718. generator.append(String::number(item));
  719. first = false;
  720. }
  721. generator.append(" } };");
  722. };
  723. generate_mapping(generator, locale_data.number_system_digits, "u32"sv, "s_number_systems_digits"sv, "s_number_systems_digits_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_map(name, "u32"sv, value); });
  724. generate_mapping(generator, locale_data.locales, s_number_system_index_type, "s_locale_number_systems"sv, "s_number_systems_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_map(name, s_number_system_index_type, value.number_systems); });
  725. generate_mapping(generator, locale_data.locales, s_unit_index_type, "s_locale_units"sv, "s_units_{}"sv, nullptr, [&](auto const& name, auto const& value) { append_map(name, s_unit_index_type, value.units); });
  726. generator.append(R"~~~(
  727. static Optional<NumberSystem> keyword_to_number_system(KeywordNumbers keyword)
  728. {
  729. switch (keyword) {)~~~");
  730. for (auto const& number_system : locale_data.number_systems) {
  731. generator.set("name"sv, format_identifier({}, number_system));
  732. generator.append(R"~~~(
  733. case KeywordNumbers::@name@:
  734. return NumberSystem::@name@;)~~~");
  735. }
  736. generator.append(R"~~~(
  737. default:
  738. return {};
  739. }
  740. }
  741. Optional<Span<u32 const>> get_digits_for_number_system(StringView system)
  742. {
  743. auto number_system_keyword = keyword_nu_from_string(system);
  744. if (!number_system_keyword.has_value())
  745. return {};
  746. auto number_system_value = keyword_to_number_system(*number_system_keyword);
  747. if (!number_system_value.has_value())
  748. return {};
  749. auto number_system_index = to_underlying(*number_system_value);
  750. return s_number_systems_digits[number_system_index];
  751. }
  752. static NumberSystemData const* find_number_system(StringView locale, StringView system)
  753. {
  754. auto locale_value = locale_from_string(locale);
  755. if (!locale_value.has_value())
  756. return nullptr;
  757. auto number_system_keyword = keyword_nu_from_string(system);
  758. if (!number_system_keyword.has_value())
  759. return {};
  760. auto number_system_value = keyword_to_number_system(*number_system_keyword);
  761. if (!number_system_value.has_value())
  762. return {};
  763. auto locale_index = to_underlying(*locale_value) - 1; // Subtract 1 because 0 == Locale::None.
  764. auto number_system_index = to_underlying(*number_system_value);
  765. auto const& number_systems = s_locale_number_systems.at(locale_index);
  766. number_system_index = number_systems.at(number_system_index);
  767. if (number_system_index == 0)
  768. return nullptr;
  769. return &s_number_systems.at(number_system_index);
  770. }
  771. Optional<StringView> get_number_system_symbol(StringView locale, StringView system, NumericSymbol symbol)
  772. {
  773. if (auto const* number_system = find_number_system(locale, system); number_system != nullptr) {
  774. auto symbols = s_numeric_symbol_lists.at(number_system->symbols);
  775. auto symbol_index = to_underlying(symbol);
  776. if (symbol_index >= symbols.size())
  777. return {};
  778. return s_string_list[symbols[symbol_index]];
  779. }
  780. return {};
  781. }
  782. Optional<NumberGroupings> get_number_system_groupings(StringView locale, StringView system)
  783. {
  784. auto locale_value = locale_from_string(locale);
  785. if (!locale_value.has_value())
  786. return {};
  787. u8 minimum_grouping_digits = s_minimum_grouping_digits[to_underlying(*locale_value) - 1];
  788. if (auto const* number_system = find_number_system(locale, system); number_system != nullptr)
  789. return NumberGroupings { minimum_grouping_digits, number_system->primary_grouping_size, number_system->secondary_grouping_size };
  790. return {};
  791. }
  792. Optional<NumberFormat> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type)
  793. {
  794. if (auto const* number_system = find_number_system(locale, system); number_system != nullptr) {
  795. @number_format_index_type@ format_index = 0;
  796. switch (type) {
  797. case StandardNumberFormatType::Decimal:
  798. format_index = number_system->decimal_format;
  799. break;
  800. case StandardNumberFormatType::Currency:
  801. format_index = number_system->currency_format;
  802. break;
  803. case StandardNumberFormatType::Accounting:
  804. format_index = number_system->accounting_format;
  805. break;
  806. case StandardNumberFormatType::Percent:
  807. format_index = number_system->percent_format;
  808. break;
  809. case StandardNumberFormatType::Scientific:
  810. format_index = number_system->scientific_format;
  811. break;
  812. }
  813. return s_number_formats[format_index].to_unicode_number_format();
  814. }
  815. return {};
  816. }
  817. Vector<NumberFormat> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type)
  818. {
  819. Vector<NumberFormat> formats;
  820. if (auto const* number_system = find_number_system(locale, system); number_system != nullptr) {
  821. @number_format_list_index_type@ number_format_list_index { 0 };
  822. switch (type) {
  823. case CompactNumberFormatType::DecimalLong:
  824. number_format_list_index = number_system->decimal_long_formats;
  825. break;
  826. case CompactNumberFormatType::DecimalShort:
  827. number_format_list_index = number_system->decimal_short_formats;
  828. break;
  829. case CompactNumberFormatType::CurrencyUnit:
  830. number_format_list_index = number_system->currency_unit_formats;
  831. break;
  832. case CompactNumberFormatType::CurrencyShort:
  833. number_format_list_index = number_system->currency_short_formats;
  834. break;
  835. }
  836. auto number_formats = s_number_format_lists.at(number_format_list_index);
  837. formats.ensure_capacity(number_formats.size());
  838. for (auto number_format : number_formats)
  839. formats.append(s_number_formats[number_format].to_unicode_number_format());
  840. }
  841. return formats;
  842. }
  843. static Unit const* find_units(StringView locale, StringView unit)
  844. {
  845. auto locale_value = locale_from_string(locale);
  846. if (!locale_value.has_value())
  847. return nullptr;
  848. auto locale_index = to_underlying(*locale_value) - 1; // Subtract 1 because 0 == Locale::None.
  849. auto const& locale_units = s_locale_units.at(locale_index);
  850. for (auto unit_index : locale_units) {
  851. auto const& units = s_units.at(unit_index);
  852. if (unit == s_string_list[units.unit])
  853. return &units;
  854. };
  855. return nullptr;
  856. }
  857. Vector<NumberFormat> get_unit_formats(StringView locale, StringView unit, Style style)
  858. {
  859. Vector<NumberFormat> formats;
  860. if (auto const* units = find_units(locale, unit); units != nullptr) {
  861. @number_format_list_index_type@ number_format_list_index { 0 };
  862. switch (style) {
  863. case Style::Long:
  864. number_format_list_index = units->long_formats;
  865. break;
  866. case Style::Short:
  867. number_format_list_index = units->short_formats;
  868. break;
  869. case Style::Narrow:
  870. number_format_list_index = units->narrow_formats;
  871. break;
  872. default:
  873. VERIFY_NOT_REACHED();
  874. }
  875. auto number_formats = s_number_format_lists.at(number_format_list_index);
  876. formats.ensure_capacity(number_formats.size());
  877. for (auto number_format : number_formats)
  878. formats.append(s_number_formats[number_format].to_unicode_number_format());
  879. }
  880. return formats;
  881. }
  882. }
  883. )~~~");
  884. TRY(file.write(generator.as_string_view().bytes()));
  885. return {};
  886. }
  887. ErrorOr<int> serenity_main(Main::Arguments arguments)
  888. {
  889. StringView generated_header_path;
  890. StringView generated_implementation_path;
  891. StringView core_path;
  892. StringView numbers_path;
  893. StringView units_path;
  894. Core::ArgsParser args_parser;
  895. args_parser.add_option(generated_header_path, "Path to the Unicode locale header file to generate", "generated-header-path", 'h', "generated-header-path");
  896. args_parser.add_option(generated_implementation_path, "Path to the Unicode locale implementation file to generate", "generated-implementation-path", 'c', "generated-implementation-path");
  897. args_parser.add_option(core_path, "Path to cldr-core directory", "core-path", 'r', "core-path");
  898. args_parser.add_option(numbers_path, "Path to cldr-numbers directory", "numbers-path", 'n', "numbers-path");
  899. args_parser.add_option(units_path, "Path to cldr-units directory", "units-path", 'u', "units-path");
  900. args_parser.parse(arguments);
  901. auto generated_header_file = TRY(open_file(generated_header_path, Core::Stream::OpenMode::Write));
  902. auto generated_implementation_file = TRY(open_file(generated_implementation_path, Core::Stream::OpenMode::Write));
  903. UnicodeLocaleData locale_data;
  904. TRY(parse_all_locales(core_path, numbers_path, units_path, locale_data));
  905. TRY(generate_unicode_locale_header(*generated_header_file, locale_data));
  906. TRY(generate_unicode_locale_implementation(*generated_implementation_file, locale_data));
  907. return 0;
  908. }