GenerateUnicodeData.cpp 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  1. /*
  2. * Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "GeneratorUtil.h"
  7. #include <AK/AllOf.h>
  8. #include <AK/Array.h>
  9. #include <AK/CharacterTypes.h>
  10. #include <AK/DeprecatedString.h>
  11. #include <AK/Error.h>
  12. #include <AK/Find.h>
  13. #include <AK/HashMap.h>
  14. #include <AK/Optional.h>
  15. #include <AK/QuickSort.h>
  16. #include <AK/SourceGenerator.h>
  17. #include <AK/StringUtils.h>
  18. #include <AK/Types.h>
  19. #include <AK/Vector.h>
  20. #include <LibCore/ArgsParser.h>
  21. #include <LibUnicode/CharacterTypes.h>
  22. // https://www.unicode.org/reports/tr44/#SpecialCasing.txt
  23. struct SpecialCasing {
  24. u32 index { 0 };
  25. u32 code_point { 0 };
  26. Vector<u32> lowercase_mapping;
  27. Vector<u32> uppercase_mapping;
  28. Vector<u32> titlecase_mapping;
  29. DeprecatedString locale;
  30. DeprecatedString condition;
  31. };
  32. // https://www.unicode.org/reports/tr44/#CaseFolding.txt
  33. struct CaseFolding {
  34. u32 code_point { 0 };
  35. StringView status { "Common"sv };
  36. Vector<u32> mapping { 0 };
  37. };
  38. // https://www.unicode.org/reports/tr44/#Character_Decomposition_Mappings
  39. struct CodePointDecomposition {
  40. // `tag` is a string since it's used for codegen as an enum value.
  41. DeprecatedString tag { "Canonical"sv };
  42. size_t decomposition_index { 0 };
  43. size_t decomposition_size { 0 };
  44. };
  45. // https://www.unicode.org/reports/tr44/#PropList.txt
  46. using PropList = HashMap<DeprecatedString, Vector<Unicode::CodePointRange>>;
  47. // https://www.unicode.org/reports/tr44/#DerivedNormalizationProps.txt
  48. enum class QuickCheck {
  49. Yes,
  50. No,
  51. Maybe,
  52. };
  53. struct Normalization {
  54. Unicode::CodePointRange code_point_range;
  55. Vector<u32> value;
  56. QuickCheck quick_check { QuickCheck::Yes };
  57. };
  58. using NormalizationProps = HashMap<DeprecatedString, Vector<Normalization>>;
  59. struct CodePointName {
  60. Unicode::CodePointRange code_point_range;
  61. size_t name { 0 };
  62. };
  63. // https://www.unicode.org/reports/tr44/#UnicodeData.txt
  64. struct CodePointData {
  65. u32 code_point { 0 };
  66. DeprecatedString name;
  67. Optional<size_t> abbreviation;
  68. u8 canonical_combining_class { 0 };
  69. DeprecatedString bidi_class;
  70. Optional<CodePointDecomposition> decomposition_mapping;
  71. Optional<i8> numeric_value_decimal;
  72. Optional<i8> numeric_value_digit;
  73. Optional<i8> numeric_value_numeric;
  74. bool bidi_mirrored { false };
  75. DeprecatedString unicode_1_name;
  76. DeprecatedString iso_comment;
  77. Optional<u32> simple_uppercase_mapping;
  78. Optional<u32> simple_lowercase_mapping;
  79. Optional<u32> simple_titlecase_mapping;
  80. Vector<u32> special_casing_indices;
  81. Vector<u32> case_folding_indices;
  82. };
  83. struct BlockName {
  84. Unicode::CodePointRange code_point_range;
  85. size_t name { 0 };
  86. };
  87. struct UnicodeData {
  88. UniqueStringStorage unique_strings;
  89. u32 code_points_with_non_zero_combining_class { 0 };
  90. u32 code_points_with_decomposition_mapping { 0 };
  91. Vector<u32> decomposition_mappings;
  92. Vector<DeprecatedString> compatibility_tags;
  93. u32 simple_uppercase_mapping_size { 0 };
  94. u32 simple_lowercase_mapping_size { 0 };
  95. u32 simple_titlecase_mapping_size { 0 };
  96. Vector<SpecialCasing> special_casing;
  97. u32 code_points_with_special_casing { 0 };
  98. u32 largest_special_casing_mapping_size { 0 };
  99. u32 largest_special_casing_size { 0 };
  100. Vector<DeprecatedString> conditions;
  101. Vector<DeprecatedString> locales;
  102. Vector<CaseFolding> case_folding;
  103. u32 code_points_with_case_folding { 0 };
  104. u32 largest_case_folding_mapping_size { 0 };
  105. u32 largest_case_folding_size { 0 };
  106. Vector<StringView> statuses;
  107. Vector<CodePointData> code_point_data;
  108. HashMap<u32, size_t> code_point_abbreviations;
  109. HashMap<u32, size_t> code_point_display_name_aliases;
  110. Vector<CodePointName> code_point_display_names;
  111. // https://www.unicode.org/reports/tr44/#General_Category_Values
  112. PropList general_categories;
  113. Vector<Alias> general_category_aliases;
  114. // The Unicode standard defines additional properties (Any, Assigned, ASCII) which are not in
  115. // any UCD file. Assigned code point ranges are derived as this generator is executed.
  116. // https://unicode.org/reports/tr18/#General_Category_Property
  117. PropList prop_list {
  118. { "Any"sv, { { 0, 0x10ffff } } },
  119. { "Assigned"sv, {} },
  120. { "ASCII"sv, { { 0, 0x7f } } },
  121. };
  122. Vector<Alias> prop_aliases;
  123. PropList script_list {
  124. { "Unknown"sv, {} },
  125. };
  126. Vector<Alias> script_aliases;
  127. PropList script_extensions;
  128. Vector<BlockName> block_display_names;
  129. // FIXME: We are not yet doing anything with this data. It will be needed for String.prototype.normalize.
  130. NormalizationProps normalization_props;
  131. PropList grapheme_break_props;
  132. PropList word_break_props;
  133. PropList sentence_break_props;
  134. };
  135. static DeprecatedString sanitize_entry(DeprecatedString const& entry)
  136. {
  137. auto sanitized = entry.replace("-"sv, "_"sv, ReplaceMode::All);
  138. sanitized = sanitized.replace(" "sv, "_"sv, ReplaceMode::All);
  139. StringBuilder builder;
  140. bool next_is_upper = true;
  141. for (auto ch : sanitized) {
  142. if (next_is_upper)
  143. builder.append_code_point(to_ascii_uppercase(ch));
  144. else
  145. builder.append_code_point(ch);
  146. next_is_upper = ch == '_';
  147. }
  148. return builder.to_deprecated_string();
  149. }
  150. static Vector<u32> parse_code_point_list(StringView list)
  151. {
  152. Vector<u32> code_points;
  153. auto segments = list.split_view(' ');
  154. for (auto const& code_point : segments)
  155. code_points.append(AK::StringUtils::convert_to_uint_from_hex<u32>(code_point).value());
  156. return code_points;
  157. }
  158. static Unicode::CodePointRange parse_code_point_range(StringView list)
  159. {
  160. Unicode::CodePointRange code_point_range {};
  161. if (list.contains(".."sv)) {
  162. auto segments = list.split_view(".."sv);
  163. VERIFY(segments.size() == 2);
  164. auto begin = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[0]).value();
  165. auto end = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[1]).value();
  166. code_point_range = { begin, end };
  167. } else {
  168. auto code_point = AK::StringUtils::convert_to_uint_from_hex<u32>(list).value();
  169. code_point_range = { code_point, code_point };
  170. }
  171. return code_point_range;
  172. }
  173. static ErrorOr<void> parse_special_casing(Core::InputBufferedFile& file, UnicodeData& unicode_data)
  174. {
  175. Array<u8, 1024> buffer;
  176. while (TRY(file.can_read_line())) {
  177. auto line = TRY(file.read_line(buffer));
  178. if (line.is_empty() || line.starts_with('#'))
  179. continue;
  180. if (auto index = line.find('#'); index.has_value())
  181. line = line.substring_view(0, *index);
  182. auto segments = line.split_view(';', SplitBehavior::KeepEmpty);
  183. VERIFY(segments.size() == 5 || segments.size() == 6);
  184. SpecialCasing casing {};
  185. casing.code_point = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[0]).value();
  186. casing.lowercase_mapping = parse_code_point_list(segments[1]);
  187. casing.titlecase_mapping = parse_code_point_list(segments[2]);
  188. casing.uppercase_mapping = parse_code_point_list(segments[3]);
  189. if (auto condition = segments[4].trim_whitespace(); !condition.is_empty()) {
  190. auto conditions = condition.split_view(' ', SplitBehavior::KeepEmpty);
  191. VERIFY(conditions.size() == 1 || conditions.size() == 2);
  192. if (conditions.size() == 2) {
  193. casing.locale = conditions[0];
  194. casing.condition = conditions[1];
  195. } else if (all_of(conditions[0], is_ascii_lower_alpha)) {
  196. casing.locale = conditions[0];
  197. } else {
  198. casing.condition = conditions[0];
  199. }
  200. if (!casing.locale.is_empty()) {
  201. casing.locale = DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(casing.locale[0]), casing.locale.substring_view(1));
  202. if (!unicode_data.locales.contains_slow(casing.locale))
  203. unicode_data.locales.append(casing.locale);
  204. }
  205. casing.condition = casing.condition.replace("_"sv, ""sv, ReplaceMode::All);
  206. if (!casing.condition.is_empty() && !unicode_data.conditions.contains_slow(casing.condition))
  207. unicode_data.conditions.append(casing.condition);
  208. }
  209. unicode_data.largest_special_casing_mapping_size = max(unicode_data.largest_special_casing_mapping_size, casing.lowercase_mapping.size());
  210. unicode_data.largest_special_casing_mapping_size = max(unicode_data.largest_special_casing_mapping_size, casing.titlecase_mapping.size());
  211. unicode_data.largest_special_casing_mapping_size = max(unicode_data.largest_special_casing_mapping_size, casing.uppercase_mapping.size());
  212. unicode_data.special_casing.append(move(casing));
  213. }
  214. quick_sort(unicode_data.special_casing, [](auto const& lhs, auto const& rhs) {
  215. if (lhs.code_point != rhs.code_point)
  216. return lhs.code_point < rhs.code_point;
  217. if (lhs.locale.is_empty() && !rhs.locale.is_empty())
  218. return false;
  219. if (!lhs.locale.is_empty() && rhs.locale.is_empty())
  220. return true;
  221. return lhs.locale < rhs.locale;
  222. });
  223. for (u32 i = 0; i < unicode_data.special_casing.size(); ++i)
  224. unicode_data.special_casing[i].index = i;
  225. return {};
  226. }
  227. static ErrorOr<void> parse_case_folding(Core::InputBufferedFile& file, UnicodeData& unicode_data)
  228. {
  229. Array<u8, 1024> buffer;
  230. while (TRY(file.can_read_line())) {
  231. auto line = TRY(file.read_line(buffer));
  232. if (line.is_empty() || line.starts_with('#'))
  233. continue;
  234. auto segments = line.split_view(';', SplitBehavior::KeepEmpty);
  235. VERIFY(segments.size() == 4);
  236. CaseFolding folding {};
  237. folding.code_point = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[0]).value();
  238. folding.mapping = parse_code_point_list(segments[2]);
  239. switch (segments[1].trim_whitespace()[0]) {
  240. case 'C':
  241. folding.status = "Common"sv;
  242. break;
  243. case 'F':
  244. folding.status = "Full"sv;
  245. break;
  246. case 'S':
  247. folding.status = "Simple"sv;
  248. break;
  249. case 'T':
  250. folding.status = "Special"sv;
  251. break;
  252. }
  253. unicode_data.largest_case_folding_mapping_size = max(unicode_data.largest_case_folding_mapping_size, folding.mapping.size());
  254. if (!unicode_data.statuses.contains_slow(folding.status))
  255. unicode_data.statuses.append(folding.status);
  256. unicode_data.case_folding.append(move(folding));
  257. }
  258. quick_sort(unicode_data.case_folding, [](auto const& lhs, auto const& rhs) {
  259. if (lhs.code_point != rhs.code_point)
  260. return lhs.code_point < rhs.code_point;
  261. return lhs.status < rhs.status;
  262. });
  263. return {};
  264. }
  265. static ErrorOr<void> parse_prop_list(Core::InputBufferedFile& file, PropList& prop_list, bool multi_value_property = false, bool sanitize_property = false)
  266. {
  267. Array<u8, 1024> buffer;
  268. while (TRY(file.can_read_line())) {
  269. auto line = TRY(file.read_line(buffer));
  270. if (line.is_empty() || line.starts_with('#'))
  271. continue;
  272. if (auto index = line.find('#'); index.has_value())
  273. line = line.substring_view(0, *index);
  274. auto segments = line.split_view(';', SplitBehavior::KeepEmpty);
  275. VERIFY(segments.size() == 2);
  276. auto code_point_range = parse_code_point_range(segments[0].trim_whitespace());
  277. Vector<StringView> properties;
  278. if (multi_value_property)
  279. properties = segments[1].trim_whitespace().split_view(' ');
  280. else
  281. properties = { segments[1].trim_whitespace() };
  282. for (auto& property : properties) {
  283. auto& code_points = prop_list.ensure(sanitize_property ? sanitize_entry(property).trim_whitespace().view() : property.trim_whitespace());
  284. code_points.append(code_point_range);
  285. }
  286. }
  287. return {};
  288. }
  289. static ErrorOr<void> parse_alias_list(Core::InputBufferedFile& file, PropList const& prop_list, Vector<Alias>& prop_aliases)
  290. {
  291. DeprecatedString current_property;
  292. Array<u8, 1024> buffer;
  293. auto append_alias = [&](auto alias, auto property) {
  294. // Note: The alias files contain lines such as "Hyphen = Hyphen", which we should just skip.
  295. if (alias == property)
  296. return;
  297. // FIXME: We will, eventually, need to find where missing properties are located and parse them.
  298. if (!prop_list.contains(property))
  299. return;
  300. prop_aliases.append({ property, alias });
  301. };
  302. while (TRY(file.can_read_line())) {
  303. auto line = TRY(file.read_line(buffer));
  304. if (line.is_empty() || line.starts_with('#')) {
  305. if (line.ends_with("Properties"sv))
  306. current_property = line.substring_view(2);
  307. continue;
  308. }
  309. // Note: For now, we only care about Binary Property aliases for Unicode property escapes.
  310. if (current_property != "Binary Properties"sv)
  311. continue;
  312. auto segments = line.split_view(';', SplitBehavior::KeepEmpty);
  313. VERIFY((segments.size() == 2) || (segments.size() == 3));
  314. auto alias = segments[0].trim_whitespace();
  315. auto property = segments[1].trim_whitespace();
  316. append_alias(alias, property);
  317. if (segments.size() == 3) {
  318. alias = segments[2].trim_whitespace();
  319. append_alias(alias, property);
  320. }
  321. }
  322. return {};
  323. }
  324. static ErrorOr<void> parse_name_aliases(Core::InputBufferedFile& file, UnicodeData& unicode_data)
  325. {
  326. Array<u8, 1024> buffer;
  327. while (TRY(file.can_read_line())) {
  328. auto line = TRY(file.read_line(buffer));
  329. if (line.is_empty() || line.starts_with('#'))
  330. continue;
  331. auto segments = line.split_view(';', SplitBehavior::KeepEmpty);
  332. VERIFY(segments.size() == 3);
  333. auto code_point = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[0].trim_whitespace());
  334. auto alias = segments[1].trim_whitespace();
  335. auto reason = segments[2].trim_whitespace();
  336. if (reason == "abbreviation"sv) {
  337. auto index = unicode_data.unique_strings.ensure(alias);
  338. unicode_data.code_point_abbreviations.set(*code_point, index);
  339. } else if (reason.is_one_of("correction"sv, "control"sv)) {
  340. if (!unicode_data.code_point_display_name_aliases.contains(*code_point)) {
  341. auto index = unicode_data.unique_strings.ensure(alias);
  342. unicode_data.code_point_display_name_aliases.set(*code_point, index);
  343. }
  344. }
  345. }
  346. return {};
  347. }
  348. static ErrorOr<void> parse_value_alias_list(Core::InputBufferedFile& file, StringView desired_category, Vector<DeprecatedString> const& value_list, Vector<Alias>& prop_aliases, bool primary_value_is_first = true, bool sanitize_alias = false)
  349. {
  350. TRY(file.seek(0, SeekMode::SetPosition));
  351. Array<u8, 1024> buffer;
  352. auto append_alias = [&](auto alias, auto value) {
  353. // Note: The value alias file contains lines such as "Ahom = Ahom", which we should just skip.
  354. if (alias == value)
  355. return;
  356. // FIXME: We will, eventually, need to find where missing properties are located and parse them.
  357. if (!value_list.contains_slow(value))
  358. return;
  359. prop_aliases.append({ value, alias });
  360. };
  361. while (TRY(file.can_read_line())) {
  362. auto line = TRY(file.read_line(buffer));
  363. if (line.is_empty() || line.starts_with('#'))
  364. continue;
  365. if (auto index = line.find('#'); index.has_value())
  366. line = line.substring_view(0, *index);
  367. auto segments = line.split_view(';', SplitBehavior::KeepEmpty);
  368. auto category = segments[0].trim_whitespace();
  369. if (category != desired_category)
  370. continue;
  371. VERIFY((segments.size() == 3) || (segments.size() == 4));
  372. auto value = primary_value_is_first ? segments[1].trim_whitespace() : segments[2].trim_whitespace();
  373. auto alias = primary_value_is_first ? segments[2].trim_whitespace() : segments[1].trim_whitespace();
  374. append_alias(sanitize_alias ? sanitize_entry(alias).view() : alias, value);
  375. if (segments.size() == 4) {
  376. alias = segments[3].trim_whitespace();
  377. append_alias(sanitize_alias ? sanitize_entry(alias).view() : alias, value);
  378. }
  379. }
  380. return {};
  381. }
  382. static ErrorOr<void> parse_normalization_props(Core::InputBufferedFile& file, UnicodeData& unicode_data)
  383. {
  384. Array<u8, 1024> buffer;
  385. while (TRY(file.can_read_line())) {
  386. auto line = TRY(file.read_line(buffer));
  387. if (line.is_empty() || line.starts_with('#'))
  388. continue;
  389. if (auto index = line.find('#'); index.has_value())
  390. line = line.substring_view(0, *index);
  391. auto segments = line.split_view(';', SplitBehavior::KeepEmpty);
  392. VERIFY((segments.size() == 2) || (segments.size() == 3));
  393. auto code_point_range = parse_code_point_range(segments[0].trim_whitespace());
  394. auto property = segments[1].trim_whitespace().to_deprecated_string();
  395. Vector<u32> value;
  396. QuickCheck quick_check = QuickCheck::Yes;
  397. if (segments.size() == 3) {
  398. auto value_or_quick_check = segments[2].trim_whitespace();
  399. if ((value_or_quick_check == "N"sv))
  400. quick_check = QuickCheck::No;
  401. else if ((value_or_quick_check == "M"sv))
  402. quick_check = QuickCheck::Maybe;
  403. else
  404. value = parse_code_point_list(value_or_quick_check);
  405. }
  406. auto& normalizations = unicode_data.normalization_props.ensure(property);
  407. normalizations.append({ code_point_range, move(value), quick_check });
  408. auto& prop_list = unicode_data.prop_list.ensure(property);
  409. prop_list.append(move(code_point_range));
  410. }
  411. return {};
  412. }
  413. static void add_canonical_code_point_name(Unicode::CodePointRange range, StringView name, UnicodeData& unicode_data)
  414. {
  415. // https://www.unicode.org/versions/Unicode15.0.0/ch04.pdf#G142981
  416. // FIXME: Implement the NR1 rules for Hangul syllables.
  417. struct CodePointNameFormat {
  418. Unicode::CodePointRange code_point_range;
  419. StringView name;
  420. };
  421. // These code point ranges are the NR2 set of name replacements defined by Table 4-8.
  422. constexpr Array<CodePointNameFormat, 16> s_ideographic_replacements { {
  423. { { 0x3400, 0x4DBF }, "CJK UNIFIED IDEOGRAPH-{:X}"sv },
  424. { { 0x4E00, 0x9FFF }, "CJK UNIFIED IDEOGRAPH-{:X}"sv },
  425. { { 0xF900, 0xFA6D }, "CJK COMPATIBILITY IDEOGRAPH-{:X}"sv },
  426. { { 0xFA70, 0xFAD9 }, "CJK COMPATIBILITY IDEOGRAPH-{:X}"sv },
  427. { { 0x17000, 0x187F7 }, "TANGUT IDEOGRAPH-{:X}"sv },
  428. { { 0x18B00, 0x18CD5 }, "KHITAN SMALL SCRIPT CHARACTER-{:X}"sv },
  429. { { 0x18D00, 0x18D08 }, "TANGUT IDEOGRAPH-{:X}"sv },
  430. { { 0x1B170, 0x1B2FB }, "NUSHU CHARACTER-{:X}"sv },
  431. { { 0x20000, 0x2A6DF }, "CJK UNIFIED IDEOGRAPH-{:X}"sv },
  432. { { 0x2A700, 0x2B739 }, "CJK UNIFIED IDEOGRAPH-{:X}"sv },
  433. { { 0x2B740, 0x2B81D }, "CJK UNIFIED IDEOGRAPH-{:X}"sv },
  434. { { 0x2B820, 0x2CEA1 }, "CJK UNIFIED IDEOGRAPH-{:X}"sv },
  435. { { 0x2CEB0, 0x2EBE0 }, "CJK UNIFIED IDEOGRAPH-{:X}"sv },
  436. { { 0x2F800, 0x2FA1D }, "CJK COMPATIBILITY IDEOGRAPH-{:X}"sv },
  437. { { 0x30000, 0x3134A }, "CJK UNIFIED IDEOGRAPH-{:X}"sv },
  438. { { 0x31350, 0x323AF }, "CJK UNIFIED IDEOGRAPH-{:X}"sv },
  439. } };
  440. auto it = find_if(s_ideographic_replacements.begin(), s_ideographic_replacements.end(),
  441. [&](auto const& replacement) {
  442. return replacement.code_point_range.first == range.first;
  443. });
  444. if (it != s_ideographic_replacements.end()) {
  445. auto index = unicode_data.unique_strings.ensure(it->name);
  446. unicode_data.code_point_display_names.append({ it->code_point_range, index });
  447. return;
  448. }
  449. it = find_if(s_ideographic_replacements.begin(), s_ideographic_replacements.end(),
  450. [&](auto const& replacement) {
  451. return (replacement.code_point_range.first <= range.first) && (range.first <= replacement.code_point_range.last);
  452. });
  453. if (it != s_ideographic_replacements.end()) {
  454. // Drop code points that will have been captured by a range defined by the ideographic replacements.
  455. return;
  456. }
  457. if (auto alias = unicode_data.code_point_display_name_aliases.get(range.first); alias.has_value()) {
  458. // NR4 states that control code points have a null string as their name. Our implementation
  459. // uses the control code's alias as its display name.
  460. unicode_data.code_point_display_names.append({ range, *alias });
  461. return;
  462. }
  463. auto index = unicode_data.unique_strings.ensure(name);
  464. unicode_data.code_point_display_names.append({ range, index });
  465. }
  466. static Optional<CodePointDecomposition> parse_decomposition_mapping(StringView string, UnicodeData& unicode_data)
  467. {
  468. if (string.is_empty())
  469. return {};
  470. CodePointDecomposition mapping;
  471. auto parts = string.split_view(' ');
  472. VERIFY(parts.size() > 0);
  473. if (parts.first().starts_with('<')) {
  474. auto const tag = parts.take_first().trim("<>"sv);
  475. mapping.tag = DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(tag[0]), tag.substring_view(1));
  476. if (!unicode_data.compatibility_tags.contains_slow(mapping.tag))
  477. unicode_data.compatibility_tags.append(mapping.tag);
  478. }
  479. mapping.decomposition_index = unicode_data.decomposition_mappings.size();
  480. mapping.decomposition_size = parts.size();
  481. for (auto part : parts) {
  482. unicode_data.decomposition_mappings.append(AK::StringUtils::convert_to_uint_from_hex<u32>(part).value());
  483. }
  484. return mapping;
  485. }
  486. static ErrorOr<void> parse_block_display_names(Core::InputBufferedFile& file, UnicodeData& unicode_data)
  487. {
  488. Array<u8, 1024> buffer;
  489. while (TRY(file.can_read_line())) {
  490. auto line = TRY(file.read_line(buffer));
  491. if (line.is_empty() || line.starts_with('#'))
  492. continue;
  493. auto segments = line.split_view(';', SplitBehavior::KeepEmpty);
  494. VERIFY(segments.size() == 2);
  495. auto code_point_range = parse_code_point_range(segments[0].trim_whitespace());
  496. auto display_name = segments[1].trim_whitespace();
  497. auto index = unicode_data.unique_strings.ensure(display_name);
  498. unicode_data.block_display_names.append({ code_point_range, index });
  499. }
  500. TRY(file.seek(0, SeekMode::SetPosition));
  501. return {};
  502. }
  503. static ErrorOr<void> parse_unicode_data(Core::InputBufferedFile& file, UnicodeData& unicode_data)
  504. {
  505. Optional<u32> code_point_range_start;
  506. auto& assigned_code_points = unicode_data.prop_list.find("Assigned"sv)->value;
  507. Optional<u32> assigned_code_point_range_start = 0;
  508. u32 previous_code_point = 0;
  509. Array<u8, 1024> buffer;
  510. while (TRY(file.can_read_line())) {
  511. auto line = TRY(file.read_line(buffer));
  512. if (line.is_empty())
  513. continue;
  514. auto segments = line.split_view(';', SplitBehavior::KeepEmpty);
  515. VERIFY(segments.size() == 15);
  516. CodePointData data {};
  517. data.code_point = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[0]).value();
  518. data.name = segments[1];
  519. data.canonical_combining_class = AK::StringUtils::convert_to_uint<u8>(segments[3]).value();
  520. data.bidi_class = segments[4];
  521. data.decomposition_mapping = parse_decomposition_mapping(segments[5], unicode_data);
  522. data.numeric_value_decimal = AK::StringUtils::convert_to_int<i8>(segments[6]);
  523. data.numeric_value_digit = AK::StringUtils::convert_to_int<i8>(segments[7]);
  524. data.numeric_value_numeric = AK::StringUtils::convert_to_int<i8>(segments[8]);
  525. data.bidi_mirrored = segments[9] == "Y"sv;
  526. data.unicode_1_name = segments[10];
  527. data.iso_comment = segments[11];
  528. data.simple_uppercase_mapping = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[12]);
  529. data.simple_lowercase_mapping = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[13]);
  530. data.simple_titlecase_mapping = AK::StringUtils::convert_to_uint_from_hex<u32>(segments[14]);
  531. if (auto abbreviation = unicode_data.code_point_abbreviations.get(data.code_point); abbreviation.has_value())
  532. data.abbreviation = *abbreviation;
  533. if (!assigned_code_point_range_start.has_value())
  534. assigned_code_point_range_start = data.code_point;
  535. if (data.name.starts_with("<"sv) && data.name.ends_with(", First>"sv)) {
  536. VERIFY(!code_point_range_start.has_value() && assigned_code_point_range_start.has_value());
  537. code_point_range_start = data.code_point;
  538. data.name = data.name.substring(1, data.name.length() - 9);
  539. assigned_code_points.append({ *assigned_code_point_range_start, previous_code_point });
  540. assigned_code_point_range_start.clear();
  541. } else if (data.name.starts_with("<"sv) && data.name.ends_with(", Last>"sv)) {
  542. VERIFY(code_point_range_start.has_value());
  543. Unicode::CodePointRange code_point_range { *code_point_range_start, data.code_point };
  544. assigned_code_points.append(code_point_range);
  545. data.name = data.name.substring(1, data.name.length() - 8);
  546. code_point_range_start.clear();
  547. add_canonical_code_point_name(code_point_range, data.name, unicode_data);
  548. } else {
  549. add_canonical_code_point_name({ data.code_point, data.code_point }, data.name, unicode_data);
  550. if ((data.code_point > 0) && (data.code_point - previous_code_point) != 1) {
  551. VERIFY(assigned_code_point_range_start.has_value());
  552. assigned_code_points.append({ *assigned_code_point_range_start, previous_code_point });
  553. assigned_code_point_range_start = data.code_point;
  554. }
  555. }
  556. bool has_special_casing { false };
  557. for (auto const& casing : unicode_data.special_casing) {
  558. if (casing.code_point == data.code_point) {
  559. data.special_casing_indices.append(casing.index);
  560. has_special_casing = true;
  561. }
  562. }
  563. bool has_case_folding { false };
  564. for (size_t i = 0; i < unicode_data.case_folding.size(); ++i) {
  565. if (auto const& folding = unicode_data.case_folding[i]; folding.code_point == data.code_point) {
  566. data.case_folding_indices.append(i);
  567. has_case_folding = true;
  568. }
  569. }
  570. unicode_data.code_points_with_non_zero_combining_class += data.canonical_combining_class != 0;
  571. unicode_data.simple_uppercase_mapping_size += data.simple_uppercase_mapping.has_value();
  572. unicode_data.simple_lowercase_mapping_size += data.simple_lowercase_mapping.has_value();
  573. unicode_data.simple_titlecase_mapping_size += data.simple_titlecase_mapping.has_value();
  574. unicode_data.code_points_with_decomposition_mapping += data.decomposition_mapping.has_value();
  575. unicode_data.code_points_with_special_casing += has_special_casing;
  576. unicode_data.largest_special_casing_size = max(unicode_data.largest_special_casing_size, data.special_casing_indices.size());
  577. unicode_data.code_points_with_case_folding += has_case_folding;
  578. unicode_data.largest_case_folding_size = max(unicode_data.largest_case_folding_size, data.case_folding_indices.size());
  579. previous_code_point = data.code_point;
  580. unicode_data.code_point_data.append(move(data));
  581. }
  582. return {};
  583. }
  584. static ErrorOr<void> generate_unicode_data_header(Core::InputBufferedFile& file, UnicodeData& unicode_data)
  585. {
  586. StringBuilder builder;
  587. SourceGenerator generator { builder };
  588. generator.set("special_casing_mapping_size", DeprecatedString::number(unicode_data.largest_special_casing_mapping_size));
  589. generator.set("case_folding_mapping_size", DeprecatedString::number(unicode_data.largest_case_folding_mapping_size));
  590. auto generate_enum = [&](StringView name, StringView default_, auto values, Vector<Alias> aliases = {}) {
  591. quick_sort(values);
  592. quick_sort(aliases, [](auto& alias1, auto& alias2) { return alias1.alias < alias2.alias; });
  593. generator.set("name", name);
  594. generator.set("underlying", DeprecatedString::formatted("{}UnderlyingType", name));
  595. generator.set("type", ((values.size() + !default_.is_empty()) < 256) ? "u8"sv : "u16"sv);
  596. generator.append(R"~~~(
  597. using @underlying@ = @type@;
  598. enum class @name@ : @underlying@ {)~~~");
  599. if (!default_.is_empty()) {
  600. generator.set("default", default_);
  601. generator.append(R"~~~(
  602. @default@,)~~~");
  603. }
  604. for (auto const& value : values) {
  605. generator.set("value", value);
  606. generator.append(R"~~~(
  607. @value@,)~~~");
  608. }
  609. for (auto const& alias : aliases) {
  610. generator.set("alias", alias.alias);
  611. generator.set("value", alias.name);
  612. generator.append(R"~~~(
  613. @alias@ = @value@,)~~~");
  614. }
  615. generator.append(R"~~~(
  616. };
  617. )~~~");
  618. };
  619. generator.append(R"~~~(
  620. #pragma once
  621. #include <AK/Types.h>
  622. #include <LibUnicode/Forward.h>
  623. namespace Unicode {
  624. )~~~");
  625. generate_enum("Locale"sv, "None"sv, unicode_data.locales);
  626. generate_enum("Condition"sv, "None"sv, move(unicode_data.conditions));
  627. generate_enum("CaseFoldingStatus"sv, {}, move(unicode_data.statuses));
  628. generate_enum("GeneralCategory"sv, {}, unicode_data.general_categories.keys(), unicode_data.general_category_aliases);
  629. generate_enum("Property"sv, {}, unicode_data.prop_list.keys(), unicode_data.prop_aliases);
  630. generate_enum("Script"sv, {}, unicode_data.script_list.keys(), unicode_data.script_aliases);
  631. generate_enum("GraphemeBreakProperty"sv, {}, unicode_data.grapheme_break_props.keys());
  632. generate_enum("WordBreakProperty"sv, {}, unicode_data.word_break_props.keys());
  633. generate_enum("SentenceBreakProperty"sv, {}, unicode_data.sentence_break_props.keys());
  634. generate_enum("CompatibilityFormattingTag"sv, "Canonical"sv, unicode_data.compatibility_tags);
  635. generator.append(R"~~~(
  636. struct SpecialCasing {
  637. u32 code_point { 0 };
  638. u32 lowercase_mapping[@special_casing_mapping_size@];
  639. u32 lowercase_mapping_size { 0 };
  640. u32 uppercase_mapping[@special_casing_mapping_size@];
  641. u32 uppercase_mapping_size { 0 };
  642. u32 titlecase_mapping[@special_casing_mapping_size@];
  643. u32 titlecase_mapping_size { 0 };
  644. Locale locale { Locale::None };
  645. Condition condition { Condition::None };
  646. };
  647. struct CaseFolding {
  648. u32 code_point { 0 };
  649. CaseFoldingStatus status { CaseFoldingStatus::Common };
  650. u32 mapping[@case_folding_mapping_size@];
  651. u32 mapping_size { 0 };
  652. };
  653. struct CodePointDecompositionRaw {
  654. u32 code_point { 0 };
  655. CompatibilityFormattingTag tag { CompatibilityFormattingTag::Canonical };
  656. size_t decomposition_index { 0 };
  657. size_t decomposition_count { 0 };
  658. };
  659. struct CodePointDecomposition {
  660. u32 code_point { 0 };
  661. CompatibilityFormattingTag tag { CompatibilityFormattingTag::Canonical };
  662. ReadonlySpan<u32> decomposition;
  663. };
  664. Optional<Locale> locale_from_string(StringView locale);
  665. ReadonlySpan<SpecialCasing const*> special_case_mapping(u32 code_point);
  666. ReadonlySpan<CaseFolding const*> case_folding_mapping(u32 code_point);
  667. }
  668. )~~~");
  669. TRY(file.write_until_depleted(generator.as_string_view().bytes()));
  670. return {};
  671. }
  672. static ErrorOr<void> generate_unicode_data_implementation(Core::InputBufferedFile& file, UnicodeData const& unicode_data)
  673. {
  674. StringBuilder builder;
  675. SourceGenerator generator { builder };
  676. generator.set("string_index_type"sv, unicode_data.unique_strings.type_that_fits());
  677. generator.set("largest_special_casing_size", DeprecatedString::number(unicode_data.largest_special_casing_size));
  678. generator.set("special_casing_size", DeprecatedString::number(unicode_data.special_casing.size()));
  679. generator.set("largest_case_folding_size", DeprecatedString::number(unicode_data.largest_case_folding_size));
  680. generator.set("case_folding_size", DeprecatedString::number(unicode_data.case_folding.size()));
  681. generator.append(R"~~~(
  682. #include <AK/Array.h>
  683. #include <AK/BinarySearch.h>
  684. #include <AK/CharacterTypes.h>
  685. #include <AK/Optional.h>
  686. #include <AK/Span.h>
  687. #include <AK/DeprecatedString.h>
  688. #include <AK/StringView.h>
  689. #include <LibUnicode/CharacterTypes.h>
  690. #include <LibUnicode/UnicodeData.h>
  691. #include <LibUnicode/Normalize.h>
  692. namespace Unicode {
  693. )~~~");
  694. unicode_data.unique_strings.generate(generator);
  695. auto append_list_and_size = [&](auto const& list, StringView format) {
  696. if (list.is_empty()) {
  697. generator.append(", {}, 0");
  698. return;
  699. }
  700. bool first = true;
  701. generator.append(", {");
  702. for (auto const& item : list) {
  703. generator.append(first ? " "sv : ", "sv);
  704. generator.append(DeprecatedString::formatted(format, item));
  705. first = false;
  706. }
  707. generator.append(DeprecatedString::formatted(" }}, {}", list.size()));
  708. };
  709. generator.append(R"~~~(
  710. static constexpr Array<SpecialCasing, @special_casing_size@> s_special_case { {)~~~");
  711. for (auto const& casing : unicode_data.special_casing) {
  712. generator.set("code_point", DeprecatedString::formatted("{:#x}", casing.code_point));
  713. generator.append(R"~~~(
  714. { @code_point@)~~~");
  715. constexpr auto format = "0x{:x}"sv;
  716. append_list_and_size(casing.lowercase_mapping, format);
  717. append_list_and_size(casing.uppercase_mapping, format);
  718. append_list_and_size(casing.titlecase_mapping, format);
  719. generator.set("locale", casing.locale.is_empty() ? "None" : casing.locale);
  720. generator.append(", Locale::@locale@");
  721. generator.set("condition", casing.condition.is_empty() ? "None" : casing.condition);
  722. generator.append(", Condition::@condition@");
  723. generator.append(" },");
  724. }
  725. generator.append(R"~~~(
  726. } };
  727. static constexpr Array<CaseFolding, @case_folding_size@> s_case_folding { {)~~~");
  728. for (auto const& folding : unicode_data.case_folding) {
  729. generator.set("code_point", DeprecatedString::formatted("{:#x}", folding.code_point));
  730. generator.set("status", folding.status);
  731. generator.append(R"~~~(
  732. { @code_point@, CaseFoldingStatus::@status@)~~~");
  733. append_list_and_size(folding.mapping, "0x{:x}"sv);
  734. generator.append(" },");
  735. }
  736. generator.append(R"~~~(
  737. } };
  738. struct CodePointMapping {
  739. u32 code_point { 0 };
  740. u32 mapping { 0 };
  741. };
  742. struct SpecialCaseMapping {
  743. u32 code_point { 0 };
  744. Array<SpecialCasing const*, @largest_special_casing_size@> special_casing {};
  745. u32 special_casing_size { 0 };
  746. };
  747. struct CaseFoldingMapping {
  748. u32 code_point { 0 };
  749. Array<CaseFolding const*, @largest_case_folding_size@> case_folding {};
  750. u32 case_folding_size { 0 };
  751. };
  752. struct CodePointAbbreviation {
  753. u32 code_point { 0 };
  754. @string_index_type@ abbreviation { 0 };
  755. };
  756. template<typename MappingType>
  757. struct CodePointComparator {
  758. constexpr int operator()(u32 code_point, MappingType const& mapping)
  759. {
  760. return code_point - mapping.code_point;
  761. }
  762. };
  763. struct BlockNameData {
  764. CodePointRange code_point_range {};
  765. @string_index_type@ display_name { 0 };
  766. };
  767. struct BlockNameComparator : public CodePointRangeComparator {
  768. constexpr int operator()(u32 code_point, BlockNameData const& name)
  769. {
  770. return CodePointRangeComparator::operator()(code_point, name.code_point_range);
  771. }
  772. };
  773. struct CodePointName {
  774. CodePointRange code_point_range {};
  775. @string_index_type@ display_name { 0 };
  776. };
  777. struct CodePointNameComparator : public CodePointRangeComparator {
  778. constexpr int operator()(u32 code_point, CodePointName const& name)
  779. {
  780. return CodePointRangeComparator::operator()(code_point, name.code_point_range);
  781. }
  782. };
  783. )~~~");
  784. generator.set("decomposition_mappings_size", DeprecatedString::number(unicode_data.decomposition_mappings.size()));
  785. generator.append("\nstatic constexpr Array<u32, @decomposition_mappings_size@> s_decomposition_mappings_data { ");
  786. generator.append(DeprecatedString::join(", "sv, unicode_data.decomposition_mappings, "{:#x}"sv));
  787. generator.append(" };\n");
  788. auto append_code_point_mappings = [&](StringView name, StringView mapping_type, u32 size, auto mapping_getter) {
  789. generator.set("name", name);
  790. generator.set("mapping_type", mapping_type);
  791. generator.set("size", DeprecatedString::number(size));
  792. generator.append(R"~~~(
  793. static constexpr Array<@mapping_type@, @size@> s_@name@_mappings { {
  794. )~~~");
  795. constexpr size_t max_mappings_per_row = 20;
  796. size_t mappings_in_current_row = 0;
  797. for (auto const& data : unicode_data.code_point_data) {
  798. auto mapping = mapping_getter(data);
  799. if constexpr (requires { mapping.has_value(); }) {
  800. if (!mapping.has_value())
  801. continue;
  802. } else {
  803. if (mapping.is_empty())
  804. continue;
  805. }
  806. if (mappings_in_current_row++ > 0)
  807. generator.append(" ");
  808. generator.set("code_point", DeprecatedString::formatted("{:#x}", data.code_point));
  809. generator.append("{ @code_point@");
  810. if constexpr (IsSame<decltype(mapping), Optional<u32>> || IsSame<decltype(mapping), Optional<size_t>>) {
  811. generator.set("mapping", DeprecatedString::formatted("{:#x}", *mapping));
  812. generator.append(", @mapping@ },");
  813. } else if constexpr (IsSame<decltype(mapping), Optional<CodePointDecomposition>>) {
  814. generator.set("tag", mapping->tag);
  815. generator.set("start", DeprecatedString::number(mapping->decomposition_index));
  816. generator.set("size", DeprecatedString::number(mapping->decomposition_size));
  817. generator.append(", CompatibilityFormattingTag::@tag@, @start@, @size@ },");
  818. } else {
  819. append_list_and_size(mapping, "&s_@name@[{}]"sv);
  820. generator.append(" },");
  821. }
  822. if (mappings_in_current_row == max_mappings_per_row) {
  823. mappings_in_current_row = 0;
  824. generator.append("\n ");
  825. }
  826. }
  827. generator.append(R"~~~(
  828. } };
  829. )~~~");
  830. };
  831. append_code_point_mappings("combining_class"sv, "CodePointMapping"sv, unicode_data.code_points_with_non_zero_combining_class,
  832. [](auto const& data) -> Optional<u32> {
  833. if (data.canonical_combining_class == 0)
  834. return {};
  835. return data.canonical_combining_class;
  836. });
  837. append_code_point_mappings("uppercase"sv, "CodePointMapping"sv, unicode_data.simple_uppercase_mapping_size, [](auto const& data) { return data.simple_uppercase_mapping; });
  838. append_code_point_mappings("lowercase"sv, "CodePointMapping"sv, unicode_data.simple_lowercase_mapping_size, [](auto const& data) { return data.simple_lowercase_mapping; });
  839. append_code_point_mappings("titlecase"sv, "CodePointMapping"sv, unicode_data.simple_titlecase_mapping_size, [](auto const& data) { return data.simple_titlecase_mapping; });
  840. append_code_point_mappings("special_case"sv, "SpecialCaseMapping"sv, unicode_data.code_points_with_special_casing, [](auto const& data) { return data.special_casing_indices; });
  841. append_code_point_mappings("case_folding"sv, "CaseFoldingMapping"sv, unicode_data.code_points_with_case_folding, [](auto const& data) { return data.case_folding_indices; });
  842. append_code_point_mappings("abbreviation"sv, "CodePointAbbreviation"sv, unicode_data.code_point_abbreviations.size(), [](auto const& data) { return data.abbreviation; });
  843. append_code_point_mappings("decomposition"sv, "CodePointDecompositionRaw"sv, unicode_data.code_points_with_decomposition_mapping,
  844. [](auto const& data) {
  845. return data.decomposition_mapping;
  846. });
  847. auto append_code_point_range_list = [&](DeprecatedString name, Vector<Unicode::CodePointRange> const& ranges) {
  848. generator.set("name", name);
  849. generator.set("size", DeprecatedString::number(ranges.size()));
  850. generator.append(R"~~~(
  851. static constexpr Array<CodePointRange, @size@> @name@ { {
  852. )~~~");
  853. constexpr size_t max_ranges_per_row = 20;
  854. size_t ranges_in_current_row = 0;
  855. for (auto const& range : ranges) {
  856. if (ranges_in_current_row++ > 0)
  857. generator.append(" ");
  858. generator.set("first", DeprecatedString::formatted("{:#x}", range.first));
  859. generator.set("last", DeprecatedString::formatted("{:#x}", range.last));
  860. generator.append("{ @first@, @last@ },");
  861. if (ranges_in_current_row == max_ranges_per_row) {
  862. ranges_in_current_row = 0;
  863. generator.append("\n ");
  864. }
  865. }
  866. generator.append(R"~~~(
  867. } };
  868. )~~~");
  869. };
  870. auto append_prop_list = [&](StringView collection_name, StringView property_format, PropList const& property_list) {
  871. for (auto const& property : property_list) {
  872. auto name = DeprecatedString::formatted(property_format, property.key);
  873. append_code_point_range_list(move(name), property.value);
  874. }
  875. auto property_names = property_list.keys();
  876. quick_sort(property_names);
  877. generator.set("name", collection_name);
  878. generator.set("size", DeprecatedString::number(property_names.size()));
  879. generator.append(R"~~~(
  880. static constexpr Array<ReadonlySpan<CodePointRange>, @size@> @name@ { {)~~~");
  881. for (auto const& property_name : property_names) {
  882. generator.set("name", DeprecatedString::formatted(property_format, property_name));
  883. generator.append(R"~~~(
  884. @name@.span(),)~~~");
  885. }
  886. generator.append(R"~~~(
  887. } };
  888. )~~~");
  889. };
  890. append_prop_list("s_general_categories"sv, "s_general_category_{}"sv, unicode_data.general_categories);
  891. append_prop_list("s_properties"sv, "s_property_{}"sv, unicode_data.prop_list);
  892. append_prop_list("s_scripts"sv, "s_script_{}"sv, unicode_data.script_list);
  893. append_prop_list("s_script_extensions"sv, "s_script_extension_{}"sv, unicode_data.script_extensions);
  894. append_prop_list("s_grapheme_break_properties"sv, "s_grapheme_break_property_{}"sv, unicode_data.grapheme_break_props);
  895. append_prop_list("s_word_break_properties"sv, "s_word_break_property_{}"sv, unicode_data.word_break_props);
  896. append_prop_list("s_sentence_break_properties"sv, "s_sentence_break_property_{}"sv, unicode_data.sentence_break_props);
  897. auto append_code_point_display_names = [&](StringView type, StringView name, auto const& display_names) {
  898. constexpr size_t max_values_per_row = 30;
  899. size_t values_in_current_row = 0;
  900. generator.set("type", type);
  901. generator.set("name", name);
  902. generator.set("size", DeprecatedString::number(display_names.size()));
  903. generator.append(R"~~~(
  904. static constexpr Array<@type@, @size@> @name@ { {
  905. )~~~");
  906. for (auto const& display_name : display_names) {
  907. if (values_in_current_row++ > 0)
  908. generator.append(", ");
  909. generator.set("first", DeprecatedString::formatted("{:#x}", display_name.code_point_range.first));
  910. generator.set("last", DeprecatedString::formatted("{:#x}", display_name.code_point_range.last));
  911. generator.set("name", DeprecatedString::number(display_name.name));
  912. generator.append("{ { @first@, @last@ }, @name@ }");
  913. if (values_in_current_row == max_values_per_row) {
  914. values_in_current_row = 0;
  915. generator.append(",\n ");
  916. }
  917. }
  918. generator.append(R"~~~(
  919. } };
  920. )~~~");
  921. };
  922. append_code_point_display_names("BlockNameData"sv, "s_block_display_names"sv, unicode_data.block_display_names);
  923. append_code_point_display_names("CodePointName"sv, "s_code_point_display_names"sv, unicode_data.code_point_display_names);
  924. generator.append(R"~~~(
  925. Optional<StringView> code_point_block_display_name(u32 code_point)
  926. {
  927. if (auto const* entry = binary_search(s_block_display_names, code_point, nullptr, BlockNameComparator {}))
  928. return decode_string(entry->display_name);
  929. return {};
  930. }
  931. ReadonlySpan<BlockName> block_display_names()
  932. {
  933. static auto display_names = []() {
  934. Array<BlockName, s_block_display_names.size()> display_names;
  935. for (size_t i = 0; i < s_block_display_names.size(); ++i) {
  936. auto const& display_name = s_block_display_names[i];
  937. display_names[i] = { display_name.code_point_range, decode_string(display_name.display_name) };
  938. }
  939. return display_names;
  940. }();
  941. return display_names.span();
  942. }
  943. Optional<DeprecatedString> code_point_display_name(u32 code_point)
  944. {
  945. if (auto const* entry = binary_search(s_code_point_display_names, code_point, nullptr, CodePointNameComparator {})) {
  946. auto display_name = decode_string(entry->display_name);
  947. if (display_name.ends_with("{:X}"sv))
  948. return DeprecatedString::formatted(display_name, code_point);
  949. return display_name;
  950. }
  951. return {};
  952. }
  953. )~~~");
  954. auto append_code_point_mapping_search = [&](StringView method, StringView mappings, StringView fallback) {
  955. generator.set("method", method);
  956. generator.set("mappings", mappings);
  957. generator.set("fallback", fallback);
  958. generator.append(R"~~~(
  959. u32 @method@(u32 code_point)
  960. {
  961. auto const* mapping = binary_search(@mappings@, code_point, nullptr, CodePointComparator<CodePointMapping> {});
  962. return mapping ? mapping->mapping : @fallback@;
  963. }
  964. )~~~");
  965. };
  966. append_code_point_mapping_search("canonical_combining_class"sv, "s_combining_class_mappings"sv, "0"sv);
  967. append_code_point_mapping_search("to_unicode_uppercase"sv, "s_uppercase_mappings"sv, "code_point"sv);
  968. append_code_point_mapping_search("to_unicode_lowercase"sv, "s_lowercase_mappings"sv, "code_point"sv);
  969. append_code_point_mapping_search("to_unicode_titlecase"sv, "s_titlecase_mappings"sv, "code_point"sv);
  970. generator.append(R"~~~(
  971. ReadonlySpan<SpecialCasing const*> special_case_mapping(u32 code_point)
  972. {
  973. auto const* mapping = binary_search(s_special_case_mappings, code_point, nullptr, CodePointComparator<SpecialCaseMapping> {});
  974. if (mapping == nullptr)
  975. return {};
  976. return mapping->special_casing.span().slice(0, mapping->special_casing_size);
  977. }
  978. ReadonlySpan<CaseFolding const*> case_folding_mapping(u32 code_point)
  979. {
  980. auto const* mapping = binary_search(s_case_folding_mappings, code_point, nullptr, CodePointComparator<CaseFoldingMapping> {});
  981. if (mapping == nullptr)
  982. return {};
  983. return mapping->case_folding.span().slice(0, mapping->case_folding_size);
  984. }
  985. Optional<StringView> code_point_abbreviation(u32 code_point)
  986. {
  987. auto const* mapping = binary_search(s_abbreviation_mappings, code_point, nullptr, CodePointComparator<CodePointAbbreviation> {});
  988. if (mapping == nullptr)
  989. return {};
  990. if (mapping->abbreviation == 0)
  991. return {};
  992. return decode_string(mapping->abbreviation);
  993. }
  994. Optional<CodePointDecomposition const> code_point_decomposition(u32 code_point)
  995. {
  996. auto const* mapping = binary_search(s_decomposition_mappings, code_point, nullptr, CodePointComparator<CodePointDecompositionRaw> {});
  997. if (mapping == nullptr)
  998. return {};
  999. return CodePointDecomposition { mapping->code_point, mapping->tag, ReadonlySpan<u32> { s_decomposition_mappings_data.data() + mapping->decomposition_index, mapping->decomposition_count } };
  1000. }
  1001. Optional<CodePointDecomposition const> code_point_decomposition_by_index(size_t index)
  1002. {
  1003. if (index >= s_decomposition_mappings.size())
  1004. return {};
  1005. auto const& mapping = s_decomposition_mappings[index];
  1006. return CodePointDecomposition { mapping.code_point, mapping.tag, ReadonlySpan<u32> { s_decomposition_mappings_data.data() + mapping.decomposition_index, mapping.decomposition_count } };
  1007. }
  1008. )~~~");
  1009. auto append_prop_search = [&](StringView enum_title, StringView enum_snake, StringView collection_name) {
  1010. generator.set("enum_title", enum_title);
  1011. generator.set("enum_snake", enum_snake);
  1012. generator.set("collection_name", collection_name);
  1013. generator.append(R"~~~(
  1014. bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@)
  1015. {
  1016. auto index = static_cast<@enum_title@UnderlyingType>(@enum_snake@);
  1017. auto const& ranges = @collection_name@.at(index);
  1018. auto const* range = binary_search(ranges, code_point, nullptr, CodePointRangeComparator {});
  1019. return range != nullptr;
  1020. }
  1021. )~~~");
  1022. };
  1023. auto append_from_string = [&](StringView enum_title, StringView enum_snake, auto const& prop_list, Vector<Alias> const& aliases) -> ErrorOr<void> {
  1024. HashValueMap<StringView> hashes;
  1025. TRY(hashes.try_ensure_capacity(prop_list.size() + aliases.size()));
  1026. ValueFromStringOptions options {};
  1027. for (auto const& prop : prop_list) {
  1028. if constexpr (IsSame<RemoveCVReference<decltype(prop)>, DeprecatedString>) {
  1029. hashes.set(CaseInsensitiveASCIIStringViewTraits::hash(prop), prop);
  1030. options.sensitivity = CaseSensitivity::CaseInsensitive;
  1031. } else {
  1032. hashes.set(prop.key.hash(), prop.key);
  1033. }
  1034. }
  1035. for (auto const& alias : aliases)
  1036. hashes.set(alias.alias.hash(), alias.alias);
  1037. generate_value_from_string(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes), options);
  1038. return {};
  1039. };
  1040. TRY(append_from_string("Locale"sv, "locale"sv, unicode_data.locales, {}));
  1041. append_prop_search("GeneralCategory"sv, "general_category"sv, "s_general_categories"sv);
  1042. TRY(append_from_string("GeneralCategory"sv, "general_category"sv, unicode_data.general_categories, unicode_data.general_category_aliases));
  1043. append_prop_search("Property"sv, "property"sv, "s_properties"sv);
  1044. TRY(append_from_string("Property"sv, "property"sv, unicode_data.prop_list, unicode_data.prop_aliases));
  1045. append_prop_search("Script"sv, "script"sv, "s_scripts"sv);
  1046. append_prop_search("Script"sv, "script_extension"sv, "s_script_extensions"sv);
  1047. TRY(append_from_string("Script"sv, "script"sv, unicode_data.script_list, unicode_data.script_aliases));
  1048. append_prop_search("GraphemeBreakProperty"sv, "grapheme_break_property"sv, "s_grapheme_break_properties"sv);
  1049. append_prop_search("WordBreakProperty"sv, "word_break_property"sv, "s_word_break_properties"sv);
  1050. append_prop_search("SentenceBreakProperty"sv, "sentence_break_property"sv, "s_sentence_break_properties"sv);
  1051. generator.append(R"~~~(
  1052. }
  1053. )~~~");
  1054. TRY(file.write_until_depleted(generator.as_string_view().bytes()));
  1055. return {};
  1056. }
  1057. static Vector<u32> flatten_code_point_ranges(Vector<Unicode::CodePointRange> const& code_points)
  1058. {
  1059. Vector<u32> flattened;
  1060. for (auto const& range : code_points) {
  1061. flattened.grow_capacity(range.last - range.first);
  1062. for (u32 code_point = range.first; code_point <= range.last; ++code_point)
  1063. flattened.append(code_point);
  1064. }
  1065. return flattened;
  1066. }
  1067. static Vector<Unicode::CodePointRange> form_code_point_ranges(Vector<u32> code_points)
  1068. {
  1069. Vector<Unicode::CodePointRange> ranges;
  1070. u32 range_start = code_points[0];
  1071. u32 range_end = range_start;
  1072. for (size_t i = 1; i < code_points.size(); ++i) {
  1073. u32 code_point = code_points[i];
  1074. if ((code_point - range_end) == 1) {
  1075. range_end = code_point;
  1076. } else {
  1077. ranges.append({ range_start, range_end });
  1078. range_start = code_point;
  1079. range_end = code_point;
  1080. }
  1081. }
  1082. ranges.append({ range_start, range_end });
  1083. return ranges;
  1084. }
  1085. static void sort_and_merge_code_point_ranges(Vector<Unicode::CodePointRange>& code_points)
  1086. {
  1087. quick_sort(code_points, [](auto const& range1, auto const& range2) {
  1088. return range1.first < range2.first;
  1089. });
  1090. for (size_t i = 0; i < code_points.size() - 1;) {
  1091. if (code_points[i].last >= code_points[i + 1].first) {
  1092. code_points[i].last = max(code_points[i].last, code_points[i + 1].last);
  1093. code_points.remove(i + 1);
  1094. } else {
  1095. ++i;
  1096. }
  1097. }
  1098. auto all_code_points = flatten_code_point_ranges(code_points);
  1099. code_points = form_code_point_ranges(all_code_points);
  1100. }
  1101. static void populate_general_category_unions(PropList& general_categories)
  1102. {
  1103. // The Unicode standard defines General Category values which are not in any UCD file. These
  1104. // values are simply unions of other values.
  1105. // https://www.unicode.org/reports/tr44/#GC_Values_Table
  1106. auto populate_union = [&](auto alias, auto categories) {
  1107. auto& code_points = general_categories.ensure(alias);
  1108. for (auto const& category : categories)
  1109. code_points.extend(general_categories.find(category)->value);
  1110. sort_and_merge_code_point_ranges(code_points);
  1111. };
  1112. populate_union("LC"sv, Array { "Ll"sv, "Lu"sv, "Lt"sv });
  1113. populate_union("L"sv, Array { "Lu"sv, "Ll"sv, "Lt"sv, "Lm"sv, "Lo"sv });
  1114. populate_union("M"sv, Array { "Mn"sv, "Mc"sv, "Me"sv });
  1115. populate_union("N"sv, Array { "Nd"sv, "Nl"sv, "No"sv });
  1116. populate_union("P"sv, Array { "Pc"sv, "Pd"sv, "Ps"sv, "Pe"sv, "Pi"sv, "Pf"sv, "Po"sv });
  1117. populate_union("S"sv, Array { "Sm"sv, "Sc"sv, "Sk"sv, "So"sv });
  1118. populate_union("Z"sv, Array { "Zs"sv, "Zl"sv, "Zp"sv });
  1119. populate_union("C"sv, Array { "Cc"sv, "Cf"sv, "Cs"sv, "Co"sv, "Cn"sv });
  1120. }
  1121. static ErrorOr<void> normalize_script_extensions(PropList& script_extensions, PropList const& script_list, Vector<Alias> const& script_aliases)
  1122. {
  1123. // The ScriptExtensions UCD file lays out its code point ranges rather uniquely compared to
  1124. // other files. The Script listed on each line may either be a full Script string or an aliased
  1125. // abbreviation. Further, the extensions may or may not include the base Script list. Normalize
  1126. // the extensions here to be keyed by the full Script name and always include the base list.
  1127. auto extensions = move(script_extensions);
  1128. script_extensions = TRY(script_list.clone());
  1129. for (auto const& extension : extensions) {
  1130. auto it = find_if(script_aliases.begin(), script_aliases.end(), [&](auto const& alias) { return extension.key == alias.alias; });
  1131. auto const& key = (it == script_aliases.end()) ? extension.key : it->name;
  1132. auto& code_points = script_extensions.find(key)->value;
  1133. code_points.extend(extension.value);
  1134. sort_and_merge_code_point_ranges(code_points);
  1135. }
  1136. // Lastly, the Common and Inherited script extensions are special. They must not contain any
  1137. // code points which appear in other script extensions. The ScriptExtensions UCD file does not
  1138. // list these extensions, therefore this peculiarity must be handled programmatically.
  1139. // https://www.unicode.org/reports/tr24/#Assignment_ScriptX_Values
  1140. auto code_point_has_other_extension = [&](StringView key, u32 code_point) {
  1141. for (auto const& extension : extensions) {
  1142. if (extension.key == key)
  1143. continue;
  1144. if (any_of(extension.value, [&](auto const& r) { return (r.first <= code_point) && (code_point <= r.last); }))
  1145. return true;
  1146. }
  1147. return false;
  1148. };
  1149. auto get_code_points_without_other_extensions = [&](StringView key) {
  1150. auto code_points = flatten_code_point_ranges(script_list.find(key)->value);
  1151. code_points.remove_all_matching([&](u32 c) { return code_point_has_other_extension(key, c); });
  1152. return code_points;
  1153. };
  1154. auto common_code_points = get_code_points_without_other_extensions("Common"sv);
  1155. script_extensions.set("Common"sv, form_code_point_ranges(common_code_points));
  1156. auto inherited_code_points = get_code_points_without_other_extensions("Inherited"sv);
  1157. script_extensions.set("Inherited"sv, form_code_point_ranges(inherited_code_points));
  1158. return {};
  1159. }
  1160. ErrorOr<int> serenity_main(Main::Arguments arguments)
  1161. {
  1162. StringView generated_header_path;
  1163. StringView generated_implementation_path;
  1164. StringView unicode_data_path;
  1165. StringView special_casing_path;
  1166. StringView case_folding_path;
  1167. StringView derived_general_category_path;
  1168. StringView prop_list_path;
  1169. StringView derived_core_prop_path;
  1170. StringView derived_binary_prop_path;
  1171. StringView prop_alias_path;
  1172. StringView prop_value_alias_path;
  1173. StringView name_alias_path;
  1174. StringView scripts_path;
  1175. StringView script_extensions_path;
  1176. StringView blocks_path;
  1177. StringView emoji_data_path;
  1178. StringView normalization_path;
  1179. StringView grapheme_break_path;
  1180. StringView word_break_path;
  1181. StringView sentence_break_path;
  1182. Core::ArgsParser args_parser;
  1183. args_parser.add_option(generated_header_path, "Path to the Unicode Data header file to generate", "generated-header-path", 'h', "generated-header-path");
  1184. args_parser.add_option(generated_implementation_path, "Path to the Unicode Data implementation file to generate", "generated-implementation-path", 'c', "generated-implementation-path");
  1185. args_parser.add_option(unicode_data_path, "Path to UnicodeData.txt file", "unicode-data-path", 'u', "unicode-data-path");
  1186. args_parser.add_option(special_casing_path, "Path to SpecialCasing.txt file", "special-casing-path", 's', "special-casing-path");
  1187. args_parser.add_option(case_folding_path, "Path to CaseFolding.txt file", "case-folding-path", 'o', "case-folding-path");
  1188. args_parser.add_option(derived_general_category_path, "Path to DerivedGeneralCategory.txt file", "derived-general-category-path", 'g', "derived-general-category-path");
  1189. args_parser.add_option(prop_list_path, "Path to PropList.txt file", "prop-list-path", 'p', "prop-list-path");
  1190. args_parser.add_option(derived_core_prop_path, "Path to DerivedCoreProperties.txt file", "derived-core-prop-path", 'd', "derived-core-prop-path");
  1191. args_parser.add_option(derived_binary_prop_path, "Path to DerivedBinaryProperties.txt file", "derived-binary-prop-path", 'b', "derived-binary-prop-path");
  1192. args_parser.add_option(prop_alias_path, "Path to PropertyAliases.txt file", "prop-alias-path", 'a', "prop-alias-path");
  1193. args_parser.add_option(prop_value_alias_path, "Path to PropertyValueAliases.txt file", "prop-value-alias-path", 'v', "prop-value-alias-path");
  1194. args_parser.add_option(name_alias_path, "Path to NameAliases.txt file", "name-alias-path", 'm', "name-alias-path");
  1195. args_parser.add_option(scripts_path, "Path to Scripts.txt file", "scripts-path", 'r', "scripts-path");
  1196. args_parser.add_option(script_extensions_path, "Path to ScriptExtensions.txt file", "script-extensions-path", 'x', "script-extensions-path");
  1197. args_parser.add_option(blocks_path, "Path to Blocks.txt file", "blocks-path", 'k', "blocks-path");
  1198. args_parser.add_option(emoji_data_path, "Path to emoji-data.txt file", "emoji-data-path", 'e', "emoji-data-path");
  1199. args_parser.add_option(normalization_path, "Path to DerivedNormalizationProps.txt file", "normalization-path", 'n', "normalization-path");
  1200. args_parser.add_option(grapheme_break_path, "Path to GraphemeBreakProperty.txt file", "grapheme-break-path", 'f', "grapheme-break-path");
  1201. args_parser.add_option(word_break_path, "Path to WordBreakProperty.txt file", "word-break-path", 'w', "word-break-path");
  1202. args_parser.add_option(sentence_break_path, "Path to SentenceBreakProperty.txt file", "sentence-break-path", 'i', "sentence-break-path");
  1203. args_parser.parse(arguments);
  1204. auto generated_header_file = TRY(open_file(generated_header_path, Core::File::OpenMode::Write));
  1205. auto generated_implementation_file = TRY(open_file(generated_implementation_path, Core::File::OpenMode::Write));
  1206. auto unicode_data_file = TRY(open_file(unicode_data_path, Core::File::OpenMode::Read));
  1207. auto derived_general_category_file = TRY(open_file(derived_general_category_path, Core::File::OpenMode::Read));
  1208. auto special_casing_file = TRY(open_file(special_casing_path, Core::File::OpenMode::Read));
  1209. auto case_folding_file = TRY(open_file(case_folding_path, Core::File::OpenMode::Read));
  1210. auto prop_list_file = TRY(open_file(prop_list_path, Core::File::OpenMode::Read));
  1211. auto derived_core_prop_file = TRY(open_file(derived_core_prop_path, Core::File::OpenMode::Read));
  1212. auto derived_binary_prop_file = TRY(open_file(derived_binary_prop_path, Core::File::OpenMode::Read));
  1213. auto prop_alias_file = TRY(open_file(prop_alias_path, Core::File::OpenMode::Read));
  1214. auto prop_value_alias_file = TRY(open_file(prop_value_alias_path, Core::File::OpenMode::Read));
  1215. auto name_alias_file = TRY(open_file(name_alias_path, Core::File::OpenMode::Read));
  1216. auto scripts_file = TRY(open_file(scripts_path, Core::File::OpenMode::Read));
  1217. auto script_extensions_file = TRY(open_file(script_extensions_path, Core::File::OpenMode::Read));
  1218. auto blocks_file = TRY(open_file(blocks_path, Core::File::OpenMode::Read));
  1219. auto emoji_data_file = TRY(open_file(emoji_data_path, Core::File::OpenMode::Read));
  1220. auto normalization_file = TRY(open_file(normalization_path, Core::File::OpenMode::Read));
  1221. auto grapheme_break_file = TRY(open_file(grapheme_break_path, Core::File::OpenMode::Read));
  1222. auto word_break_file = TRY(open_file(word_break_path, Core::File::OpenMode::Read));
  1223. auto sentence_break_file = TRY(open_file(sentence_break_path, Core::File::OpenMode::Read));
  1224. UnicodeData unicode_data {};
  1225. TRY(parse_special_casing(*special_casing_file, unicode_data));
  1226. TRY(parse_case_folding(*case_folding_file, unicode_data));
  1227. TRY(parse_prop_list(*derived_general_category_file, unicode_data.general_categories));
  1228. TRY(parse_prop_list(*prop_list_file, unicode_data.prop_list));
  1229. TRY(parse_prop_list(*derived_core_prop_file, unicode_data.prop_list));
  1230. TRY(parse_prop_list(*derived_binary_prop_file, unicode_data.prop_list));
  1231. TRY(parse_prop_list(*emoji_data_file, unicode_data.prop_list));
  1232. TRY(parse_normalization_props(*normalization_file, unicode_data));
  1233. TRY(parse_alias_list(*prop_alias_file, unicode_data.prop_list, unicode_data.prop_aliases));
  1234. TRY(parse_prop_list(*scripts_file, unicode_data.script_list));
  1235. TRY(parse_prop_list(*script_extensions_file, unicode_data.script_extensions, true));
  1236. TRY(parse_block_display_names(*blocks_file, unicode_data));
  1237. TRY(parse_name_aliases(*name_alias_file, unicode_data));
  1238. TRY(parse_prop_list(*grapheme_break_file, unicode_data.grapheme_break_props));
  1239. TRY(parse_prop_list(*word_break_file, unicode_data.word_break_props));
  1240. TRY(parse_prop_list(*sentence_break_file, unicode_data.sentence_break_props));
  1241. populate_general_category_unions(unicode_data.general_categories);
  1242. TRY(parse_unicode_data(*unicode_data_file, unicode_data));
  1243. TRY(parse_value_alias_list(*prop_value_alias_file, "gc"sv, unicode_data.general_categories.keys(), unicode_data.general_category_aliases));
  1244. TRY(parse_value_alias_list(*prop_value_alias_file, "sc"sv, unicode_data.script_list.keys(), unicode_data.script_aliases, false));
  1245. TRY(normalize_script_extensions(unicode_data.script_extensions, unicode_data.script_list, unicode_data.script_aliases));
  1246. TRY(generate_unicode_data_header(*generated_header_file, unicode_data));
  1247. TRY(generate_unicode_data_implementation(*generated_implementation_file, unicode_data));
  1248. return 0;
  1249. }