1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . S T R I N G S . 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
.Maps
;
39 with Ada
.Finalization
;
41 package Ada
.Strings
.Unbounded
is
44 type Unbounded_String
is private;
46 Null_Unbounded_String
: constant Unbounded_String
;
48 function Length
(Source
: Unbounded_String
) return Natural;
50 type String_Access
is access all String;
52 procedure Free
(X
: in out String_Access
);
54 --------------------------------------------------------
55 -- Conversion, Concatenation, and Selection Functions --
56 --------------------------------------------------------
58 function To_Unbounded_String
59 (Source
: String) return Unbounded_String
;
61 function To_Unbounded_String
62 (Length
: Natural) return Unbounded_String
;
64 function To_String
(Source
: Unbounded_String
) return String;
66 procedure Set_Unbounded_String
67 (Target
: out Unbounded_String
;
69 pragma Ada_05
(Set_Unbounded_String
);
72 (Source
: in out Unbounded_String
;
73 New_Item
: Unbounded_String
);
76 (Source
: in out Unbounded_String
;
80 (Source
: in out Unbounded_String
;
81 New_Item
: Character);
84 (Left
: Unbounded_String
;
85 Right
: Unbounded_String
) return Unbounded_String
;
88 (Left
: Unbounded_String
;
89 Right
: String) return Unbounded_String
;
93 Right
: Unbounded_String
) return Unbounded_String
;
96 (Left
: Unbounded_String
;
97 Right
: Character) return Unbounded_String
;
101 Right
: Unbounded_String
) return Unbounded_String
;
104 (Source
: Unbounded_String
;
105 Index
: Positive) return Character;
107 procedure Replace_Element
108 (Source
: in out Unbounded_String
;
113 (Source
: Unbounded_String
;
115 High
: Natural) return String;
117 function Unbounded_Slice
118 (Source
: Unbounded_String
;
120 High
: Natural) return Unbounded_String
;
121 pragma Ada_05
(Unbounded_Slice
);
123 procedure Unbounded_Slice
124 (Source
: Unbounded_String
;
125 Target
: out Unbounded_String
;
128 pragma Ada_05
(Unbounded_Slice
);
131 (Left
: Unbounded_String
;
132 Right
: Unbounded_String
) return Boolean;
135 (Left
: Unbounded_String
;
136 Right
: String) return Boolean;
140 Right
: Unbounded_String
) return Boolean;
143 (Left
: Unbounded_String
;
144 Right
: Unbounded_String
) return Boolean;
147 (Left
: Unbounded_String
;
148 Right
: String) return Boolean;
152 Right
: Unbounded_String
) return Boolean;
155 (Left
: Unbounded_String
;
156 Right
: Unbounded_String
) return Boolean;
159 (Left
: Unbounded_String
;
160 Right
: String) return Boolean;
164 Right
: Unbounded_String
) return Boolean;
167 (Left
: Unbounded_String
;
168 Right
: Unbounded_String
) return Boolean;
171 (Left
: Unbounded_String
;
172 Right
: String) return Boolean;
176 Right
: Unbounded_String
) return Boolean;
179 (Left
: Unbounded_String
;
180 Right
: Unbounded_String
) return Boolean;
183 (Left
: Unbounded_String
;
184 Right
: String) return Boolean;
188 Right
: Unbounded_String
) return Boolean;
190 ------------------------
191 -- Search Subprograms --
192 ------------------------
195 (Source
: Unbounded_String
;
197 Going
: Direction
:= Forward
;
198 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
201 (Source
: Unbounded_String
;
203 Going
: Direction
:= Forward
;
204 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
207 (Source
: Unbounded_String
;
208 Set
: Maps
.Character_Set
;
209 Test
: Membership
:= Inside
;
210 Going
: Direction
:= Forward
) return Natural;
213 (Source
: Unbounded_String
;
216 Going
: Direction
:= Forward
;
217 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
218 pragma Ada_05
(Index
);
221 (Source
: Unbounded_String
;
224 Going
: Direction
:= Forward
;
225 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
226 pragma Ada_05
(Index
);
229 (Source
: Unbounded_String
;
230 Set
: Maps
.Character_Set
;
232 Test
: Membership
:= Inside
;
233 Going
: Direction
:= Forward
) return Natural;
234 pragma Ada_05
(Index
);
236 function Index_Non_Blank
237 (Source
: Unbounded_String
;
238 Going
: Direction
:= Forward
) return Natural;
240 function Index_Non_Blank
241 (Source
: Unbounded_String
;
243 Going
: Direction
:= Forward
) return Natural;
244 pragma Ada_05
(Index_Non_Blank
);
247 (Source
: Unbounded_String
;
249 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
252 (Source
: Unbounded_String
;
254 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
257 (Source
: Unbounded_String
;
258 Set
: Maps
.Character_Set
) return Natural;
261 (Source
: Unbounded_String
;
262 Set
: Maps
.Character_Set
;
264 First
: out Positive;
267 ------------------------------------
268 -- String Translation Subprograms --
269 ------------------------------------
272 (Source
: Unbounded_String
;
273 Mapping
: Maps
.Character_Mapping
) return Unbounded_String
;
276 (Source
: in out Unbounded_String
;
277 Mapping
: Maps
.Character_Mapping
);
280 (Source
: Unbounded_String
;
281 Mapping
: Maps
.Character_Mapping_Function
) return Unbounded_String
;
284 (Source
: in out Unbounded_String
;
285 Mapping
: Maps
.Character_Mapping_Function
);
287 ---------------------------------------
288 -- String Transformation Subprograms --
289 ---------------------------------------
291 function Replace_Slice
292 (Source
: Unbounded_String
;
295 By
: String) return Unbounded_String
;
297 procedure Replace_Slice
298 (Source
: in out Unbounded_String
;
304 (Source
: Unbounded_String
;
306 New_Item
: String) return Unbounded_String
;
309 (Source
: in out Unbounded_String
;
314 (Source
: Unbounded_String
;
316 New_Item
: String) return Unbounded_String
;
319 (Source
: in out Unbounded_String
;
324 (Source
: Unbounded_String
;
326 Through
: Natural) return Unbounded_String
;
329 (Source
: in out Unbounded_String
;
334 (Source
: Unbounded_String
;
335 Side
: Trim_End
) return Unbounded_String
;
338 (Source
: in out Unbounded_String
;
342 (Source
: Unbounded_String
;
343 Left
: Maps
.Character_Set
;
344 Right
: Maps
.Character_Set
) return Unbounded_String
;
347 (Source
: in out Unbounded_String
;
348 Left
: Maps
.Character_Set
;
349 Right
: Maps
.Character_Set
);
352 (Source
: Unbounded_String
;
354 Pad
: Character := Space
) return Unbounded_String
;
357 (Source
: in out Unbounded_String
;
359 Pad
: Character := Space
);
362 (Source
: Unbounded_String
;
364 Pad
: Character := Space
) return Unbounded_String
;
367 (Source
: in out Unbounded_String
;
369 Pad
: Character := Space
);
373 Right
: Character) return Unbounded_String
;
377 Right
: String) return Unbounded_String
;
381 Right
: Unbounded_String
) return Unbounded_String
;
384 pragma Inline
(Length
);
386 package AF
renames Ada
.Finalization
;
388 Null_String
: aliased String := "";
390 function To_Unbounded
(S
: String) return Unbounded_String
391 renames To_Unbounded_String
;
393 type Unbounded_String
is new AF
.Controlled
with record
394 Reference
: String_Access
:= Null_String
'Access;
398 -- The Unbounded_String is using a buffered implementation to increase
399 -- speed of the Append/Delete/Insert procedures. The Reference string
400 -- pointer above contains the current string value and extra room at the
401 -- end to be used by the next Append routine. Last is the index of the
402 -- string ending character. So the current string value is really
403 -- Reference (1 .. Last).
405 pragma Stream_Convert
(Unbounded_String
, To_Unbounded
, To_String
);
407 pragma Finalize_Storage_Only
(Unbounded_String
);
408 -- Finalization is required only for freeing storage
410 procedure Initialize
(Object
: in out Unbounded_String
);
411 procedure Adjust
(Object
: in out Unbounded_String
);
412 procedure Finalize
(Object
: in out Unbounded_String
);
414 procedure Realloc_For_Chunk
415 (Source
: in out Unbounded_String
;
416 Chunk_Size
: Natural);
417 pragma Inline
(Realloc_For_Chunk
);
418 -- Adjust the size allocated for the string. Add at least Chunk_Size so it
419 -- is safe to add a string of this size at the end of the current content.
420 -- The real size allocated for the string is Chunk_Size + x of the current
421 -- string size. This buffered handling makes the Append unbounded string
422 -- routines very fast. This spec is in the private part so that it can be
423 -- accessed from children (e.g. from Unbounded.Text_IO).
425 Null_Unbounded_String
: constant Unbounded_String
:=
427 Reference
=> Null_String
'Access,
429 -- Note: this declaration is illegal since library level controlled
430 -- objects are not allowed in preelaborated units. See AI-161 for a
431 -- discussion of this issue and an attempt to address it. Meanwhile,
432 -- what happens in GNAT is that this check is omitted for internal
433 -- implementation units (see check in sem_cat.adb).
435 end Ada
.Strings
.Unbounded
;