LibUnicode: Handle edge-case script extensions, Common and Inherited

These script extensions have some peculiar behavior in the Unicode spec.
The UCD ScriptExtension file does not contain these scripts. Rather, it
is implied the code points which have these scripts as an extension are
the code points that both:

  1. Have Common or Inherited as their primary script value
  2. Do not have any other script value in their script extension lists

Because these are not explictly listed in the UCD, we must manually form
these script extensions.
This commit is contained in:
Timothy Flynn 2021-08-10 17:42:21 -04:00 committed by Andreas Kling
commit 1e91334008
Notes: sideshowbarker 2024-07-18 07:06:47 +09:00
2 changed files with 49 additions and 0 deletions

View file

@ -464,4 +464,26 @@ TEST_CASE(script_extension)
EXPECT(!Unicode::code_point_has_script(0x1dc1, script_greek));
EXPECT(Unicode::code_point_has_script_extension(0x1dc1, script_greek));
auto script_common = script("Common"sv);
auto script_zyyy = script("Zyyy"sv);
EXPECT_EQ(script_common, script_zyyy);
EXPECT(Unicode::code_point_has_script(0x202f, script_common));
EXPECT(!Unicode::code_point_has_script_extension(0x202f, script_common));
EXPECT(Unicode::code_point_has_script(0x3000, script_common));
EXPECT(Unicode::code_point_has_script_extension(0x3000, script_common));
auto script_inherited = script("Inherited"sv);
auto script_qaai = script("Qaai"sv);
auto script_zinh = script("Zinh"sv);
EXPECT_EQ(script_inherited, script_qaai);
EXPECT_EQ(script_inherited, script_zinh);
EXPECT(Unicode::code_point_has_script(0x1ced, script_inherited));
EXPECT(!Unicode::code_point_has_script_extension(0x1ced, script_inherited));
EXPECT(Unicode::code_point_has_script(0x101fd, script_inherited));
EXPECT(Unicode::code_point_has_script_extension(0x101fd, script_inherited));
}