umwi_0.1.0_34abe384/generator/src/tools-emoji_classifier.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
with AAA.Strings;

with Ada.Strings.UTF_Encoding.Wide_Wide_Strings;
use  Ada.Strings.UTF_Encoding.Wide_Wide_Strings;
with Ada.Wide_Wide_Text_IO; use Ada.Wide_Wide_Text_IO;

package body Tools.Emoji_Classifier is

   First : Boolean := True;

   --------------
   -- Classify --
   --------------

   procedure Classify (Line : WWString) is
      use AAA.Strings;
   begin
      if Line = "" or else Line (Line'First) = '#' then
         return;
      end if;

      declare
         Line8 : constant String := Encode (Line); -- To UTF8
         Codes : constant Vector := Split (Line8, ';', Trim => True);
         Sepco : constant Vector := Split (Codes (1), '.');
         Label : constant Vector := Split (Codes (2), '#', Trim => True);
         Info  : Vector := Label;
         --  The emoji-data.txt file is UTF8 with plenty of non-ASCII content
      begin
         if Decode (Label (1)) = Target_Label then
            Put_Line (F.all,
                      (if First then "      " else "    | ")
                      & C (Sepco (1))
                      & (if Sepco.Length in 3
                        then " .. " & C (Sepco (3))
                        else "")
                     );
            Info.Delete_First;
            Put_Line (F.all, "      --  " & Decode (Info.Flatten ('#')));
            First := False;
         end if;
      end;
   end Classify;

begin
   New_Line (F.all);
   Put_Line (F.all, "   subtype " & Target_Label & " is WWChar");
   Put_Line (F.all, "      with Static_Predicate => " & Target_Label & " in");
end Tools.Emoji_Classifier;