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-1998 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 2, 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. See the GNU General Public License --
21 -- for more details. You should have received a copy of the GNU General --
22 -- Public License distributed with GNAT; see file COPYING. If not, write --
23 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
24 -- MA 02111-1307, USA. --
26 -- As a special exception, if other files instantiate generics from this --
27 -- unit, or you link this unit with other files to produce an executable, --
28 -- this unit does not by itself cause the resulting executable to be --
29 -- covered by the GNU General Public License. This exception does not --
30 -- however invalidate any other reasons why the executable file might be --
31 -- covered by the GNU Public License. --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
36 ------------------------------------------------------------------------------
38 with Ada.Finalization;
40 package Ada.Strings.Wide_Maps is
41 pragma Preelaborate (Wide_Maps);
43 -------------------------------------
44 -- Wide Character Set Declarations --
45 -------------------------------------
47 type Wide_Character_Set is private;
48 -- Representation for a set of Wide_Character values:
50 Null_Set : constant Wide_Character_Set;
52 ------------------------------------------
53 -- Constructors for Wide Character Sets --
54 ------------------------------------------
56 type Wide_Character_Range is record
58 High : Wide_Character;
60 -- Represents Wide_Character range Low .. High
62 type Wide_Character_Ranges is
63 array (Positive range <>) of Wide_Character_Range;
66 (Ranges : in Wide_Character_Ranges)
67 return Wide_Character_Set;
70 (Span : in Wide_Character_Range)
71 return Wide_Character_Set;
74 (Set : in Wide_Character_Set)
75 return Wide_Character_Ranges;
77 ---------------------------------------
78 -- Operations on Wide Character Sets --
79 ---------------------------------------
81 function "=" (Left, Right : in Wide_Character_Set) return Boolean;
84 (Right : in Wide_Character_Set)
85 return Wide_Character_Set;
88 (Left, Right : in Wide_Character_Set)
89 return Wide_Character_Set;
92 (Left, Right : in Wide_Character_Set)
93 return Wide_Character_Set;
96 (Left, Right : in Wide_Character_Set)
97 return Wide_Character_Set;
100 (Left, Right : in Wide_Character_Set)
101 return Wide_Character_Set;
104 (Element : in Wide_Character;
105 Set : in Wide_Character_Set)
109 (Elements : in Wide_Character_Set;
110 Set : in Wide_Character_Set)
114 (Left : in Wide_Character_Set;
115 Right : in Wide_Character_Set)
119 subtype Wide_Character_Sequence is Wide_String;
120 -- Alternative representation for a set of character values
123 (Sequence : in Wide_Character_Sequence)
124 return Wide_Character_Set;
127 (Singleton : in Wide_Character)
128 return Wide_Character_Set;
131 (Set : in Wide_Character_Set)
132 return Wide_Character_Sequence;
134 -----------------------------------------
135 -- Wide Character Mapping Declarations --
136 -----------------------------------------
138 type Wide_Character_Mapping is private;
139 -- Representation for a wide character to wide character mapping:
142 (Map : in Wide_Character_Mapping;
143 Element : in Wide_Character)
144 return Wide_Character;
146 Identity : constant Wide_Character_Mapping;
148 ---------------------------------
149 -- Operations on Wide Mappings --
150 ---------------------------------
153 (From, To : in Wide_Character_Sequence)
154 return Wide_Character_Mapping;
157 (Map : in Wide_Character_Mapping)
158 return Wide_Character_Sequence;
161 (Map : in Wide_Character_Mapping)
162 return Wide_Character_Sequence;
164 type Wide_Character_Mapping_Function is
165 access function (From : in Wide_Character) return Wide_Character;
168 package AF renames Ada.Finalization;
170 ------------------------------------------
171 -- Representation of Wide_Character_Set --
172 ------------------------------------------
174 -- A wide character set is represented as a sequence of wide character
175 -- ranges (i.e. an object of type Wide_Character_Ranges) in which the
178 -- The lower bound is 1
179 -- The ranges are in order by increasing Low values
180 -- The ranges are non-overlapping and discontigous
182 -- A character value is in the set if it is contained in one of the
183 -- ranges. The actual Wide_Character_Set value is a controlled pointer
184 -- to this Wide_Character_Ranges value. The use of a controlled type
185 -- is necessary to prevent storage leaks.
187 type Wide_Character_Ranges_Access is access all Wide_Character_Ranges;
189 type Wide_Character_Set is new AF.Controlled with record
190 Set : Wide_Character_Ranges_Access;
193 pragma Finalize_Storage_Only (Wide_Character_Set);
194 -- This avoids useless finalizations, and, more importantly avoids
195 -- incorrect attempts to finalize constants that are statically
196 -- declared here and in Ada.Strings.Wide_Maps, which is incorrect.
198 procedure Initialize (Object : in out Wide_Character_Set);
199 procedure Adjust (Object : in out Wide_Character_Set);
200 procedure Finalize (Object : in out Wide_Character_Set);
202 Null_Range : aliased constant Wide_Character_Ranges :=
203 (1 .. 0 => (Low => ' ', High => ' '));
205 Null_Set : constant Wide_Character_Set :=
207 Set => Null_Range'Unrestricted_Access);
209 ----------------------------------------------
210 -- Representation of Wide_Character_Mapping --
211 ----------------------------------------------
213 -- A wide character mapping is represented as two strings of equal
214 -- length, where any character appearing in Domain is mapped to the
215 -- corresponding character in Rangev. A character not appearing in
216 -- Domain is mapped to itself. The characters in Domain are sorted
217 -- in ascending order.
219 -- The actual Wide_Character_Mapping value is a controlled record
220 -- that contains a pointer to a discriminated record containing the
221 -- range and domain values.
223 -- Note: this representation is canonical, and the values stored in
224 -- Domain and Rangev are exactly the values that are returned by the
225 -- functions To_Domain and To_Range. The use of a controlled type is
226 -- necessary to prevent storage leaks.
228 type Wide_Character_Mapping_Values (Length : Natural) is record
229 Domain : Wide_Character_Sequence (1 .. Length);
230 Rangev : Wide_Character_Sequence (1 .. Length);
233 type Wide_Character_Mapping_Values_Access is
234 access all Wide_Character_Mapping_Values;
236 type Wide_Character_Mapping is new AF.Controlled with record
237 Map : Wide_Character_Mapping_Values_Access;
240 pragma Finalize_Storage_Only (Wide_Character_Mapping);
241 -- This avoids useless finalizations, and, more importantly avoids
242 -- incorrect attempts to finalize constants that are statically
243 -- declared here and in Ada.Strings.Wide_Maps, which is incorrect.
245 procedure Initialize (Object : in out Wide_Character_Mapping);
246 procedure Adjust (Object : in out Wide_Character_Mapping);
247 procedure Finalize (Object : in out Wide_Character_Mapping);
249 Null_Map : aliased constant Wide_Character_Mapping_Values :=
254 Identity : constant Wide_Character_Mapping :=
256 Map => Null_Map'Unrestricted_Access);
258 end Ada.Strings.Wide_Maps;