vss_24.0.0_b4d0be7c/tools/ucd/ucd-derived_normalization_props_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
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
--
--  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;

with Ada.Wide_Wide_Text_IO;

package body UCD.Derived_Normalization_Props_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.

      Value_Field : constant Data_File_Loaders.Field_Index := 2;
      --  Index of the data field for the value of property, when provided.

      Loader : UCD.Data_File_Loaders.File_Loader;

   begin
      --  Default value for derived NFD_Quick_Check, NFC_Quick_Check,
      --  NFKD_Quick_Check properties is 'Y', this feature is not supported
      --  by the loader, thus set it manually.

      declare
         NFD_QC_Property  : constant not null Properties.Property_Access :=
           Properties.Resolve ("NFD_QC");
         NFD_QC_Y         : constant not null
           Properties.Property_Value_Access :=
             Properties.Resolve (NFD_QC_Property, "Y");
         NFC_QC_Property  : constant not null Properties.Property_Access :=
           Properties.Resolve ("NFC_QC");
         NFC_QC_Y         : constant not null
           Properties.Property_Value_Access :=
             Properties.Resolve (NFC_QC_Property, "Y");
         NFKD_QC_Property : constant not null Properties.Property_Access :=
           Properties.Resolve ("NFKD_QC");
         NFKD_QC_Y        : constant not null
           Properties.Property_Value_Access :=
             Properties.Resolve (NFKD_QC_Property, "Y");
         NFKC_QC_Property : constant not null Properties.Property_Access :=
           Properties.Resolve ("NFKC_QC");
         NFKC_QC_Y        : constant not null
           Properties.Property_Value_Access :=
             Properties.Resolve (NFKC_QC_Property, "Y");

      begin
         for Code in Code_Point loop
            Characters.Set (Code, NFD_QC_Property, NFD_QC_Y);
            Characters.Set (Code, NFC_QC_Property, NFC_QC_Y);
            Characters.Set (Code, NFKD_QC_Property, NFKD_QC_Y);
            Characters.Set (Code, NFKC_QC_Property, NFKC_QC_Y);
         end loop;
      end;

      Loader.Open (UCD_Root, "DerivedNormalizationProps.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_Name : constant Wide_Wide_String :=
                 Loader.Get_Field (Name_Field);
               Property      : constant not null Properties.Property_Access :=
                 Properties.Resolve (Property_Name);

            begin
               if Property_Name
                    in "FC_NFKC" | "Expands_On_NFD" | "Expands_On_NFC"
                      | "Expands_On_NFKD" | "Expands_On_NFKC"
               then
                  --  FC_NFKC_Closure, Expands_On_NFD, Expands_On_NFC,
                  --  Expands_On_NFKD, Expands_On_NFKC properties are
                  --  deprecated and not used in VSS, don't load it.

                  null;

               elsif Property_Name
                       in "Full_Composition_Exclusion"
                         | "Changes_When_NFKC_Casefolded"
               then
                  --  Binary properties

                  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;

               elsif Property_Name
                       in "NFD_QC" | "NFC_QC" | "NFKD_QC" | "NFKC_QC"
               then
                  --  Enumeration properties

                  for Code in First_Code .. Last_Code loop
                     Characters.Set
                       (Code,
                        Property,
                        Properties.Resolve
                          (Property, Loader.Get_Field (Value_Field)));
                  end loop;

               elsif Property_Name = "NFKC_CF" then
                  --  String property

                  Property.Is_String := True;

                  for Code in First_Code .. Last_Code loop
                     Characters.Set
                       (Code,
                        Property,
                        new Properties.Property_Value'
                          (Names                           => <>,
                           Is_Used                         => <>,
                           Canonical_Combining_Class_Value => <>,
                           String                          =>
                             Loader.Get_Field (Value_Field)));
                  end loop;

               else
                  Ada.Wide_Wide_Text_IO.Put_Line (''' & Property_Name & ''');

                  raise Program_Error;
               end if;
            end;

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

end UCD.Derived_Normalization_Props_Loader;