GenerateUnicodeNumberFormat.cpp 45 KB

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