vss_24.0.0_b4d0be7c/tools/ucd/ucd-emoji_data_loader.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
--
--  Copyright (C) 2021, AdaCore
--
--  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--

with Ada.Strings.Wide_Wide_Unbounded; use Ada.Strings.Wide_Wide_Unbounded;

with UCD.Characters;
with UCD.Data_File_Loaders;
with UCD.Properties;

package body UCD.Emoji_Data_Loader is

   ----------
   -- Load --
   ----------

   procedure Load (UCD_Root : Wide_Wide_String) is
      Name_Field : constant Data_File_Loaders.Field_Index := 1;
      --  Index of the data field with name of the property.

      Loader : UCD.Data_File_Loaders.File_Loader;

   begin
      --  Unicode 13.0: exception: Extended_Pictographic property is Y by
      --  default for unassigned code points in few ranges.

      declare
         use type UCD.Properties.Property_Value_Access;

         GC_Property      : constant not null Properties.Property_Access :=
           Properties.Resolve ("gc");
         GC_Unassigned    : constant not null
           Properties.Property_Value_Access :=
             Properties.Resolve (GC_Property, "Cn");
         ExtPict_Property : constant not null Properties.Property_Access :=
           Properties.Resolve ("ExtPict");
         ExtPict_Y        : constant not null
           Properties.Property_Value_Access :=
             Properties.Resolve (ExtPict_Property, "Y");
         ExtPict_N        : constant not null
           Properties.Property_Value_Access :=
             Properties.Resolve (ExtPict_Property, "N");

      begin
         for C in UCD.Code_Point loop
            if C in 16#01_F000# .. 16#01_FAFF# | 16#01_FC00# .. 16#01_FFFD#
            then
               if UCD.Characters.Get (C, GC_Property) = GC_Unassigned then
                  UCD.Characters.Set (C, ExtPict_Property, ExtPict_Y);

               else
                  UCD.Characters.Set (C, ExtPict_Property, ExtPict_N);
               end if;

            else
               UCD.Characters.Set (C, ExtPict_Property, ExtPict_N);
            end if;
         end loop;
      end;

      Loader.Open (UCD_Root, "emoji/emoji-data.txt");

      while not Loader.End_Of_File loop
         declare
            First_Code : UCD.Code_Point;
            Last_Code  : UCD.Code_Point;

         begin
            Loader.Get_Code_Point_Range (First_Code, Last_Code);

            declare
               Property : constant not null Properties.Property_Access :=
                 Properties.Resolve (Loader.Get_Field (Name_Field));

            begin
               for Code in First_Code .. Last_Code loop
                  Characters.Set
                    (Code, Property, Property.Name_To_Value.Element
                       (To_Unbounded_Wide_Wide_String ("Y")));
               end loop;
            end;

            Loader.Skip_Line;
         end;
      end loop;
   end Load;

end UCD.Emoji_Data_Loader;