GenerateUnicodeData.cpp 43 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/HashMap.h>
  12. #include <AK/Optional.h>
  13. #include <AK/QuickSort.h>
  14. #include <AK/SourceGenerator.h>
  15. #include <AK/String.h>
  16. #include <AK/StringUtils.h>
  17. #include <AK/Types.h>
  18. #include <AK/Vector.h>
  19. #include <LibCore/ArgsParser.h>
  20. #include <LibCore/File.h>
  21. // Some code points are excluded from UnicodeData.txt, and instead are part of a "range" of code
  22. // points, as indicated by the "name" field. For example:
  23. // 3400;<CJK Ideograph Extension A, First>;Lo;0;L;;;;;N;;;;;
  24. // 4DBF;<CJK Ideograph Extension A, Last>;Lo;0;L;;;;;N;;;;;
  25. struct CodePointRange {
  26. u32 first;
  27. u32 last;
  28. };
  29. // SpecialCasing source: https://www.unicode.org/Public/13.0.0/ucd/SpecialCasing.txt
  30. // Field descriptions: https://www.unicode.org/reports/tr44/tr44-13.html#SpecialCasing.txt
  31. struct SpecialCasing {
  32. u32 index { 0 };
  33. u32 code_point { 0 };
  34. Vector<u32> lowercase_mapping;
  35. Vector<u32> uppercase_mapping;
  36. Vector<u32> titlecase_mapping;
  37. String locale;
  38. String condition;
  39. };
  40. // PropList source: https://www.unicode.org/Public/13.0.0/ucd/PropList.txt
  41. // Property descriptions: https://www.unicode.org/reports/tr44/tr44-13.html#PropList.txt
  42. using PropList = HashMap<String, Vector<CodePointRange>>;
  43. // Normalization source: https://www.unicode.org/Public/13.0.0/ucd/DerivedNormalizationProps.txt
  44. // Normalization descriptions: https://www.unicode.org/reports/tr44/#DerivedNormalizationProps.txt
  45. enum class QuickCheck {
  46. Yes,
  47. No,
  48. Maybe,
  49. };
  50. struct Normalization {
  51. CodePointRange code_point_range;
  52. Vector<u32> value;
  53. QuickCheck quick_check { QuickCheck::Yes };
  54. };
  55. using NormalizationProps = HashMap<String, Vector<Normalization>>;
  56. // UnicodeData source: https://www.unicode.org/Public/13.0.0/ucd/UnicodeData.txt
  57. // Field descriptions: https://www.unicode.org/reports/tr44/tr44-13.html#UnicodeData.txt
  58. // https://www.unicode.org/reports/tr44/#General_Category_Values
  59. struct CodePointData {
  60. u32 code_point { 0 };
  61. String name;
  62. u8 canonical_combining_class { 0 };
  63. String bidi_class;
  64. String decomposition_type;
  65. Optional<i8> numeric_value_decimal;
  66. Optional<i8> numeric_value_digit;
  67. Optional<i8> numeric_value_numeric;
  68. bool bidi_mirrored { false };
  69. String unicode_1_name;
  70. String iso_comment;
  71. Optional<u32> simple_uppercase_mapping;
  72. Optional<u32> simple_lowercase_mapping;
  73. Optional<u32> simple_titlecase_mapping;
  74. Vector<u32> special_casing_indices;
  75. };
  76. struct UnicodeData {
  77. u32 code_points_with_non_zero_combining_class { 0 };
  78. u32 simple_uppercase_mapping_size { 0 };
  79. u32 simple_lowercase_mapping_size { 0 };
  80. Vector<SpecialCasing> special_casing;
  81. u32 code_points_with_special_casing { 0 };
  82. u32 largest_casing_transform_size { 0 };
  83. u32 largest_special_casing_size { 0 };
  84. Vector<String> conditions;
  85. Vector<CodePointData> code_point_data;
  86. Vector<CodePointRange> code_point_ranges;
  87. PropList general_categories;
  88. Vector<Alias> general_category_aliases;
  89. // The Unicode standard defines additional properties (Any, Assigned, ASCII) which are not in
  90. // any UCD file. Assigned code point ranges are derived as this generator is executed.
  91. // https://unicode.org/reports/tr18/#General_Category_Property
  92. PropList prop_list {
  93. { "Any"sv, { { 0, 0x10ffff } } },
  94. { "Assigned"sv, {} },
  95. { "ASCII"sv, { { 0, 0x7f } } },
  96. };
  97. Vector<Alias> prop_aliases;
  98. PropList script_list {
  99. { "Unknown"sv, {} },
  100. };
  101. Vector<Alias> script_aliases;
  102. PropList script_extensions;
  103. // FIXME: We are not yet doing anything with this data. It will be needed for String.prototype.normalize.
  104. NormalizationProps normalization_props;
  105. };
  106. static Vector<u32> parse_code_point_list(StringView list)
  107. {
  108. Vector<u32> code_points;
  109. auto segments = list.split_view(' ');
  110. for (auto const& code_point : segments)
  111. code_points.append(AK::StringUtils::convert_to_uint_from_hex<u32>(code_point).value());
  112. return code_points;
  113. }
  114. static CodePointRange parse_code_point_range(StringView list)
  115. {
  116. CodePointRange code_point_range {};
  117. if (list.contains(".."sv)) {
  118. auto segments = list.split_view(".."sv);
  119. VERIFY(segments.size() == 2);
  120. auto begin = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[0]).value();
  121. auto end = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[1]).value();
  122. code_point_range = { begin, end };
  123. } else {
  124. auto code_point = AK::StringUtils::convert_to_uint_from_hex<u32>(list).value();
  125. code_point_range = { code_point, code_point };
  126. }
  127. return code_point_range;
  128. }
  129. static void parse_special_casing(Core::File& file, UnicodeData& unicode_data)
  130. {
  131. while (file.can_read_line()) {
  132. auto line = file.read_line();
  133. if (line.is_empty() || line.starts_with('#'))
  134. continue;
  135. if (auto index = line.find('#'); index.has_value())
  136. line = line.substring(0, *index);
  137. auto segments = line.split(';', true);
  138. VERIFY(segments.size() == 5 || segments.size() == 6);
  139. SpecialCasing casing {};
  140. casing.code_point = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[0]).value();
  141. casing.lowercase_mapping = parse_code_point_list(segments[1]);
  142. casing.titlecase_mapping = parse_code_point_list(segments[2]);
  143. casing.uppercase_mapping = parse_code_point_list(segments[3]);
  144. if (auto condition = segments[4].trim_whitespace(); !condition.is_empty()) {
  145. auto conditions = condition.split(' ', true);
  146. VERIFY(conditions.size() == 1 || conditions.size() == 2);
  147. if (conditions.size() == 2) {
  148. casing.locale = move(conditions[0]);
  149. casing.condition = move(conditions[1]);
  150. } else if (all_of(conditions[0], is_ascii_lower_alpha)) {
  151. casing.locale = move(conditions[0]);
  152. } else {
  153. casing.condition = move(conditions[0]);
  154. }
  155. if (!casing.locale.is_empty())
  156. casing.locale = String::formatted("{:c}{}", to_ascii_uppercase(casing.locale[0]), casing.locale.substring_view(1));
  157. casing.condition = casing.condition.replace("_", "", true);
  158. if (!casing.condition.is_empty() && !unicode_data.conditions.contains_slow(casing.condition))
  159. unicode_data.conditions.append(casing.condition);
  160. }
  161. unicode_data.largest_casing_transform_size = max(unicode_data.largest_casing_transform_size, casing.lowercase_mapping.size());
  162. unicode_data.largest_casing_transform_size = max(unicode_data.largest_casing_transform_size, casing.titlecase_mapping.size());
  163. unicode_data.largest_casing_transform_size = max(unicode_data.largest_casing_transform_size, casing.uppercase_mapping.size());
  164. unicode_data.special_casing.append(move(casing));
  165. }
  166. quick_sort(unicode_data.special_casing, [](auto const& lhs, auto const& rhs) {
  167. if (lhs.code_point != rhs.code_point)
  168. return lhs.code_point < rhs.code_point;
  169. if (lhs.locale.is_empty() && !rhs.locale.is_empty())
  170. return false;
  171. if (!lhs.locale.is_empty() && rhs.locale.is_empty())
  172. return true;
  173. return lhs.locale < rhs.locale;
  174. });
  175. for (u32 i = 0; i < unicode_data.special_casing.size(); ++i)
  176. unicode_data.special_casing[i].index = i;
  177. }
  178. static void parse_prop_list(Core::File& file, PropList& prop_list, bool multi_value_property = false)
  179. {
  180. while (file.can_read_line()) {
  181. auto line = file.read_line();
  182. if (line.is_empty() || line.starts_with('#'))
  183. continue;
  184. if (auto index = line.find('#'); index.has_value())
  185. line = line.substring(0, *index);
  186. auto segments = line.split_view(';', true);
  187. VERIFY(segments.size() == 2);
  188. auto code_point_range = parse_code_point_range(segments[0].trim_whitespace());
  189. Vector<StringView> properties;
  190. if (multi_value_property)
  191. properties = segments[1].trim_whitespace().split_view(' ');
  192. else
  193. properties = { segments[1].trim_whitespace() };
  194. for (auto const& property : properties) {
  195. auto& code_points = prop_list.ensure(property.trim_whitespace());
  196. code_points.append(code_point_range);
  197. }
  198. }
  199. }
  200. static void parse_alias_list(Core::File& file, PropList const& prop_list, Vector<Alias>& prop_aliases)
  201. {
  202. String current_property;
  203. auto append_alias = [&](auto alias, auto property) {
  204. // Note: The alias files contain lines such as "Hyphen = Hyphen", which we should just skip.
  205. if (alias == property)
  206. return;
  207. // FIXME: We will, eventually, need to find where missing properties are located and parse them.
  208. if (!prop_list.contains(property))
  209. return;
  210. prop_aliases.append({ property, alias });
  211. };
  212. while (file.can_read_line()) {
  213. auto line = file.read_line();
  214. if (line.is_empty() || line.starts_with('#')) {
  215. if (line.ends_with("Properties"sv))
  216. current_property = line.substring(2);
  217. continue;
  218. }
  219. // Note: For now, we only care about Binary Property aliases for Unicode property escapes.
  220. if (current_property != "Binary Properties"sv)
  221. continue;
  222. auto segments = line.split_view(';', true);
  223. VERIFY((segments.size() == 2) || (segments.size() == 3));
  224. auto alias = segments[0].trim_whitespace();
  225. auto property = segments[1].trim_whitespace();
  226. append_alias(alias, property);
  227. if (segments.size() == 3) {
  228. alias = segments[2].trim_whitespace();
  229. append_alias(alias, property);
  230. }
  231. }
  232. }
  233. static void parse_name_aliases(Core::File& file, Vector<CodePointData>& code_point_data)
  234. {
  235. auto iterator = code_point_data.begin();
  236. VERIFY(!iterator.is_end());
  237. // We use a single iterator because both lists should be sorted, and repeated lookups are unnecessary.
  238. auto code_point_data_at = [&iterator](u32 code_point) -> CodePointData& {
  239. VERIFY(!iterator.is_end());
  240. while (iterator->code_point < code_point) {
  241. ++iterator;
  242. VERIFY(!iterator.is_end());
  243. }
  244. VERIFY(iterator->code_point == code_point);
  245. return *iterator;
  246. };
  247. // We always use the *first* "control"-type alias. The actual reason for this is to avoid the silly name "END OF LINE" for code point 0x000a.
  248. u32 last_overridden = (u32)-1;
  249. while (file.can_read_line()) {
  250. auto line = file.read_line();
  251. if (line.is_empty() || line.starts_with('#'))
  252. continue;
  253. auto segments = line.split_view(';', true);
  254. VERIFY(segments.size() == 3);
  255. auto code_point_optional = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[0].trim_whitespace());
  256. auto alias = segments[1].trim_whitespace();
  257. auto reason = segments[2].trim_whitespace();
  258. VERIFY(code_point_optional.has_value());
  259. VERIFY(!alias.is_empty());
  260. // Thankfully, there is no correction alias for any of the control code points (yet).
  261. if (!reason.is_one_of("correction", "control"))
  262. continue;
  263. auto code_point = code_point_optional.value();
  264. if (code_point == last_overridden)
  265. continue;
  266. code_point_data_at(code_point).name = alias;
  267. last_overridden = code_point;
  268. }
  269. }
  270. static void parse_value_alias_list(Core::File& file, StringView desired_category, Vector<String> const& value_list, Vector<Alias>& prop_aliases, bool primary_value_is_first = true)
  271. {
  272. VERIFY(file.seek(0));
  273. auto append_alias = [&](auto alias, auto value) {
  274. // Note: The value alias file contains lines such as "Ahom = Ahom", which we should just skip.
  275. if (alias == value)
  276. return;
  277. // FIXME: We will, eventually, need to find where missing properties are located and parse them.
  278. if (!value_list.contains_slow(value))
  279. return;
  280. prop_aliases.append({ value, alias });
  281. };
  282. while (file.can_read_line()) {
  283. auto line = file.read_line();
  284. if (line.is_empty() || line.starts_with('#'))
  285. continue;
  286. if (auto index = line.find('#'); index.has_value())
  287. line = line.substring(0, *index);
  288. auto segments = line.split_view(';', true);
  289. auto category = segments[0].trim_whitespace();
  290. if (category != desired_category)
  291. continue;
  292. VERIFY((segments.size() == 3) || (segments.size() == 4));
  293. auto value = primary_value_is_first ? segments[1].trim_whitespace() : segments[2].trim_whitespace();
  294. auto alias = primary_value_is_first ? segments[2].trim_whitespace() : segments[1].trim_whitespace();
  295. append_alias(alias, value);
  296. if (segments.size() == 4) {
  297. alias = segments[3].trim_whitespace();
  298. append_alias(alias, value);
  299. }
  300. }
  301. }
  302. static void parse_normalization_props(Core::File& file, UnicodeData& unicode_data)
  303. {
  304. while (file.can_read_line()) {
  305. auto line = file.read_line();
  306. if (line.is_empty() || line.starts_with('#'))
  307. continue;
  308. if (auto index = line.find('#'); index.has_value())
  309. line = line.substring(0, *index);
  310. auto segments = line.split_view(';', true);
  311. VERIFY((segments.size() == 2) || (segments.size() == 3));
  312. auto code_point_range = parse_code_point_range(segments[0].trim_whitespace());
  313. auto property = segments[1].trim_whitespace().to_string();
  314. Vector<u32> value;
  315. QuickCheck quick_check = QuickCheck::Yes;
  316. if (segments.size() == 3) {
  317. auto value_or_quick_check = segments[2].trim_whitespace();
  318. if ((value_or_quick_check == "N"sv))
  319. quick_check = QuickCheck::No;
  320. else if ((value_or_quick_check == "M"sv))
  321. quick_check = QuickCheck::Maybe;
  322. else
  323. value = parse_code_point_list(value_or_quick_check);
  324. }
  325. auto& normalizations = unicode_data.normalization_props.ensure(property);
  326. normalizations.append({ code_point_range, move(value), quick_check });
  327. auto& prop_list = unicode_data.prop_list.ensure(property);
  328. prop_list.append(move(code_point_range));
  329. }
  330. }
  331. static void parse_unicode_data(Core::File& file, UnicodeData& unicode_data)
  332. {
  333. Optional<u32> code_point_range_start;
  334. auto& assigned_code_points = unicode_data.prop_list.find("Assigned"sv)->value;
  335. Optional<u32> assigned_code_point_range_start = 0;
  336. u32 previous_code_point = 0;
  337. while (file.can_read_line()) {
  338. auto line = file.read_line();
  339. if (line.is_empty())
  340. continue;
  341. auto segments = line.split(';', true);
  342. VERIFY(segments.size() == 15);
  343. CodePointData data {};
  344. data.code_point = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[0]).value();
  345. data.name = move(segments[1]);
  346. data.canonical_combining_class = AK::StringUtils::convert_to_uint<u8>(segments[3]).value();
  347. data.bidi_class = move(segments[4]);
  348. data.decomposition_type = move(segments[5]);
  349. data.numeric_value_decimal = AK::StringUtils::convert_to_int<i8>(segments[6]);
  350. data.numeric_value_digit = AK::StringUtils::convert_to_int<i8>(segments[7]);
  351. data.numeric_value_numeric = AK::StringUtils::convert_to_int<i8>(segments[8]);
  352. data.bidi_mirrored = segments[9] == "Y"sv;
  353. data.unicode_1_name = move(segments[10]);
  354. data.iso_comment = move(segments[11]);
  355. data.simple_uppercase_mapping = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[12]);
  356. data.simple_lowercase_mapping = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[13]);
  357. data.simple_titlecase_mapping = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[14]);
  358. if (!assigned_code_point_range_start.has_value())
  359. assigned_code_point_range_start = data.code_point;
  360. if (data.name.starts_with("<"sv) && data.name.ends_with(", First>")) {
  361. VERIFY(!code_point_range_start.has_value() && assigned_code_point_range_start.has_value());
  362. code_point_range_start = data.code_point;
  363. data.name = data.name.substring(1, data.name.length() - 9);
  364. assigned_code_points.append({ *assigned_code_point_range_start, previous_code_point });
  365. assigned_code_point_range_start.clear();
  366. } else if (data.name.starts_with("<"sv) && data.name.ends_with(", Last>")) {
  367. VERIFY(code_point_range_start.has_value());
  368. CodePointRange code_point_range { *code_point_range_start, data.code_point };
  369. unicode_data.code_point_ranges.append(code_point_range);
  370. assigned_code_points.append(code_point_range);
  371. data.name = data.name.substring(1, data.name.length() - 8);
  372. code_point_range_start.clear();
  373. } else if ((data.code_point > 0) && (data.code_point - previous_code_point) != 1) {
  374. VERIFY(assigned_code_point_range_start.has_value());
  375. assigned_code_points.append({ *assigned_code_point_range_start, previous_code_point });
  376. assigned_code_point_range_start = data.code_point;
  377. }
  378. bool has_special_casing { false };
  379. for (auto const& casing : unicode_data.special_casing) {
  380. if (casing.code_point == data.code_point) {
  381. data.special_casing_indices.append(casing.index);
  382. has_special_casing = true;
  383. }
  384. }
  385. unicode_data.code_points_with_non_zero_combining_class += data.canonical_combining_class != 0;
  386. unicode_data.simple_uppercase_mapping_size += data.simple_uppercase_mapping.has_value();
  387. unicode_data.simple_lowercase_mapping_size += data.simple_lowercase_mapping.has_value();
  388. unicode_data.code_points_with_special_casing += has_special_casing;
  389. unicode_data.largest_special_casing_size = max(unicode_data.largest_special_casing_size, data.special_casing_indices.size());
  390. previous_code_point = data.code_point;
  391. unicode_data.code_point_data.append(move(data));
  392. }
  393. }
  394. static void generate_unicode_data_header(Core::File& file, UnicodeData& unicode_data)
  395. {
  396. StringBuilder builder;
  397. SourceGenerator generator { builder };
  398. generator.set("casing_transform_size", String::number(unicode_data.largest_casing_transform_size));
  399. auto generate_enum = [&](StringView name, StringView default_, Vector<String> values, Vector<Alias> aliases = {}) {
  400. quick_sort(values);
  401. quick_sort(aliases, [](auto& alias1, auto& alias2) { return alias1.alias < alias2.alias; });
  402. generator.set("name", name);
  403. generator.set("underlying", String::formatted("{}UnderlyingType", name));
  404. generator.append(R"~~~(
  405. using @underlying@ = u8;
  406. enum class @name@ : @underlying@ {)~~~");
  407. if (!default_.is_empty()) {
  408. generator.set("default", default_);
  409. generator.append(R"~~~(
  410. @default@,)~~~");
  411. }
  412. for (auto const& value : values) {
  413. generator.set("value", value);
  414. generator.append(R"~~~(
  415. @value@,)~~~");
  416. }
  417. for (auto const& alias : aliases) {
  418. generator.set("alias", alias.alias);
  419. generator.set("value", alias.name);
  420. generator.append(R"~~~(
  421. @alias@ = @value@,)~~~");
  422. }
  423. generator.append(R"~~~(
  424. };
  425. )~~~");
  426. };
  427. generator.append(R"~~~(
  428. #pragma once
  429. #include <AK/Optional.h>
  430. #include <AK/Span.h>
  431. #include <AK/Types.h>
  432. #include <LibUnicode/Forward.h>
  433. #include <LibUnicode/UnicodeLocale.h>
  434. namespace Unicode {
  435. )~~~");
  436. generate_enum("Condition"sv, "None"sv, move(unicode_data.conditions));
  437. generate_enum("GeneralCategory"sv, {}, unicode_data.general_categories.keys(), unicode_data.general_category_aliases);
  438. generate_enum("Property"sv, {}, unicode_data.prop_list.keys(), unicode_data.prop_aliases);
  439. generate_enum("Script"sv, {}, unicode_data.script_list.keys(), unicode_data.script_aliases);
  440. generator.append(R"~~~(
  441. struct SpecialCasing {
  442. u32 code_point { 0 };
  443. u32 lowercase_mapping[@casing_transform_size@];
  444. u32 lowercase_mapping_size { 0 };
  445. u32 uppercase_mapping[@casing_transform_size@];
  446. u32 uppercase_mapping_size { 0 };
  447. u32 titlecase_mapping[@casing_transform_size@];
  448. u32 titlecase_mapping_size { 0 };
  449. Locale locale { Locale::None };
  450. Condition condition { Condition::None };
  451. };
  452. namespace Detail {
  453. StringView code_point_display_name(u32 code_point);
  454. u32 canonical_combining_class(u32 code_point);
  455. u32 simple_uppercase_mapping(u32 code_point);
  456. u32 simple_lowercase_mapping(u32 code_point);
  457. Span<SpecialCasing const* const> special_case_mapping(u32 code_point);
  458. bool code_point_has_general_category(u32 code_point, GeneralCategory general_category);
  459. Optional<GeneralCategory> general_category_from_string(StringView general_category);
  460. bool code_point_has_property(u32 code_point, Property property);
  461. Optional<Property> property_from_string(StringView property);
  462. bool code_point_has_script(u32 code_point, Script script);
  463. bool code_point_has_script_extension(u32 code_point, Script script);
  464. Optional<Script> script_from_string(StringView script);
  465. }
  466. }
  467. )~~~");
  468. VERIFY(file.write(generator.as_string_view()));
  469. }
  470. static void generate_unicode_data_implementation(Core::File& file, UnicodeData const& unicode_data)
  471. {
  472. StringBuilder builder;
  473. SourceGenerator generator { builder };
  474. generator.set("largest_special_casing_size", String::number(unicode_data.largest_special_casing_size));
  475. generator.set("special_casing_size", String::number(unicode_data.special_casing.size()));
  476. generator.append(R"~~~(
  477. #include <AK/Array.h>
  478. #include <AK/BinarySearch.h>
  479. #include <AK/CharacterTypes.h>
  480. #include <AK/String.h>
  481. #include <AK/StringView.h>
  482. #include <LibUnicode/UnicodeData.h>
  483. namespace Unicode {
  484. )~~~");
  485. auto append_list_and_size = [&](auto const& list, StringView format) {
  486. if (list.is_empty()) {
  487. generator.append(", {}, 0");
  488. return;
  489. }
  490. bool first = true;
  491. generator.append(", {");
  492. for (auto const& item : list) {
  493. generator.append(first ? " " : ", ");
  494. generator.append(String::formatted(format, item));
  495. first = false;
  496. }
  497. generator.append(String::formatted(" }}, {}", list.size()));
  498. };
  499. generator.append(R"~~~(
  500. static constexpr Array<SpecialCasing, @special_casing_size@> s_special_casing { {)~~~");
  501. for (auto const& casing : unicode_data.special_casing) {
  502. generator.set("code_point", String::formatted("{:#x}", casing.code_point));
  503. generator.append(R"~~~(
  504. { @code_point@)~~~");
  505. constexpr auto format = "0x{:x}"sv;
  506. append_list_and_size(casing.lowercase_mapping, format);
  507. append_list_and_size(casing.uppercase_mapping, format);
  508. append_list_and_size(casing.titlecase_mapping, format);
  509. generator.set("locale", casing.locale.is_empty() ? "None" : casing.locale);
  510. generator.append(", Locale::@locale@");
  511. generator.set("condition", casing.condition.is_empty() ? "None" : casing.condition);
  512. generator.append(", Condition::@condition@");
  513. generator.append(" },");
  514. }
  515. generator.append(R"~~~(
  516. } };
  517. struct CodePointMapping {
  518. u32 code_point { 0 };
  519. u32 mapping { 0 };
  520. };
  521. struct SpecialCaseMapping {
  522. u32 code_point { 0 };
  523. Array<SpecialCasing const*, @largest_special_casing_size@> special_casing {};
  524. u32 special_casing_size { 0 };
  525. };
  526. template<typename MappingType>
  527. struct CodePointComparator {
  528. constexpr int operator()(u32 code_point, MappingType const& mapping)
  529. {
  530. return code_point - mapping.code_point;
  531. }
  532. };
  533. )~~~");
  534. auto append_code_point_mappings = [&](StringView name, StringView mapping_type, u32 size, auto mapping_getter) {
  535. generator.set("name", name);
  536. generator.set("mapping_type", mapping_type);
  537. generator.set("size", String::number(size));
  538. generator.append(R"~~~(
  539. static constexpr Array<@mapping_type@, @size@> s_@name@_mappings { {
  540. )~~~");
  541. constexpr size_t max_mappings_per_row = 20;
  542. size_t mappings_in_current_row = 0;
  543. for (auto const& data : unicode_data.code_point_data) {
  544. auto mapping = mapping_getter(data);
  545. if constexpr (IsSame<decltype(mapping), Optional<u32>>) {
  546. if (!mapping.has_value())
  547. continue;
  548. } else {
  549. if (mapping.is_empty())
  550. continue;
  551. }
  552. if (mappings_in_current_row++ > 0)
  553. generator.append(" ");
  554. generator.set("code_point", String::formatted("{:#x}", data.code_point));
  555. generator.append("{ @code_point@");
  556. if constexpr (IsSame<decltype(mapping), Optional<u32>>) {
  557. generator.set("mapping", String::formatted("{:#x}", *mapping));
  558. generator.append(", @mapping@ },");
  559. } else {
  560. append_list_and_size(data.special_casing_indices, "&s_special_casing[{}]"sv);
  561. generator.append(" },");
  562. }
  563. if (mappings_in_current_row == max_mappings_per_row) {
  564. mappings_in_current_row = 0;
  565. generator.append("\n ");
  566. }
  567. }
  568. generator.append(R"~~~(
  569. } };
  570. )~~~");
  571. };
  572. append_code_point_mappings("combining_class"sv, "CodePointMapping"sv, unicode_data.code_points_with_non_zero_combining_class,
  573. [](auto const& data) -> Optional<u32> {
  574. if (data.canonical_combining_class == 0)
  575. return {};
  576. return data.canonical_combining_class;
  577. });
  578. append_code_point_mappings("uppercase"sv, "CodePointMapping"sv, unicode_data.simple_uppercase_mapping_size, [](auto const& data) { return data.simple_uppercase_mapping; });
  579. append_code_point_mappings("lowercase"sv, "CodePointMapping"sv, unicode_data.simple_lowercase_mapping_size, [](auto const& data) { return data.simple_lowercase_mapping; });
  580. append_code_point_mappings("special_case"sv, "SpecialCaseMapping"sv, unicode_data.code_points_with_special_casing, [](auto const& data) { return data.special_casing_indices; });
  581. generator.append(R"~~~(
  582. struct CodePointRange {
  583. u32 first { 0 };
  584. u32 last { 0 };
  585. };
  586. struct CodePointRangeComparator {
  587. constexpr int operator()(u32 code_point, CodePointRange const& range)
  588. {
  589. return (code_point > range.last) - (code_point < range.first);
  590. }
  591. };
  592. )~~~");
  593. auto append_code_point_range_list = [&](String name, Vector<CodePointRange> const& ranges) {
  594. generator.set("name", name);
  595. generator.set("size", String::number(ranges.size()));
  596. generator.append(R"~~~(
  597. static constexpr Array<CodePointRange, @size@> @name@ { {
  598. )~~~");
  599. constexpr size_t max_ranges_per_row = 20;
  600. size_t ranges_in_current_row = 0;
  601. for (auto const& range : ranges) {
  602. if (ranges_in_current_row++ > 0)
  603. generator.append(" ");
  604. generator.set("first", String::formatted("{:#x}", range.first));
  605. generator.set("last", String::formatted("{:#x}", range.last));
  606. generator.append("{ @first@, @last@ },");
  607. if (ranges_in_current_row == max_ranges_per_row) {
  608. ranges_in_current_row = 0;
  609. generator.append("\n ");
  610. }
  611. }
  612. generator.append(R"~~~(
  613. } };
  614. )~~~");
  615. };
  616. auto append_prop_list = [&](StringView collection_name, StringView property_format, PropList const& property_list) {
  617. for (auto const& property : property_list) {
  618. auto name = String::formatted(property_format, property.key);
  619. append_code_point_range_list(move(name), property.value);
  620. }
  621. auto property_names = property_list.keys();
  622. quick_sort(property_names);
  623. generator.set("name", collection_name);
  624. generator.set("size", String::number(property_names.size()));
  625. generator.append(R"~~~(
  626. static constexpr Array<Span<CodePointRange const>, @size@> @name@ { {)~~~");
  627. for (auto const& property_name : property_names) {
  628. generator.set("name", String::formatted(property_format, property_name));
  629. generator.append(R"~~~(
  630. @name@.span(),)~~~");
  631. }
  632. generator.append(R"~~~(
  633. } };
  634. )~~~");
  635. };
  636. append_prop_list("s_general_categories"sv, "s_general_category_{}"sv, unicode_data.general_categories);
  637. append_prop_list("s_properties"sv, "s_property_{}"sv, unicode_data.prop_list);
  638. append_prop_list("s_scripts"sv, "s_script_{}"sv, unicode_data.script_list);
  639. append_prop_list("s_script_extensions"sv, "s_script_extension_{}"sv, unicode_data.script_extensions);
  640. generator.append(R"~~~(
  641. struct CodePointName {
  642. u32 code_point { 0 };
  643. StringView display_name;
  644. };
  645. )~~~");
  646. generator.set("code_point_names_size", String::number(unicode_data.code_point_data.size()));
  647. generator.append(R"~~~(
  648. static constexpr Array<CodePointName, @code_point_names_size@> s_code_point_names { {
  649. )~~~");
  650. for (auto const& code_point_data : unicode_data.code_point_data) {
  651. generator.set("code_point", String::formatted("{:#x}", code_point_data.code_point));
  652. generator.set("code_point_name", code_point_data.name);
  653. generator.append(R"~~~( { @code_point@, "@code_point_name@"sv },
  654. )~~~");
  655. }
  656. generator.append(R"~~~(} };
  657. )~~~");
  658. generator.append(R"~~~(
  659. namespace Detail {
  660. StringView code_point_display_name(u32 code_point)
  661. {
  662. auto const* entry = binary_search(s_code_point_names, code_point, nullptr, CodePointComparator<CodePointName> {});
  663. return entry ? entry->display_name : StringView();
  664. }
  665. )~~~");
  666. auto append_code_point_mapping_search = [&](StringView method, StringView mappings, StringView fallback) {
  667. generator.set("method", method);
  668. generator.set("mappings", mappings);
  669. generator.set("fallback", fallback);
  670. generator.append(R"~~~(
  671. u32 @method@(u32 code_point)
  672. {
  673. auto const* mapping = binary_search(@mappings@, code_point, nullptr, CodePointComparator<CodePointMapping> {});
  674. return mapping ? mapping->mapping : @fallback@;
  675. }
  676. )~~~");
  677. };
  678. append_code_point_mapping_search("canonical_combining_class"sv, "s_combining_class_mappings"sv, "0"sv);
  679. append_code_point_mapping_search("simple_uppercase_mapping"sv, "s_uppercase_mappings"sv, "code_point"sv);
  680. append_code_point_mapping_search("simple_lowercase_mapping"sv, "s_lowercase_mappings"sv, "code_point"sv);
  681. generator.append(R"~~~(
  682. Span<SpecialCasing const* const> special_case_mapping(u32 code_point)
  683. {
  684. auto const* mapping = binary_search(s_special_case_mappings, code_point, nullptr, CodePointComparator<SpecialCaseMapping> {});
  685. if (mapping == nullptr)
  686. return {};
  687. return mapping->special_casing.span().slice(0, mapping->special_casing_size);
  688. }
  689. )~~~");
  690. auto append_prop_search = [&](StringView enum_title, StringView enum_snake, StringView collection_name) {
  691. generator.set("enum_title", enum_title);
  692. generator.set("enum_snake", enum_snake);
  693. generator.set("collection_name", collection_name);
  694. generator.append(R"~~~(
  695. bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@)
  696. {
  697. auto index = static_cast<@enum_title@UnderlyingType>(@enum_snake@);
  698. auto const& ranges = @collection_name@.at(index);
  699. auto const* range = binary_search(ranges, code_point, nullptr, CodePointRangeComparator {});
  700. return range != nullptr;
  701. }
  702. )~~~");
  703. };
  704. auto append_from_string = [&](StringView enum_title, StringView enum_snake, PropList const& prop_list, Vector<Alias> const& aliases) {
  705. HashValueMap<StringView> hashes;
  706. hashes.ensure_capacity(prop_list.size() + aliases.size());
  707. for (auto const& prop : prop_list)
  708. hashes.set(prop.key.hash(), prop.key);
  709. for (auto const& alias : aliases)
  710. hashes.set(alias.alias.hash(), alias.alias);
  711. generate_value_from_string(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes));
  712. };
  713. append_prop_search("GeneralCategory"sv, "general_category"sv, "s_general_categories"sv);
  714. append_from_string("GeneralCategory"sv, "general_category"sv, unicode_data.general_categories, unicode_data.general_category_aliases);
  715. append_prop_search("Property"sv, "property"sv, "s_properties"sv);
  716. append_from_string("Property"sv, "property"sv, unicode_data.prop_list, unicode_data.prop_aliases);
  717. append_prop_search("Script"sv, "script"sv, "s_scripts"sv);
  718. append_prop_search("Script"sv, "script_extension"sv, "s_script_extensions"sv);
  719. append_from_string("Script"sv, "script"sv, unicode_data.script_list, unicode_data.script_aliases);
  720. generator.append(R"~~~(
  721. }
  722. }
  723. )~~~");
  724. VERIFY(file.write(generator.as_string_view()));
  725. }
  726. static Vector<u32> flatten_code_point_ranges(Vector<CodePointRange> const& code_points)
  727. {
  728. Vector<u32> flattened;
  729. for (auto const& range : code_points) {
  730. flattened.grow_capacity(range.last - range.first);
  731. for (u32 code_point = range.first; code_point <= range.last; ++code_point)
  732. flattened.append(code_point);
  733. }
  734. return flattened;
  735. }
  736. static Vector<CodePointRange> form_code_point_ranges(Vector<u32> code_points)
  737. {
  738. Vector<CodePointRange> ranges;
  739. u32 range_start = code_points[0];
  740. u32 range_end = range_start;
  741. for (size_t i = 1; i < code_points.size(); ++i) {
  742. u32 code_point = code_points[i];
  743. if ((code_point - range_end) == 1) {
  744. range_end = code_point;
  745. } else {
  746. ranges.append({ range_start, range_end });
  747. range_start = code_point;
  748. range_end = code_point;
  749. }
  750. }
  751. ranges.append({ range_start, range_end });
  752. return ranges;
  753. }
  754. static void sort_and_merge_code_point_ranges(Vector<CodePointRange>& code_points)
  755. {
  756. quick_sort(code_points, [](auto const& range1, auto const& range2) {
  757. return range1.first < range2.first;
  758. });
  759. for (size_t i = 0; i < code_points.size() - 1;) {
  760. if (code_points[i].last >= code_points[i + 1].first) {
  761. code_points[i].last = max(code_points[i].last, code_points[i + 1].last);
  762. code_points.remove(i + 1);
  763. } else {
  764. ++i;
  765. }
  766. }
  767. auto all_code_points = flatten_code_point_ranges(code_points);
  768. code_points = form_code_point_ranges(all_code_points);
  769. }
  770. static void populate_general_category_unions(PropList& general_categories)
  771. {
  772. // The Unicode standard defines General Category values which are not in any UCD file. These
  773. // values are simply unions of other values.
  774. // https://www.unicode.org/reports/tr44/#GC_Values_Table
  775. auto populate_union = [&](auto alias, auto categories) {
  776. auto& code_points = general_categories.ensure(alias);
  777. for (auto const& category : categories)
  778. code_points.extend(general_categories.find(category)->value);
  779. sort_and_merge_code_point_ranges(code_points);
  780. };
  781. populate_union("LC"sv, Array { "Ll"sv, "Lu"sv, "Lt"sv });
  782. populate_union("L"sv, Array { "Lu"sv, "Ll"sv, "Lt"sv, "Lm"sv, "Lo"sv });
  783. populate_union("M"sv, Array { "Mn"sv, "Mc"sv, "Me"sv });
  784. populate_union("N"sv, Array { "Nd"sv, "Nl"sv, "No"sv });
  785. populate_union("P"sv, Array { "Pc"sv, "Pd"sv, "Ps"sv, "Pe"sv, "Pi"sv, "Pf"sv, "Po"sv });
  786. populate_union("S"sv, Array { "Sm"sv, "Sc"sv, "Sk"sv, "So"sv });
  787. populate_union("Z"sv, Array { "Zs"sv, "Zl"sv, "Zp"sv });
  788. populate_union("C"sv, Array { "Cc"sv, "Cf"sv, "Cs"sv, "Co"sv, "Cn"sv });
  789. }
  790. static void normalize_script_extensions(PropList& script_extensions, PropList const& script_list, Vector<Alias> const& script_aliases)
  791. {
  792. // The ScriptExtensions UCD file lays out its code point ranges rather uniquely compared to
  793. // other files. The Script listed on each line may either be a full Script string or an aliased
  794. // abbreviation. Further, the extensions may or may not include the base Script list. Normalize
  795. // the extensions here to be keyed by the full Script name and always include the base list.
  796. auto extensions = move(script_extensions);
  797. script_extensions = script_list;
  798. for (auto const& extension : extensions) {
  799. auto it = find_if(script_aliases.begin(), script_aliases.end(), [&](auto const& alias) { return extension.key == alias.alias; });
  800. auto const& key = (it == script_aliases.end()) ? extension.key : it->name;
  801. auto& code_points = script_extensions.find(key)->value;
  802. code_points.extend(extension.value);
  803. sort_and_merge_code_point_ranges(code_points);
  804. }
  805. // Lastly, the Common and Inherited script extensions are special. They must not contain any
  806. // code points which appear in other script extensions. The ScriptExtensions UCD file does not
  807. // list these extensions, therefore this peculiarity must be handled programmatically.
  808. // https://www.unicode.org/reports/tr24/#Assignment_ScriptX_Values
  809. auto code_point_has_other_extension = [&](StringView key, u32 code_point) {
  810. for (auto const& extension : extensions) {
  811. if (extension.key == key)
  812. continue;
  813. if (any_of(extension.value, [&](auto const& r) { return (r.first <= code_point) && (code_point <= r.last); }))
  814. return true;
  815. }
  816. return false;
  817. };
  818. auto get_code_points_without_other_extensions = [&](StringView key) {
  819. auto code_points = flatten_code_point_ranges(script_list.find(key)->value);
  820. code_points.remove_all_matching([&](u32 c) { return code_point_has_other_extension(key, c); });
  821. return code_points;
  822. };
  823. auto common_code_points = get_code_points_without_other_extensions("Common"sv);
  824. script_extensions.set("Common"sv, form_code_point_ranges(common_code_points));
  825. auto inherited_code_points = get_code_points_without_other_extensions("Inherited"sv);
  826. script_extensions.set("Inherited"sv, form_code_point_ranges(inherited_code_points));
  827. }
  828. ErrorOr<int> serenity_main(Main::Arguments arguments)
  829. {
  830. StringView generated_header_path;
  831. StringView generated_implementation_path;
  832. StringView unicode_data_path;
  833. StringView special_casing_path;
  834. StringView derived_general_category_path;
  835. StringView prop_list_path;
  836. StringView derived_core_prop_path;
  837. StringView derived_binary_prop_path;
  838. StringView prop_alias_path;
  839. StringView prop_value_alias_path;
  840. StringView name_alias_path;
  841. StringView scripts_path;
  842. StringView script_extensions_path;
  843. StringView emoji_data_path;
  844. StringView normalization_path;
  845. Core::ArgsParser args_parser;
  846. args_parser.add_option(generated_header_path, "Path to the Unicode Data header file to generate", "generated-header-path", 'h', "generated-header-path");
  847. args_parser.add_option(generated_implementation_path, "Path to the Unicode Data implementation file to generate", "generated-implementation-path", 'c', "generated-implementation-path");
  848. args_parser.add_option(unicode_data_path, "Path to UnicodeData.txt file", "unicode-data-path", 'u', "unicode-data-path");
  849. args_parser.add_option(special_casing_path, "Path to SpecialCasing.txt file", "special-casing-path", 's', "special-casing-path");
  850. args_parser.add_option(derived_general_category_path, "Path to DerivedGeneralCategory.txt file", "derived-general-category-path", 'g', "derived-general-category-path");
  851. args_parser.add_option(prop_list_path, "Path to PropList.txt file", "prop-list-path", 'p', "prop-list-path");
  852. args_parser.add_option(derived_core_prop_path, "Path to DerivedCoreProperties.txt file", "derived-core-prop-path", 'd', "derived-core-prop-path");
  853. args_parser.add_option(derived_binary_prop_path, "Path to DerivedBinaryProperties.txt file", "derived-binary-prop-path", 'b', "derived-binary-prop-path");
  854. args_parser.add_option(prop_alias_path, "Path to PropertyAliases.txt file", "prop-alias-path", 'a', "prop-alias-path");
  855. args_parser.add_option(prop_value_alias_path, "Path to PropertyValueAliases.txt file", "prop-value-alias-path", 'v', "prop-value-alias-path");
  856. args_parser.add_option(name_alias_path, "Path to NameAliases.txt file", "name-alias-path", 'm', "name-alias-path");
  857. args_parser.add_option(scripts_path, "Path to Scripts.txt file", "scripts-path", 'r', "scripts-path");
  858. args_parser.add_option(script_extensions_path, "Path to ScriptExtensions.txt file", "script-extensions-path", 'x', "script-extensions-path");
  859. args_parser.add_option(emoji_data_path, "Path to emoji-data.txt file", "emoji-data-path", 'e', "emoji-data-path");
  860. args_parser.add_option(normalization_path, "Path to DerivedNormalizationProps.txt file", "normalization-path", 'n', "normalization-path");
  861. args_parser.parse(arguments);
  862. auto open_file = [&](StringView path, Core::OpenMode mode = Core::OpenMode::ReadOnly) -> ErrorOr<NonnullRefPtr<Core::File>> {
  863. if (path.is_empty()) {
  864. args_parser.print_usage(stderr, arguments.argv[0]);
  865. return Error::from_string_literal("Must provide all command line options"sv);
  866. }
  867. return Core::File::open(path, mode);
  868. };
  869. auto generated_header_file = TRY(open_file(generated_header_path, Core::OpenMode::ReadWrite));
  870. auto generated_implementation_file = TRY(open_file(generated_implementation_path, Core::OpenMode::ReadWrite));
  871. auto unicode_data_file = TRY(open_file(unicode_data_path));
  872. auto derived_general_category_file = TRY(open_file(derived_general_category_path));
  873. auto special_casing_file = TRY(open_file(special_casing_path));
  874. auto prop_list_file = TRY(open_file(prop_list_path));
  875. auto derived_core_prop_file = TRY(open_file(derived_core_prop_path));
  876. auto derived_binary_prop_file = TRY(open_file(derived_binary_prop_path));
  877. auto prop_alias_file = TRY(open_file(prop_alias_path));
  878. auto prop_value_alias_file = TRY(open_file(prop_value_alias_path));
  879. auto name_alias_file = TRY(open_file(name_alias_path));
  880. auto scripts_file = TRY(open_file(scripts_path));
  881. auto script_extensions_file = TRY(open_file(script_extensions_path));
  882. auto emoji_data_file = TRY(open_file(emoji_data_path));
  883. auto normalization_file = TRY(open_file(normalization_path));
  884. UnicodeData unicode_data {};
  885. parse_special_casing(special_casing_file, unicode_data);
  886. parse_prop_list(derived_general_category_file, unicode_data.general_categories);
  887. parse_prop_list(prop_list_file, unicode_data.prop_list);
  888. parse_prop_list(derived_core_prop_file, unicode_data.prop_list);
  889. parse_prop_list(derived_binary_prop_file, unicode_data.prop_list);
  890. parse_prop_list(emoji_data_file, unicode_data.prop_list);
  891. parse_normalization_props(normalization_file, unicode_data);
  892. parse_alias_list(prop_alias_file, unicode_data.prop_list, unicode_data.prop_aliases);
  893. parse_prop_list(scripts_file, unicode_data.script_list);
  894. parse_prop_list(script_extensions_file, unicode_data.script_extensions, true);
  895. populate_general_category_unions(unicode_data.general_categories);
  896. parse_unicode_data(unicode_data_file, unicode_data);
  897. parse_name_aliases(name_alias_file, unicode_data.code_point_data);
  898. parse_value_alias_list(prop_value_alias_file, "gc"sv, unicode_data.general_categories.keys(), unicode_data.general_category_aliases);
  899. parse_value_alias_list(prop_value_alias_file, "sc"sv, unicode_data.script_list.keys(), unicode_data.script_aliases, false);
  900. normalize_script_extensions(unicode_data.script_extensions, unicode_data.script_list, unicode_data.script_aliases);
  901. generate_unicode_data_header(generated_header_file, unicode_data);
  902. generate_unicode_data_implementation(generated_implementation_file, unicode_data);
  903. return 0;
  904. }