GenerateUnicodeData.cpp 43 KB

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