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 | --
-- Copyright (C) 2021-2023, 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; use Ada.Wide_Wide_Text_IO;
package body UCD.Property_Value_Aliases_Loader is
------------------
-- Load_Aliases --
------------------
procedure Load_Aliases (UCD_Root : Wide_Wide_String) is
Loader : UCD.Data_File_Loaders.File_Loader;
begin
Loader.Open (UCD_Root, "PropertyValueAliases.txt", "aliases");
while not Loader.End_Of_File loop
if not Loader.Is_Missing then
declare
P : constant Properties.Property_Access :=
Properties.Name_To_Property
(To_Unbounded_Wide_Wide_String (Loader.Get_Field (0)));
V : constant Properties.Property_Value_Access :=
new Properties.Property_Value;
F : Data_File_Loaders.Field_Index := 1;
begin
if P.Is_Canonical_Combining_Class then
-- Second field for 'ccc' property is numeric value.
V.Canonical_Combining_Class_Value :=
Properties.Canonical_Combinig_Class'Wide_Wide_Value
(Loader.Get_Field (1));
F := 2;
end if;
for J in F .. Data_File_Loaders.Field_Index'Last loop
if Loader.Has_Field (J) then
declare
Name : constant Unbounded_Wide_Wide_String :=
To_Unbounded_Wide_Wide_String (Loader.Get_Field (J));
begin
-- Short name and long name may be the same, ignore
-- duplicates.
if V.Names.Is_Empty
or else Name /= V.Names.First_Element
then
V.Names.Append (Name);
end if;
end;
end if;
end loop;
-- Register value and its names
P.All_Values.Append (V);
for Name of V.Names loop
P.Name_To_Value.Insert (Name, V);
end loop;
end;
end if;
Loader.Skip_Line;
end loop;
end Load_Aliases;
------------------
-- Load_Missing --
------------------
procedure Load_Missing (UCD_Root : Wide_Wide_String) is
Loader : UCD.Data_File_Loaders.File_Loader;
begin
Loader.Open (UCD_Root, "PropertyValueAliases.txt", "missing");
while not Loader.End_Of_File loop
if Loader.Is_Missing then
declare
use type Properties.Property_Value_Access;
First_Code : UCD.Code_Point;
Last_Code : UCD.Code_Point;
Property : constant Properties.Property_Access :=
Properties.Name_To_Property
(To_Unbounded_Wide_Wide_String
(Loader.Get_Field (1, True)));
Image : constant Wide_Wide_String :=
Loader.Get_Field (2, True);
Value : constant Properties.Property_Value_Access :=
(if Image in "<none>" | "<code point>" | "NaN"
then null else Properties.Resolve (Property, Image));
-- Ignore:
-- - "<none>" for string properties;
-- - "<code point>" for mapping to itself;
-- - "NaN" for numeric values.
begin
Loader.Get_Code_Point_Range (First_Code, Last_Code);
-- Put_Line (Image);
if Value /= null then
Ada.Wide_Wide_Text_IO.Put_Line
(" - set " & Loader.Get_Field (1, True)
& " to '" & Loader.Get_Field (2, True)
& "' in " & Loader.Get_Field (0, True));
for Code in First_Code .. Last_Code loop
Characters.Set (Code, Property, Value);
end loop;
end if;
end;
end if;
Loader.Skip_Line;
end loop;
end Load_Missing;
end UCD.Property_Value_Aliases_Loader;
|