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-2006, 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;
45 pragma Preelaborable_Initialization
(Unbounded_String
);
47 Null_Unbounded_String
: constant Unbounded_String
;
49 function Length
(Source
: Unbounded_String
) return Natural;
51 type String_Access
is access all String;
53 procedure Free
(X
: in out String_Access
);
55 --------------------------------------------------------
56 -- Conversion, Concatenation, and Selection Functions --
57 --------------------------------------------------------
59 function To_Unbounded_String
60 (Source
: String) return Unbounded_String
;
62 function To_Unbounded_String
63 (Length
: Natural) return Unbounded_String
;
65 function To_String
(Source
: Unbounded_String
) return String;
67 procedure Set_Unbounded_String
68 (Target
: out Unbounded_String
;
70 pragma Ada_05
(Set_Unbounded_String
);
73 (Source
: in out Unbounded_String
;
74 New_Item
: Unbounded_String
);
77 (Source
: in out Unbounded_String
;
81 (Source
: in out Unbounded_String
;
82 New_Item
: Character);
85 (Left
: Unbounded_String
;
86 Right
: Unbounded_String
) return Unbounded_String
;
89 (Left
: Unbounded_String
;
90 Right
: String) return Unbounded_String
;
94 Right
: Unbounded_String
) return Unbounded_String
;
97 (Left
: Unbounded_String
;
98 Right
: Character) return Unbounded_String
;
102 Right
: Unbounded_String
) return Unbounded_String
;
105 (Source
: Unbounded_String
;
106 Index
: Positive) return Character;
108 procedure Replace_Element
109 (Source
: in out Unbounded_String
;
114 (Source
: Unbounded_String
;
116 High
: Natural) return String;
118 function Unbounded_Slice
119 (Source
: Unbounded_String
;
121 High
: Natural) return Unbounded_String
;
122 pragma Ada_05
(Unbounded_Slice
);
124 procedure Unbounded_Slice
125 (Source
: Unbounded_String
;
126 Target
: out Unbounded_String
;
129 pragma Ada_05
(Unbounded_Slice
);
132 (Left
: Unbounded_String
;
133 Right
: Unbounded_String
) return Boolean;
136 (Left
: Unbounded_String
;
137 Right
: String) return Boolean;
141 Right
: Unbounded_String
) return Boolean;
144 (Left
: Unbounded_String
;
145 Right
: Unbounded_String
) return Boolean;
148 (Left
: Unbounded_String
;
149 Right
: String) return Boolean;
153 Right
: Unbounded_String
) return Boolean;
156 (Left
: Unbounded_String
;
157 Right
: Unbounded_String
) return Boolean;
160 (Left
: Unbounded_String
;
161 Right
: String) return Boolean;
165 Right
: Unbounded_String
) return Boolean;
168 (Left
: Unbounded_String
;
169 Right
: Unbounded_String
) return Boolean;
172 (Left
: Unbounded_String
;
173 Right
: String) return Boolean;
177 Right
: Unbounded_String
) return Boolean;
180 (Left
: Unbounded_String
;
181 Right
: Unbounded_String
) return Boolean;
184 (Left
: Unbounded_String
;
185 Right
: String) return Boolean;
189 Right
: Unbounded_String
) return Boolean;
191 ------------------------
192 -- Search Subprograms --
193 ------------------------
196 (Source
: Unbounded_String
;
198 Going
: Direction
:= Forward
;
199 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
202 (Source
: Unbounded_String
;
204 Going
: Direction
:= Forward
;
205 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
208 (Source
: Unbounded_String
;
209 Set
: Maps
.Character_Set
;
210 Test
: Membership
:= Inside
;
211 Going
: Direction
:= Forward
) return Natural;
214 (Source
: Unbounded_String
;
217 Going
: Direction
:= Forward
;
218 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
219 pragma Ada_05
(Index
);
222 (Source
: Unbounded_String
;
225 Going
: Direction
:= Forward
;
226 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
227 pragma Ada_05
(Index
);
230 (Source
: Unbounded_String
;
231 Set
: Maps
.Character_Set
;
233 Test
: Membership
:= Inside
;
234 Going
: Direction
:= Forward
) return Natural;
235 pragma Ada_05
(Index
);
237 function Index_Non_Blank
238 (Source
: Unbounded_String
;
239 Going
: Direction
:= Forward
) return Natural;
241 function Index_Non_Blank
242 (Source
: Unbounded_String
;
244 Going
: Direction
:= Forward
) return Natural;
245 pragma Ada_05
(Index_Non_Blank
);
248 (Source
: Unbounded_String
;
250 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
253 (Source
: Unbounded_String
;
255 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
258 (Source
: Unbounded_String
;
259 Set
: Maps
.Character_Set
) return Natural;
262 (Source
: Unbounded_String
;
263 Set
: Maps
.Character_Set
;
265 First
: out Positive;
268 ------------------------------------
269 -- String Translation Subprograms --
270 ------------------------------------
273 (Source
: Unbounded_String
;
274 Mapping
: Maps
.Character_Mapping
) return Unbounded_String
;
277 (Source
: in out Unbounded_String
;
278 Mapping
: Maps
.Character_Mapping
);
281 (Source
: Unbounded_String
;
282 Mapping
: Maps
.Character_Mapping_Function
) return Unbounded_String
;
285 (Source
: in out Unbounded_String
;
286 Mapping
: Maps
.Character_Mapping_Function
);
288 ---------------------------------------
289 -- String Transformation Subprograms --
290 ---------------------------------------
292 function Replace_Slice
293 (Source
: Unbounded_String
;
296 By
: String) return Unbounded_String
;
298 procedure Replace_Slice
299 (Source
: in out Unbounded_String
;
305 (Source
: Unbounded_String
;
307 New_Item
: String) return Unbounded_String
;
310 (Source
: in out Unbounded_String
;
315 (Source
: Unbounded_String
;
317 New_Item
: String) return Unbounded_String
;
320 (Source
: in out Unbounded_String
;
325 (Source
: Unbounded_String
;
327 Through
: Natural) return Unbounded_String
;
330 (Source
: in out Unbounded_String
;
335 (Source
: Unbounded_String
;
336 Side
: Trim_End
) return Unbounded_String
;
339 (Source
: in out Unbounded_String
;
343 (Source
: Unbounded_String
;
344 Left
: Maps
.Character_Set
;
345 Right
: Maps
.Character_Set
) return Unbounded_String
;
348 (Source
: in out Unbounded_String
;
349 Left
: Maps
.Character_Set
;
350 Right
: Maps
.Character_Set
);
353 (Source
: Unbounded_String
;
355 Pad
: Character := Space
) return Unbounded_String
;
358 (Source
: in out Unbounded_String
;
360 Pad
: Character := Space
);
363 (Source
: Unbounded_String
;
365 Pad
: Character := Space
) return Unbounded_String
;
368 (Source
: in out Unbounded_String
;
370 Pad
: Character := Space
);
374 Right
: Character) return Unbounded_String
;
378 Right
: String) return Unbounded_String
;
382 Right
: Unbounded_String
) return Unbounded_String
;
385 pragma Inline
(Length
);
387 package AF
renames Ada
.Finalization
;
389 Null_String
: aliased String := "";
391 function To_Unbounded
(S
: String) return Unbounded_String
392 renames To_Unbounded_String
;
394 type Unbounded_String
is new AF
.Controlled
with record
395 Reference
: String_Access
:= Null_String
'Access;
399 -- The Unbounded_String is using a buffered implementation to increase
400 -- speed of the Append/Delete/Insert procedures. The Reference string
401 -- pointer above contains the current string value and extra room at the
402 -- end to be used by the next Append routine. Last is the index of the
403 -- string ending character. So the current string value is really
404 -- Reference (1 .. Last).
406 pragma Stream_Convert
(Unbounded_String
, To_Unbounded
, To_String
);
408 pragma Finalize_Storage_Only
(Unbounded_String
);
409 -- Finalization is required only for freeing storage
411 procedure Initialize
(Object
: in out Unbounded_String
);
412 procedure Adjust
(Object
: in out Unbounded_String
);
413 procedure Finalize
(Object
: in out Unbounded_String
);
415 procedure Realloc_For_Chunk
416 (Source
: in out Unbounded_String
;
417 Chunk_Size
: Natural);
418 pragma Inline
(Realloc_For_Chunk
);
419 -- Adjust the size allocated for the string. Add at least Chunk_Size so it
420 -- is safe to add a string of this size at the end of the current content.
421 -- The real size allocated for the string is Chunk_Size + x of the current
422 -- string size. This buffered handling makes the Append unbounded string
423 -- routines very fast. This spec is in the private part so that it can be
424 -- accessed from children (e.g. from Unbounded.Text_IO).
426 Null_Unbounded_String
: constant Unbounded_String
:=
428 Reference
=> Null_String
'Access,
430 end Ada
.Strings
.Unbounded
;