1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . S T R I N G S . W I D E _ W I D E _ U N B O U N D E D --
9 -- Copyright (C) 1992-2005, 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, 51 Franklin Street, Fifth Floor, --
24 -- Boston, MA 02110-1301, 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
.Strings
.Wide_Wide_Maps
;
39 with Ada
.Finalization
;
41 package Ada
.Strings
.Wide_Wide_Unbounded
is
44 type Unbounded_Wide_Wide_String
is private;
46 Null_Unbounded_Wide_Wide_String
: constant Unbounded_Wide_Wide_String
;
48 function Length
(Source
: Unbounded_Wide_Wide_String
) return Natural;
50 type Wide_Wide_String_Access
is access all Wide_Wide_String
;
52 procedure Free
(X
: in out Wide_Wide_String_Access
);
54 --------------------------------------------------------
55 -- Conversion, Concatenation, and Selection Functions --
56 --------------------------------------------------------
58 function To_Unbounded_Wide_Wide_String
59 (Source
: Wide_Wide_String
) return Unbounded_Wide_Wide_String
;
61 function To_Unbounded_Wide_Wide_String
62 (Length
: Natural) return Unbounded_Wide_Wide_String
;
64 function To_Wide_Wide_String
65 (Source
: Unbounded_Wide_Wide_String
) return Wide_Wide_String
;
67 procedure Set_Unbounded_Wide_Wide_String
68 (Target
: out Unbounded_Wide_Wide_String
;
69 Source
: Wide_Wide_String
);
70 pragma Ada_05
(Set_Unbounded_Wide_Wide_String
);
73 (Source
: in out Unbounded_Wide_Wide_String
;
74 New_Item
: Unbounded_Wide_Wide_String
);
77 (Source
: in out Unbounded_Wide_Wide_String
;
78 New_Item
: Wide_Wide_String
);
81 (Source
: in out Unbounded_Wide_Wide_String
;
82 New_Item
: Wide_Wide_Character
);
85 (Left
: Unbounded_Wide_Wide_String
;
86 Right
: Unbounded_Wide_Wide_String
) return Unbounded_Wide_Wide_String
;
89 (Left
: Unbounded_Wide_Wide_String
;
90 Right
: Wide_Wide_String
) return Unbounded_Wide_Wide_String
;
93 (Left
: Wide_Wide_String
;
94 Right
: Unbounded_Wide_Wide_String
) return Unbounded_Wide_Wide_String
;
97 (Left
: Unbounded_Wide_Wide_String
;
98 Right
: Wide_Wide_Character
) return Unbounded_Wide_Wide_String
;
101 (Left
: Wide_Wide_Character
;
102 Right
: Unbounded_Wide_Wide_String
) return Unbounded_Wide_Wide_String
;
105 (Source
: Unbounded_Wide_Wide_String
;
106 Index
: Positive) return Wide_Wide_Character
;
108 procedure Replace_Element
109 (Source
: in out Unbounded_Wide_Wide_String
;
111 By
: Wide_Wide_Character
);
114 (Source
: Unbounded_Wide_Wide_String
;
116 High
: Natural) return Wide_Wide_String
;
118 function Unbounded_Slice
119 (Source
: Unbounded_Wide_Wide_String
;
121 High
: Natural) return Unbounded_Wide_Wide_String
;
122 pragma Ada_05
(Unbounded_Slice
);
124 procedure Unbounded_Slice
125 (Source
: Unbounded_Wide_Wide_String
;
126 Target
: out Unbounded_Wide_Wide_String
;
129 pragma Ada_05
(Unbounded_Slice
);
132 (Left
: Unbounded_Wide_Wide_String
;
133 Right
: Unbounded_Wide_Wide_String
) return Boolean;
136 (Left
: Unbounded_Wide_Wide_String
;
137 Right
: Wide_Wide_String
) return Boolean;
140 (Left
: Wide_Wide_String
;
141 Right
: Unbounded_Wide_Wide_String
) return Boolean;
144 (Left
: Unbounded_Wide_Wide_String
;
145 Right
: Unbounded_Wide_Wide_String
) return Boolean;
148 (Left
: Unbounded_Wide_Wide_String
;
149 Right
: Wide_Wide_String
) return Boolean;
152 (Left
: Wide_Wide_String
;
153 Right
: Unbounded_Wide_Wide_String
) return Boolean;
156 (Left
: Unbounded_Wide_Wide_String
;
157 Right
: Unbounded_Wide_Wide_String
) return Boolean;
160 (Left
: Unbounded_Wide_Wide_String
;
161 Right
: Wide_Wide_String
) return Boolean;
164 (Left
: Wide_Wide_String
;
165 Right
: Unbounded_Wide_Wide_String
) return Boolean;
168 (Left
: Unbounded_Wide_Wide_String
;
169 Right
: Unbounded_Wide_Wide_String
) return Boolean;
172 (Left
: Unbounded_Wide_Wide_String
;
173 Right
: Wide_Wide_String
) return Boolean;
176 (Left
: Wide_Wide_String
;
177 Right
: Unbounded_Wide_Wide_String
) return Boolean;
180 (Left
: Unbounded_Wide_Wide_String
;
181 Right
: Unbounded_Wide_Wide_String
) return Boolean;
184 (Left
: Unbounded_Wide_Wide_String
;
185 Right
: Wide_Wide_String
) return Boolean;
188 (Left
: Wide_Wide_String
;
189 Right
: Unbounded_Wide_Wide_String
) return Boolean;
191 ------------------------
192 -- Search Subprograms --
193 ------------------------
196 (Source
: Unbounded_Wide_Wide_String
;
197 Pattern
: Wide_Wide_String
;
198 Going
: Direction
:= Forward
;
199 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
200 Wide_Wide_Maps
.Identity
)
204 (Source
: Unbounded_Wide_Wide_String
;
205 Pattern
: Wide_Wide_String
;
206 Going
: Direction
:= Forward
;
207 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
211 (Source
: Unbounded_Wide_Wide_String
;
212 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
213 Test
: Membership
:= Inside
;
214 Going
: Direction
:= Forward
) return Natural;
217 (Source
: Unbounded_Wide_Wide_String
;
218 Pattern
: Wide_Wide_String
;
220 Going
: Direction
:= Forward
;
221 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
222 Wide_Wide_Maps
.Identity
)
224 pragma Ada_05
(Index
);
227 (Source
: Unbounded_Wide_Wide_String
;
228 Pattern
: Wide_Wide_String
;
230 Going
: Direction
:= Forward
;
231 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
233 pragma Ada_05
(Index
);
236 (Source
: Unbounded_Wide_Wide_String
;
237 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
239 Test
: Membership
:= Inside
;
240 Going
: Direction
:= Forward
) return Natural;
241 pragma Ada_05
(Index
);
243 function Index_Non_Blank
244 (Source
: Unbounded_Wide_Wide_String
;
245 Going
: Direction
:= Forward
) return Natural;
247 function Index_Non_Blank
248 (Source
: Unbounded_Wide_Wide_String
;
250 Going
: Direction
:= Forward
) return Natural;
251 pragma Ada_05
(Index_Non_Blank
);
254 (Source
: Unbounded_Wide_Wide_String
;
255 Pattern
: Wide_Wide_String
;
256 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
257 Wide_Wide_Maps
.Identity
)
261 (Source
: Unbounded_Wide_Wide_String
;
262 Pattern
: Wide_Wide_String
;
263 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
267 (Source
: Unbounded_Wide_Wide_String
;
268 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
) return Natural;
271 (Source
: Unbounded_Wide_Wide_String
;
272 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
274 First
: out Positive;
277 ------------------------------------
278 -- String Translation Subprograms --
279 ------------------------------------
282 (Source
: Unbounded_Wide_Wide_String
;
283 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
)
284 return Unbounded_Wide_Wide_String
;
287 (Source
: in out Unbounded_Wide_Wide_String
;
288 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
);
291 (Source
: Unbounded_Wide_Wide_String
;
292 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
293 return Unbounded_Wide_Wide_String
;
296 (Source
: in out Unbounded_Wide_Wide_String
;
297 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
);
299 ---------------------------------------
300 -- String Transformation Subprograms --
301 ---------------------------------------
303 function Replace_Slice
304 (Source
: Unbounded_Wide_Wide_String
;
307 By
: Wide_Wide_String
) return Unbounded_Wide_Wide_String
;
309 procedure Replace_Slice
310 (Source
: in out Unbounded_Wide_Wide_String
;
313 By
: Wide_Wide_String
);
316 (Source
: Unbounded_Wide_Wide_String
;
318 New_Item
: Wide_Wide_String
) return Unbounded_Wide_Wide_String
;
321 (Source
: in out Unbounded_Wide_Wide_String
;
323 New_Item
: Wide_Wide_String
);
326 (Source
: Unbounded_Wide_Wide_String
;
328 New_Item
: Wide_Wide_String
) return Unbounded_Wide_Wide_String
;
331 (Source
: in out Unbounded_Wide_Wide_String
;
333 New_Item
: Wide_Wide_String
);
336 (Source
: Unbounded_Wide_Wide_String
;
338 Through
: Natural) return Unbounded_Wide_Wide_String
;
341 (Source
: in out Unbounded_Wide_Wide_String
;
346 (Source
: Unbounded_Wide_Wide_String
;
347 Side
: Trim_End
) return Unbounded_Wide_Wide_String
;
350 (Source
: in out Unbounded_Wide_Wide_String
;
354 (Source
: Unbounded_Wide_Wide_String
;
355 Left
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
356 Right
: Wide_Wide_Maps
.Wide_Wide_Character_Set
)
357 return Unbounded_Wide_Wide_String
;
360 (Source
: in out Unbounded_Wide_Wide_String
;
361 Left
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
362 Right
: Wide_Wide_Maps
.Wide_Wide_Character_Set
);
365 (Source
: Unbounded_Wide_Wide_String
;
367 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
)
368 return Unbounded_Wide_Wide_String
;
371 (Source
: in out Unbounded_Wide_Wide_String
;
373 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
);
376 (Source
: Unbounded_Wide_Wide_String
;
378 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
)
379 return Unbounded_Wide_Wide_String
;
382 (Source
: in out Unbounded_Wide_Wide_String
;
384 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
);
388 Right
: Wide_Wide_Character
) return Unbounded_Wide_Wide_String
;
392 Right
: Wide_Wide_String
) return Unbounded_Wide_Wide_String
;
396 Right
: Unbounded_Wide_Wide_String
) return Unbounded_Wide_Wide_String
;
399 pragma Inline
(Length
);
401 package AF
renames Ada
.Finalization
;
403 Null_Wide_Wide_String
: aliased Wide_Wide_String
:= "";
405 function To_Unbounded_Wide
406 (S
: Wide_Wide_String
) return Unbounded_Wide_Wide_String
407 renames To_Unbounded_Wide_Wide_String
;
409 type Unbounded_Wide_Wide_String
is new AF
.Controlled
with record
410 Reference
: Wide_Wide_String_Access
:= Null_Wide_Wide_String
'Access;
414 -- The Unbounded_Wide_Wide_String is using a buffered implementation to
415 -- increase speed of the Append/Delete/Insert procedures. The Reference
416 -- string pointer above contains the current string value and extra room
417 -- at the end to be used by the next Append routine. Last is the index of
418 -- the string ending character. So the current string value is really
419 -- Reference (1 .. Last).
421 pragma Stream_Convert
422 (Unbounded_Wide_Wide_String
, To_Unbounded_Wide
, To_Wide_Wide_String
);
424 pragma Finalize_Storage_Only
(Unbounded_Wide_Wide_String
);
425 -- Finalization is required only for freeing storage
427 procedure Initialize
(Object
: in out Unbounded_Wide_Wide_String
);
428 procedure Adjust
(Object
: in out Unbounded_Wide_Wide_String
);
429 procedure Finalize
(Object
: in out Unbounded_Wide_Wide_String
);
430 procedure Realloc_For_Chunk
431 (Source
: in out Unbounded_Wide_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.
439 Null_Unbounded_Wide_Wide_String
: constant Unbounded_Wide_Wide_String
:=
442 Null_Wide_Wide_String
'Access,
444 -- Note: this declaration is illegal since library level controlled
445 -- objects are not allowed in preelaborated units. See AI-161 for a
446 -- discussion of this issue and an attempt to address it. Meanwhile,
447 -- what happens in GNAT is that this check is omitted for internal
448 -- implementation units (see check in sem_cat.adb).
450 end Ada
.Strings
.Wide_Wide_Unbounded
;