1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . S T R I N G S . 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_Maps
;
39 with Ada
.Finalization
;
41 package Ada
.Strings
.Wide_Unbounded
is
44 type Unbounded_Wide_String
is private;
46 Null_Unbounded_Wide_String
: constant Unbounded_Wide_String
;
48 function Length
(Source
: Unbounded_Wide_String
) return Natural;
50 type Wide_String_Access
is access all Wide_String;
52 procedure Free
(X
: in out Wide_String_Access
);
54 --------------------------------------------------------
55 -- Conversion, Concatenation, and Selection Functions --
56 --------------------------------------------------------
58 function To_Unbounded_Wide_String
59 (Source
: Wide_String) return Unbounded_Wide_String
;
61 function To_Unbounded_Wide_String
62 (Length
: Natural) return Unbounded_Wide_String
;
64 function To_Wide_String
65 (Source
: Unbounded_Wide_String
)
68 procedure Set_Unbounded_Wide_String
69 (Target
: out Unbounded_Wide_String
;
70 Source
: Wide_String);
71 pragma Ada_05
(Set_Unbounded_Wide_String
);
74 (Source
: in out Unbounded_Wide_String
;
75 New_Item
: Unbounded_Wide_String
);
78 (Source
: in out Unbounded_Wide_String
;
79 New_Item
: Wide_String);
82 (Source
: in out Unbounded_Wide_String
;
83 New_Item
: Wide_Character);
86 (Left
: Unbounded_Wide_String
;
87 Right
: Unbounded_Wide_String
) return Unbounded_Wide_String
;
90 (Left
: Unbounded_Wide_String
;
91 Right
: Wide_String) return Unbounded_Wide_String
;
95 Right
: Unbounded_Wide_String
) return Unbounded_Wide_String
;
98 (Left
: Unbounded_Wide_String
;
99 Right
: Wide_Character) return Unbounded_Wide_String
;
102 (Left
: Wide_Character;
103 Right
: Unbounded_Wide_String
) return Unbounded_Wide_String
;
106 (Source
: Unbounded_Wide_String
;
107 Index
: Positive) return Wide_Character;
109 procedure Replace_Element
110 (Source
: in out Unbounded_Wide_String
;
112 By
: Wide_Character);
115 (Source
: Unbounded_Wide_String
;
117 High
: Natural) return Wide_String;
119 function Unbounded_Slice
120 (Source
: Unbounded_Wide_String
;
122 High
: Natural) return Unbounded_Wide_String
;
123 pragma Ada_05
(Unbounded_Slice
);
125 procedure Unbounded_Slice
126 (Source
: Unbounded_Wide_String
;
127 Target
: out Unbounded_Wide_String
;
130 pragma Ada_05
(Unbounded_Slice
);
133 (Left
: Unbounded_Wide_String
;
134 Right
: Unbounded_Wide_String
) return Boolean;
137 (Left
: Unbounded_Wide_String
;
138 Right
: Wide_String) return Boolean;
142 Right
: Unbounded_Wide_String
) return Boolean;
145 (Left
: Unbounded_Wide_String
;
146 Right
: Unbounded_Wide_String
) return Boolean;
149 (Left
: Unbounded_Wide_String
;
150 Right
: Wide_String) return Boolean;
154 Right
: Unbounded_Wide_String
) return Boolean;
157 (Left
: Unbounded_Wide_String
;
158 Right
: Unbounded_Wide_String
) return Boolean;
161 (Left
: Unbounded_Wide_String
;
162 Right
: Wide_String) return Boolean;
166 Right
: Unbounded_Wide_String
) return Boolean;
169 (Left
: Unbounded_Wide_String
;
170 Right
: Unbounded_Wide_String
) return Boolean;
173 (Left
: Unbounded_Wide_String
;
174 Right
: Wide_String) return Boolean;
178 Right
: Unbounded_Wide_String
) return Boolean;
181 (Left
: Unbounded_Wide_String
;
182 Right
: Unbounded_Wide_String
) return Boolean;
185 (Left
: Unbounded_Wide_String
;
186 Right
: Wide_String) return Boolean;
190 Right
: Unbounded_Wide_String
) return Boolean;
192 ------------------------
193 -- Search Subprograms --
194 ------------------------
197 (Source
: Unbounded_Wide_String
;
198 Pattern
: Wide_String;
199 Going
: Direction
:= Forward
;
200 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
204 (Source
: Unbounded_Wide_String
;
205 Pattern
: Wide_String;
206 Going
: Direction
:= Forward
;
207 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
210 (Source
: Unbounded_Wide_String
;
211 Set
: Wide_Maps
.Wide_Character_Set
;
212 Test
: Membership
:= Inside
;
213 Going
: Direction
:= Forward
) return Natural;
216 (Source
: Unbounded_Wide_String
;
217 Pattern
: Wide_String;
219 Going
: Direction
:= Forward
;
220 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
222 pragma Ada_05
(Index
);
225 (Source
: Unbounded_Wide_String
;
226 Pattern
: Wide_String;
228 Going
: Direction
:= Forward
;
229 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
230 pragma Ada_05
(Index
);
233 (Source
: Unbounded_Wide_String
;
234 Set
: Wide_Maps
.Wide_Character_Set
;
236 Test
: Membership
:= Inside
;
237 Going
: Direction
:= Forward
) return Natural;
238 pragma Ada_05
(Index
);
240 function Index_Non_Blank
241 (Source
: Unbounded_Wide_String
;
242 Going
: Direction
:= Forward
) return Natural;
244 function Index_Non_Blank
245 (Source
: Unbounded_Wide_String
;
247 Going
: Direction
:= Forward
) return Natural;
248 pragma Ada_05
(Index_Non_Blank
);
251 (Source
: Unbounded_Wide_String
;
252 Pattern
: Wide_String;
253 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
257 (Source
: Unbounded_Wide_String
;
258 Pattern
: Wide_String;
259 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
262 (Source
: Unbounded_Wide_String
;
263 Set
: Wide_Maps
.Wide_Character_Set
) return Natural;
266 (Source
: Unbounded_Wide_String
;
267 Set
: Wide_Maps
.Wide_Character_Set
;
269 First
: out Positive;
272 ------------------------------------
273 -- String Translation Subprograms --
274 ------------------------------------
277 (Source
: Unbounded_Wide_String
;
278 Mapping
: Wide_Maps
.Wide_Character_Mapping
)
279 return Unbounded_Wide_String
;
282 (Source
: in out Unbounded_Wide_String
;
283 Mapping
: Wide_Maps
.Wide_Character_Mapping
);
286 (Source
: Unbounded_Wide_String
;
287 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
)
288 return Unbounded_Wide_String
;
291 (Source
: in out Unbounded_Wide_String
;
292 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
);
294 ---------------------------------------
295 -- String Transformation Subprograms --
296 ---------------------------------------
298 function Replace_Slice
299 (Source
: Unbounded_Wide_String
;
302 By
: Wide_String) return Unbounded_Wide_String
;
304 procedure Replace_Slice
305 (Source
: in out Unbounded_Wide_String
;
311 (Source
: Unbounded_Wide_String
;
313 New_Item
: Wide_String) return Unbounded_Wide_String
;
316 (Source
: in out Unbounded_Wide_String
;
318 New_Item
: Wide_String);
321 (Source
: Unbounded_Wide_String
;
323 New_Item
: Wide_String) return Unbounded_Wide_String
;
326 (Source
: in out Unbounded_Wide_String
;
328 New_Item
: Wide_String);
331 (Source
: Unbounded_Wide_String
;
333 Through
: Natural) return Unbounded_Wide_String
;
336 (Source
: in out Unbounded_Wide_String
;
341 (Source
: Unbounded_Wide_String
;
342 Side
: Trim_End
) return Unbounded_Wide_String
;
345 (Source
: in out Unbounded_Wide_String
;
349 (Source
: Unbounded_Wide_String
;
350 Left
: Wide_Maps
.Wide_Character_Set
;
351 Right
: Wide_Maps
.Wide_Character_Set
) return Unbounded_Wide_String
;
354 (Source
: in out Unbounded_Wide_String
;
355 Left
: Wide_Maps
.Wide_Character_Set
;
356 Right
: Wide_Maps
.Wide_Character_Set
);
359 (Source
: Unbounded_Wide_String
;
361 Pad
: Wide_Character := Wide_Space
) return Unbounded_Wide_String
;
364 (Source
: in out Unbounded_Wide_String
;
366 Pad
: Wide_Character := Wide_Space
);
369 (Source
: Unbounded_Wide_String
;
371 Pad
: Wide_Character := Wide_Space
) return Unbounded_Wide_String
;
374 (Source
: in out Unbounded_Wide_String
;
376 Pad
: Wide_Character := Wide_Space
);
380 Right
: Wide_Character) return Unbounded_Wide_String
;
384 Right
: Wide_String) return Unbounded_Wide_String
;
388 Right
: Unbounded_Wide_String
) return Unbounded_Wide_String
;
391 pragma Inline
(Length
);
393 package AF
renames Ada
.Finalization
;
395 Null_Wide_String
: aliased Wide_String := "";
397 function To_Unbounded_Wide
(S
: Wide_String) return Unbounded_Wide_String
398 renames To_Unbounded_Wide_String
;
400 type Unbounded_Wide_String
is new AF
.Controlled
with record
401 Reference
: Wide_String_Access
:= Null_Wide_String
'Access;
405 -- The Unbounded_Wide_String is using a buffered implementation to increase
406 -- speed of the Append/Delete/Insert procedures. The Reference string
407 -- pointer above contains the current string value and extra room at the
408 -- end to be used by the next Append routine. Last is the index of the
409 -- string ending character. So the current string value is really
410 -- Reference (1 .. Last).
412 pragma Stream_Convert
413 (Unbounded_Wide_String
, To_Unbounded_Wide
, To_Wide_String
);
415 pragma Finalize_Storage_Only
(Unbounded_Wide_String
);
416 -- Finalization is required only for freeing storage
418 procedure Initialize
(Object
: in out Unbounded_Wide_String
);
419 procedure Adjust
(Object
: in out Unbounded_Wide_String
);
420 procedure Finalize
(Object
: in out Unbounded_Wide_String
);
422 procedure Realloc_For_Chunk
423 (Source
: in out Unbounded_Wide_String
;
424 Chunk_Size
: Natural);
425 -- Adjust the size allocated for the string. Add at least Chunk_Size so it
426 -- is safe to add a string of this size at the end of the current content.
427 -- The real size allocated for the string is Chunk_Size + x of the current
428 -- string size. This buffered handling makes the Append unbounded string
429 -- routines very fast.
431 Null_Unbounded_Wide_String
: constant Unbounded_Wide_String
:=
433 Reference
=> Null_Wide_String
'Access,
435 -- Note: this declaration is illegal since library level controlled
436 -- objects are not allowed in preelaborated units. See AI-161 for a
437 -- discussion of this issue and an attempt to address it. Meanwhile,
438 -- what happens in GNAT is that this check is omitted for internal
439 -- implementation units (see check in sem_cat.adb).
441 end Ada
.Strings
.Wide_Unbounded
;