1 |
706 |
jeremybenn |
------------------------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-- GNAT RUN-TIME COMPONENTS --
|
4 |
|
|
-- --
|
5 |
|
|
-- A D A . S T R I N G S . W I D E _ U N B O U N D E D --
|
6 |
|
|
-- --
|
7 |
|
|
-- S p e c --
|
8 |
|
|
-- --
|
9 |
|
|
-- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
|
10 |
|
|
-- --
|
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. --
|
14 |
|
|
-- --
|
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. --
|
21 |
|
|
-- --
|
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. --
|
25 |
|
|
-- --
|
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/>. --
|
30 |
|
|
-- --
|
31 |
|
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
32 |
|
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
33 |
|
|
-- --
|
34 |
|
|
------------------------------------------------------------------------------
|
35 |
|
|
|
36 |
|
|
with Ada.Strings.Wide_Maps;
|
37 |
|
|
with Ada.Finalization;
|
38 |
|
|
|
39 |
|
|
package Ada.Strings.Wide_Unbounded is
|
40 |
|
|
pragma Preelaborate;
|
41 |
|
|
|
42 |
|
|
type Unbounded_Wide_String is private;
|
43 |
|
|
pragma Preelaborable_Initialization (Unbounded_Wide_String);
|
44 |
|
|
|
45 |
|
|
Null_Unbounded_Wide_String : constant Unbounded_Wide_String;
|
46 |
|
|
|
47 |
|
|
function Length (Source : Unbounded_Wide_String) return Natural;
|
48 |
|
|
|
49 |
|
|
type Wide_String_Access is access all Wide_String;
|
50 |
|
|
|
51 |
|
|
procedure Free (X : in out Wide_String_Access);
|
52 |
|
|
|
53 |
|
|
--------------------------------------------------------
|
54 |
|
|
-- Conversion, Concatenation, and Selection Functions --
|
55 |
|
|
--------------------------------------------------------
|
56 |
|
|
|
57 |
|
|
function To_Unbounded_Wide_String
|
58 |
|
|
(Source : Wide_String) return Unbounded_Wide_String;
|
59 |
|
|
|
60 |
|
|
function To_Unbounded_Wide_String
|
61 |
|
|
(Length : Natural) return Unbounded_Wide_String;
|
62 |
|
|
|
63 |
|
|
function To_Wide_String
|
64 |
|
|
(Source : Unbounded_Wide_String)
|
65 |
|
|
return Wide_String;
|
66 |
|
|
|
67 |
|
|
procedure Set_Unbounded_Wide_String
|
68 |
|
|
(Target : out Unbounded_Wide_String;
|
69 |
|
|
Source : Wide_String);
|
70 |
|
|
pragma Ada_05 (Set_Unbounded_Wide_String);
|
71 |
|
|
|
72 |
|
|
procedure Append
|
73 |
|
|
(Source : in out Unbounded_Wide_String;
|
74 |
|
|
New_Item : Unbounded_Wide_String);
|
75 |
|
|
|
76 |
|
|
procedure Append
|
77 |
|
|
(Source : in out Unbounded_Wide_String;
|
78 |
|
|
New_Item : Wide_String);
|
79 |
|
|
|
80 |
|
|
procedure Append
|
81 |
|
|
(Source : in out Unbounded_Wide_String;
|
82 |
|
|
New_Item : Wide_Character);
|
83 |
|
|
|
84 |
|
|
function "&"
|
85 |
|
|
(Left : Unbounded_Wide_String;
|
86 |
|
|
Right : Unbounded_Wide_String) return Unbounded_Wide_String;
|
87 |
|
|
|
88 |
|
|
function "&"
|
89 |
|
|
(Left : Unbounded_Wide_String;
|
90 |
|
|
Right : Wide_String) return Unbounded_Wide_String;
|
91 |
|
|
|
92 |
|
|
function "&"
|
93 |
|
|
(Left : Wide_String;
|
94 |
|
|
Right : Unbounded_Wide_String) return Unbounded_Wide_String;
|
95 |
|
|
|
96 |
|
|
function "&"
|
97 |
|
|
(Left : Unbounded_Wide_String;
|
98 |
|
|
Right : Wide_Character) return Unbounded_Wide_String;
|
99 |
|
|
|
100 |
|
|
function "&"
|
101 |
|
|
(Left : Wide_Character;
|
102 |
|
|
Right : Unbounded_Wide_String) return Unbounded_Wide_String;
|
103 |
|
|
|
104 |
|
|
function Element
|
105 |
|
|
(Source : Unbounded_Wide_String;
|
106 |
|
|
Index : Positive) return Wide_Character;
|
107 |
|
|
|
108 |
|
|
procedure Replace_Element
|
109 |
|
|
(Source : in out Unbounded_Wide_String;
|
110 |
|
|
Index : Positive;
|
111 |
|
|
By : Wide_Character);
|
112 |
|
|
|
113 |
|
|
function Slice
|
114 |
|
|
(Source : Unbounded_Wide_String;
|
115 |
|
|
Low : Positive;
|
116 |
|
|
High : Natural) return Wide_String;
|
117 |
|
|
|
118 |
|
|
function Unbounded_Slice
|
119 |
|
|
(Source : Unbounded_Wide_String;
|
120 |
|
|
Low : Positive;
|
121 |
|
|
High : Natural) return Unbounded_Wide_String;
|
122 |
|
|
pragma Ada_05 (Unbounded_Slice);
|
123 |
|
|
|
124 |
|
|
procedure Unbounded_Slice
|
125 |
|
|
(Source : Unbounded_Wide_String;
|
126 |
|
|
Target : out Unbounded_Wide_String;
|
127 |
|
|
Low : Positive;
|
128 |
|
|
High : Natural);
|
129 |
|
|
pragma Ada_05 (Unbounded_Slice);
|
130 |
|
|
|
131 |
|
|
function "="
|
132 |
|
|
(Left : Unbounded_Wide_String;
|
133 |
|
|
Right : Unbounded_Wide_String) return Boolean;
|
134 |
|
|
|
135 |
|
|
function "="
|
136 |
|
|
(Left : Unbounded_Wide_String;
|
137 |
|
|
Right : Wide_String) return Boolean;
|
138 |
|
|
|
139 |
|
|
function "="
|
140 |
|
|
(Left : Wide_String;
|
141 |
|
|
Right : Unbounded_Wide_String) return Boolean;
|
142 |
|
|
|
143 |
|
|
function "<"
|
144 |
|
|
(Left : Unbounded_Wide_String;
|
145 |
|
|
Right : Unbounded_Wide_String) return Boolean;
|
146 |
|
|
|
147 |
|
|
function "<"
|
148 |
|
|
(Left : Unbounded_Wide_String;
|
149 |
|
|
Right : Wide_String) return Boolean;
|
150 |
|
|
|
151 |
|
|
function "<"
|
152 |
|
|
(Left : Wide_String;
|
153 |
|
|
Right : Unbounded_Wide_String) return Boolean;
|
154 |
|
|
|
155 |
|
|
function "<="
|
156 |
|
|
(Left : Unbounded_Wide_String;
|
157 |
|
|
Right : Unbounded_Wide_String) return Boolean;
|
158 |
|
|
|
159 |
|
|
function "<="
|
160 |
|
|
(Left : Unbounded_Wide_String;
|
161 |
|
|
Right : Wide_String) return Boolean;
|
162 |
|
|
|
163 |
|
|
function "<="
|
164 |
|
|
(Left : Wide_String;
|
165 |
|
|
Right : Unbounded_Wide_String) return Boolean;
|
166 |
|
|
|
167 |
|
|
function ">"
|
168 |
|
|
(Left : Unbounded_Wide_String;
|
169 |
|
|
Right : Unbounded_Wide_String) return Boolean;
|
170 |
|
|
|
171 |
|
|
function ">"
|
172 |
|
|
(Left : Unbounded_Wide_String;
|
173 |
|
|
Right : Wide_String) return Boolean;
|
174 |
|
|
|
175 |
|
|
function ">"
|
176 |
|
|
(Left : Wide_String;
|
177 |
|
|
Right : Unbounded_Wide_String) return Boolean;
|
178 |
|
|
|
179 |
|
|
function ">="
|
180 |
|
|
(Left : Unbounded_Wide_String;
|
181 |
|
|
Right : Unbounded_Wide_String) return Boolean;
|
182 |
|
|
|
183 |
|
|
function ">="
|
184 |
|
|
(Left : Unbounded_Wide_String;
|
185 |
|
|
Right : Wide_String) return Boolean;
|
186 |
|
|
|
187 |
|
|
function ">="
|
188 |
|
|
(Left : Wide_String;
|
189 |
|
|
Right : Unbounded_Wide_String) return Boolean;
|
190 |
|
|
|
191 |
|
|
------------------------
|
192 |
|
|
-- Search Subprograms --
|
193 |
|
|
------------------------
|
194 |
|
|
|
195 |
|
|
function Index
|
196 |
|
|
(Source : Unbounded_Wide_String;
|
197 |
|
|
Pattern : Wide_String;
|
198 |
|
|
Going : Direction := Forward;
|
199 |
|
|
Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
|
200 |
|
|
return Natural;
|
201 |
|
|
|
202 |
|
|
function Index
|
203 |
|
|
(Source : Unbounded_Wide_String;
|
204 |
|
|
Pattern : Wide_String;
|
205 |
|
|
Going : Direction := Forward;
|
206 |
|
|
Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural;
|
207 |
|
|
|
208 |
|
|
function Index
|
209 |
|
|
(Source : Unbounded_Wide_String;
|
210 |
|
|
Set : Wide_Maps.Wide_Character_Set;
|
211 |
|
|
Test : Membership := Inside;
|
212 |
|
|
Going : Direction := Forward) return Natural;
|
213 |
|
|
|
214 |
|
|
function Index
|
215 |
|
|
(Source : Unbounded_Wide_String;
|
216 |
|
|
Pattern : Wide_String;
|
217 |
|
|
From : Positive;
|
218 |
|
|
Going : Direction := Forward;
|
219 |
|
|
Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
|
220 |
|
|
return Natural;
|
221 |
|
|
pragma Ada_05 (Index);
|
222 |
|
|
|
223 |
|
|
function Index
|
224 |
|
|
(Source : Unbounded_Wide_String;
|
225 |
|
|
Pattern : Wide_String;
|
226 |
|
|
From : Positive;
|
227 |
|
|
Going : Direction := Forward;
|
228 |
|
|
Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural;
|
229 |
|
|
pragma Ada_05 (Index);
|
230 |
|
|
|
231 |
|
|
function Index
|
232 |
|
|
(Source : Unbounded_Wide_String;
|
233 |
|
|
Set : Wide_Maps.Wide_Character_Set;
|
234 |
|
|
From : Positive;
|
235 |
|
|
Test : Membership := Inside;
|
236 |
|
|
Going : Direction := Forward) return Natural;
|
237 |
|
|
pragma Ada_05 (Index);
|
238 |
|
|
|
239 |
|
|
function Index_Non_Blank
|
240 |
|
|
(Source : Unbounded_Wide_String;
|
241 |
|
|
Going : Direction := Forward) return Natural;
|
242 |
|
|
|
243 |
|
|
function Index_Non_Blank
|
244 |
|
|
(Source : Unbounded_Wide_String;
|
245 |
|
|
From : Positive;
|
246 |
|
|
Going : Direction := Forward) return Natural;
|
247 |
|
|
pragma Ada_05 (Index_Non_Blank);
|
248 |
|
|
|
249 |
|
|
function Count
|
250 |
|
|
(Source : Unbounded_Wide_String;
|
251 |
|
|
Pattern : Wide_String;
|
252 |
|
|
Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
|
253 |
|
|
return Natural;
|
254 |
|
|
|
255 |
|
|
function Count
|
256 |
|
|
(Source : Unbounded_Wide_String;
|
257 |
|
|
Pattern : Wide_String;
|
258 |
|
|
Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural;
|
259 |
|
|
|
260 |
|
|
function Count
|
261 |
|
|
(Source : Unbounded_Wide_String;
|
262 |
|
|
Set : Wide_Maps.Wide_Character_Set) return Natural;
|
263 |
|
|
|
264 |
|
|
procedure Find_Token
|
265 |
|
|
(Source : Unbounded_Wide_String;
|
266 |
|
|
Set : Wide_Maps.Wide_Character_Set;
|
267 |
|
|
From : Positive;
|
268 |
|
|
Test : Membership;
|
269 |
|
|
First : out Positive;
|
270 |
|
|
Last : out Natural);
|
271 |
|
|
pragma Ada_2012 (Find_Token);
|
272 |
|
|
|
273 |
|
|
procedure Find_Token
|
274 |
|
|
(Source : Unbounded_Wide_String;
|
275 |
|
|
Set : Wide_Maps.Wide_Character_Set;
|
276 |
|
|
Test : Membership;
|
277 |
|
|
First : out Positive;
|
278 |
|
|
Last : out Natural);
|
279 |
|
|
|
280 |
|
|
------------------------------------
|
281 |
|
|
-- String Translation Subprograms --
|
282 |
|
|
------------------------------------
|
283 |
|
|
|
284 |
|
|
function Translate
|
285 |
|
|
(Source : Unbounded_Wide_String;
|
286 |
|
|
Mapping : Wide_Maps.Wide_Character_Mapping)
|
287 |
|
|
return Unbounded_Wide_String;
|
288 |
|
|
|
289 |
|
|
procedure Translate
|
290 |
|
|
(Source : in out Unbounded_Wide_String;
|
291 |
|
|
Mapping : Wide_Maps.Wide_Character_Mapping);
|
292 |
|
|
|
293 |
|
|
function Translate
|
294 |
|
|
(Source : Unbounded_Wide_String;
|
295 |
|
|
Mapping : Wide_Maps.Wide_Character_Mapping_Function)
|
296 |
|
|
return Unbounded_Wide_String;
|
297 |
|
|
|
298 |
|
|
procedure Translate
|
299 |
|
|
(Source : in out Unbounded_Wide_String;
|
300 |
|
|
Mapping : Wide_Maps.Wide_Character_Mapping_Function);
|
301 |
|
|
|
302 |
|
|
---------------------------------------
|
303 |
|
|
-- String Transformation Subprograms --
|
304 |
|
|
---------------------------------------
|
305 |
|
|
|
306 |
|
|
function Replace_Slice
|
307 |
|
|
(Source : Unbounded_Wide_String;
|
308 |
|
|
Low : Positive;
|
309 |
|
|
High : Natural;
|
310 |
|
|
By : Wide_String) return Unbounded_Wide_String;
|
311 |
|
|
|
312 |
|
|
procedure Replace_Slice
|
313 |
|
|
(Source : in out Unbounded_Wide_String;
|
314 |
|
|
Low : Positive;
|
315 |
|
|
High : Natural;
|
316 |
|
|
By : Wide_String);
|
317 |
|
|
|
318 |
|
|
function Insert
|
319 |
|
|
(Source : Unbounded_Wide_String;
|
320 |
|
|
Before : Positive;
|
321 |
|
|
New_Item : Wide_String) return Unbounded_Wide_String;
|
322 |
|
|
|
323 |
|
|
procedure Insert
|
324 |
|
|
(Source : in out Unbounded_Wide_String;
|
325 |
|
|
Before : Positive;
|
326 |
|
|
New_Item : Wide_String);
|
327 |
|
|
|
328 |
|
|
function Overwrite
|
329 |
|
|
(Source : Unbounded_Wide_String;
|
330 |
|
|
Position : Positive;
|
331 |
|
|
New_Item : Wide_String) return Unbounded_Wide_String;
|
332 |
|
|
|
333 |
|
|
procedure Overwrite
|
334 |
|
|
(Source : in out Unbounded_Wide_String;
|
335 |
|
|
Position : Positive;
|
336 |
|
|
New_Item : Wide_String);
|
337 |
|
|
|
338 |
|
|
function Delete
|
339 |
|
|
(Source : Unbounded_Wide_String;
|
340 |
|
|
From : Positive;
|
341 |
|
|
Through : Natural) return Unbounded_Wide_String;
|
342 |
|
|
|
343 |
|
|
procedure Delete
|
344 |
|
|
(Source : in out Unbounded_Wide_String;
|
345 |
|
|
From : Positive;
|
346 |
|
|
Through : Natural);
|
347 |
|
|
|
348 |
|
|
function Trim
|
349 |
|
|
(Source : Unbounded_Wide_String;
|
350 |
|
|
Side : Trim_End) return Unbounded_Wide_String;
|
351 |
|
|
|
352 |
|
|
procedure Trim
|
353 |
|
|
(Source : in out Unbounded_Wide_String;
|
354 |
|
|
Side : Trim_End);
|
355 |
|
|
|
356 |
|
|
function Trim
|
357 |
|
|
(Source : Unbounded_Wide_String;
|
358 |
|
|
Left : Wide_Maps.Wide_Character_Set;
|
359 |
|
|
Right : Wide_Maps.Wide_Character_Set) return Unbounded_Wide_String;
|
360 |
|
|
|
361 |
|
|
procedure Trim
|
362 |
|
|
(Source : in out Unbounded_Wide_String;
|
363 |
|
|
Left : Wide_Maps.Wide_Character_Set;
|
364 |
|
|
Right : Wide_Maps.Wide_Character_Set);
|
365 |
|
|
|
366 |
|
|
function Head
|
367 |
|
|
(Source : Unbounded_Wide_String;
|
368 |
|
|
Count : Natural;
|
369 |
|
|
Pad : Wide_Character := Wide_Space) return Unbounded_Wide_String;
|
370 |
|
|
|
371 |
|
|
procedure Head
|
372 |
|
|
(Source : in out Unbounded_Wide_String;
|
373 |
|
|
Count : Natural;
|
374 |
|
|
Pad : Wide_Character := Wide_Space);
|
375 |
|
|
|
376 |
|
|
function Tail
|
377 |
|
|
(Source : Unbounded_Wide_String;
|
378 |
|
|
Count : Natural;
|
379 |
|
|
Pad : Wide_Character := Wide_Space) return Unbounded_Wide_String;
|
380 |
|
|
|
381 |
|
|
procedure Tail
|
382 |
|
|
(Source : in out Unbounded_Wide_String;
|
383 |
|
|
Count : Natural;
|
384 |
|
|
Pad : Wide_Character := Wide_Space);
|
385 |
|
|
|
386 |
|
|
function "*"
|
387 |
|
|
(Left : Natural;
|
388 |
|
|
Right : Wide_Character) return Unbounded_Wide_String;
|
389 |
|
|
|
390 |
|
|
function "*"
|
391 |
|
|
(Left : Natural;
|
392 |
|
|
Right : Wide_String) return Unbounded_Wide_String;
|
393 |
|
|
|
394 |
|
|
function "*"
|
395 |
|
|
(Left : Natural;
|
396 |
|
|
Right : Unbounded_Wide_String) return Unbounded_Wide_String;
|
397 |
|
|
|
398 |
|
|
private
|
399 |
|
|
pragma Inline (Length);
|
400 |
|
|
|
401 |
|
|
package AF renames Ada.Finalization;
|
402 |
|
|
|
403 |
|
|
Null_Wide_String : aliased Wide_String := "";
|
404 |
|
|
|
405 |
|
|
function To_Unbounded_Wide (S : Wide_String) return Unbounded_Wide_String
|
406 |
|
|
renames To_Unbounded_Wide_String;
|
407 |
|
|
|
408 |
|
|
type Unbounded_Wide_String is new AF.Controlled with record
|
409 |
|
|
Reference : Wide_String_Access := Null_Wide_String'Access;
|
410 |
|
|
Last : Natural := 0;
|
411 |
|
|
end record;
|
412 |
|
|
|
413 |
|
|
-- The Unbounded_Wide_String is using a buffered implementation to increase
|
414 |
|
|
-- speed of the Append/Delete/Insert procedures. The Reference string
|
415 |
|
|
-- pointer above contains the current string value and extra room at the
|
416 |
|
|
-- end to be used by the next Append routine. Last is the index of the
|
417 |
|
|
-- string ending character. So the current string value is really
|
418 |
|
|
-- Reference (1 .. Last).
|
419 |
|
|
|
420 |
|
|
pragma Stream_Convert
|
421 |
|
|
(Unbounded_Wide_String, To_Unbounded_Wide, To_Wide_String);
|
422 |
|
|
|
423 |
|
|
pragma Finalize_Storage_Only (Unbounded_Wide_String);
|
424 |
|
|
-- Finalization is required only for freeing storage
|
425 |
|
|
|
426 |
|
|
procedure Initialize (Object : in out Unbounded_Wide_String);
|
427 |
|
|
procedure Adjust (Object : in out Unbounded_Wide_String);
|
428 |
|
|
procedure Finalize (Object : in out Unbounded_Wide_String);
|
429 |
|
|
|
430 |
|
|
procedure Realloc_For_Chunk
|
431 |
|
|
(Source : in out Unbounded_Wide_String;
|
432 |
|
|
Chunk_Size : Natural);
|
433 |
|
|
-- Adjust the size allocated for the string. Add at least Chunk_Size so it
|
434 |
|
|
-- is safe to add a string of this size at the end of the current content.
|
435 |
|
|
-- The real size allocated for the string is Chunk_Size + x of the current
|
436 |
|
|
-- string size. This buffered handling makes the Append unbounded string
|
437 |
|
|
-- routines very fast.
|
438 |
|
|
|
439 |
|
|
Null_Unbounded_Wide_String : constant Unbounded_Wide_String :=
|
440 |
|
|
(AF.Controlled with
|
441 |
|
|
Reference => Null_Wide_String'Access,
|
442 |
|
|
Last => 0);
|
443 |
|
|
end Ada.Strings.Wide_Unbounded;
|