GenerateUnicodeNumberFormat.cpp 45 KB

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