1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . S T R I N G S . W I D E _ M A P S --
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
23 -- additional permissions described in the GCC Runtime Library Exception, --
24 -- version 3.1, as published by the Free Software Foundation. --
26 -- You should have received a copy of the GNU General Public License and --
27 -- a copy of the GCC Runtime Library Exception along with this program; --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
29 -- <http://www.gnu.org/licenses/>. --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
34 ------------------------------------------------------------------------------
36 with Ada
.Finalization
;
38 package Ada
.Strings
.Wide_Maps
is
41 -------------------------------------
42 -- Wide Character Set Declarations --
43 -------------------------------------
45 type Wide_Character_Set
is private;
46 pragma Preelaborable_Initialization
(Wide_Character_Set
);
47 -- Representation for a set of Wide_Character values:
49 Null_Set
: constant Wide_Character_Set
;
51 ------------------------------------------
52 -- Constructors for Wide Character Sets --
53 ------------------------------------------
55 type Wide_Character_Range
is record
57 High
: Wide_Character;
59 -- Represents Wide_Character range Low .. High
61 type Wide_Character_Ranges
is
62 array (Positive range <>) of Wide_Character_Range
;
65 (Ranges
: Wide_Character_Ranges
) return Wide_Character_Set
;
68 (Span
: Wide_Character_Range
) return Wide_Character_Set
;
71 (Set
: Wide_Character_Set
) return Wide_Character_Ranges
;
73 ---------------------------------------
74 -- Operations on Wide Character Sets --
75 ---------------------------------------
77 function "=" (Left
, Right
: Wide_Character_Set
) return Boolean;
80 (Right
: Wide_Character_Set
) return Wide_Character_Set
;
83 (Left
, Right
: Wide_Character_Set
) return Wide_Character_Set
;
86 (Left
, Right
: Wide_Character_Set
) return Wide_Character_Set
;
89 (Left
, Right
: Wide_Character_Set
) return Wide_Character_Set
;
92 (Left
, Right
: Wide_Character_Set
) return Wide_Character_Set
;
95 (Element
: Wide_Character;
96 Set
: Wide_Character_Set
) return Boolean;
99 (Elements
: Wide_Character_Set
;
100 Set
: Wide_Character_Set
) return Boolean;
103 (Left
: Wide_Character_Set
;
104 Right
: Wide_Character_Set
) return Boolean
107 subtype Wide_Character_Sequence
is Wide_String;
108 -- Alternative representation for a set of character values
111 (Sequence
: Wide_Character_Sequence
) return Wide_Character_Set
;
114 (Singleton
: Wide_Character) return Wide_Character_Set
;
117 (Set
: Wide_Character_Set
) return Wide_Character_Sequence
;
119 -----------------------------------------
120 -- Wide Character Mapping Declarations --
121 -----------------------------------------
123 type Wide_Character_Mapping
is private;
124 pragma Preelaborable_Initialization
(Wide_Character_Mapping
);
125 -- Representation for a wide character to wide character mapping:
128 (Map
: Wide_Character_Mapping
;
129 Element
: Wide_Character) return Wide_Character;
131 Identity
: constant Wide_Character_Mapping
;
133 ---------------------------------
134 -- Operations on Wide Mappings --
135 ---------------------------------
138 (From
, To
: Wide_Character_Sequence
) return Wide_Character_Mapping
;
141 (Map
: Wide_Character_Mapping
) return Wide_Character_Sequence
;
144 (Map
: Wide_Character_Mapping
) return Wide_Character_Sequence
;
146 type Wide_Character_Mapping_Function
is
147 access function (From
: Wide_Character) return Wide_Character;
150 package AF
renames Ada
.Finalization
;
152 ------------------------------------------
153 -- Representation of Wide_Character_Set --
154 ------------------------------------------
156 -- A wide character set is represented as a sequence of wide character
157 -- ranges (i.e. an object of type Wide_Character_Ranges) in which the
160 -- The lower bound is 1
161 -- The ranges are in order by increasing Low values
162 -- The ranges are non-overlapping and discontigous
164 -- A character value is in the set if it is contained in one of the
165 -- ranges. The actual Wide_Character_Set value is a controlled pointer
166 -- to this Wide_Character_Ranges value. The use of a controlled type
167 -- is necessary to prevent storage leaks.
169 type Wide_Character_Ranges_Access
is access all Wide_Character_Ranges
;
171 type Wide_Character_Set
is new AF
.Controlled
with record
172 Set
: Wide_Character_Ranges_Access
;
175 pragma Finalize_Storage_Only
(Wide_Character_Set
);
176 -- This avoids useless finalizations, and, more importantly avoids
177 -- incorrect attempts to finalize constants that are statically
178 -- declared here and in Ada.Strings.Wide_Maps, which is incorrect.
180 overriding
procedure Initialize
(Object
: in out Wide_Character_Set
);
181 overriding
procedure Adjust
(Object
: in out Wide_Character_Set
);
182 overriding
procedure Finalize
(Object
: in out Wide_Character_Set
);
184 Null_Range
: aliased constant Wide_Character_Ranges
:=
185 (1 .. 0 => (Low
=> ' ', High
=> ' '));
187 Null_Set
: constant Wide_Character_Set
:=
189 Set
=> Null_Range
'Unrestricted_Access);
191 ----------------------------------------------
192 -- Representation of Wide_Character_Mapping --
193 ----------------------------------------------
195 -- A wide character mapping is represented as two strings of equal
196 -- length, where any character appearing in Domain is mapped to the
197 -- corresponding character in Rangev. A character not appearing in
198 -- Domain is mapped to itself. The characters in Domain are sorted
199 -- in ascending order.
201 -- The actual Wide_Character_Mapping value is a controlled record
202 -- that contains a pointer to a discriminated record containing the
203 -- range and domain values.
205 -- Note: this representation is canonical, and the values stored in
206 -- Domain and Rangev are exactly the values that are returned by the
207 -- functions To_Domain and To_Range. The use of a controlled type is
208 -- necessary to prevent storage leaks.
210 type Wide_Character_Mapping_Values
(Length
: Natural) is record
211 Domain
: Wide_Character_Sequence
(1 .. Length
);
212 Rangev
: Wide_Character_Sequence
(1 .. Length
);
215 type Wide_Character_Mapping_Values_Access
is
216 access all Wide_Character_Mapping_Values
;
218 type Wide_Character_Mapping
is new AF
.Controlled
with record
219 Map
: Wide_Character_Mapping_Values_Access
;
222 pragma Finalize_Storage_Only
(Wide_Character_Mapping
);
223 -- This avoids useless finalizations, and, more importantly avoids
224 -- incorrect attempts to finalize constants that are statically
225 -- declared here and in Ada.Strings.Wide_Maps, which is incorrect.
227 overriding
procedure Initialize
(Object
: in out Wide_Character_Mapping
);
228 overriding
procedure Adjust
(Object
: in out Wide_Character_Mapping
);
229 overriding
procedure Finalize
(Object
: in out Wide_Character_Mapping
);
231 Null_Map
: aliased constant Wide_Character_Mapping_Values
:=
236 Identity
: constant Wide_Character_Mapping
:=
238 Map
=> Null_Map
'Unrestricted_Access);
240 end Ada
.Strings
.Wide_Maps
;