1 ------------------------------------------------------------------------------
3 -- GNAT RUNTIME 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-2002 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, 59 Temple Place - Suite 330, Boston, --
24 -- MA 02111-1307, 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
42 pragma Preelaborate
(Unbounded
);
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
(Source
: String) return Unbounded_String
;
59 function To_Unbounded_String
(Length
: in Natural) return Unbounded_String
;
61 function To_String
(Source
: Unbounded_String
) return String;
64 (Source
: in out Unbounded_String
;
65 New_Item
: in Unbounded_String
);
68 (Source
: in out Unbounded_String
;
69 New_Item
: in String);
72 (Source
: in out Unbounded_String
;
73 New_Item
: in Character);
75 function "&" (Left
, Right
: Unbounded_String
) return Unbounded_String
;
78 (Left
: in Unbounded_String
;
80 return Unbounded_String
;
84 Right
: in Unbounded_String
)
85 return Unbounded_String
;
88 (Left
: in Unbounded_String
;
90 return Unbounded_String
;
94 Right
: in Unbounded_String
)
95 return Unbounded_String
;
98 (Source
: in Unbounded_String
;
102 procedure Replace_Element
103 (Source
: in out Unbounded_String
;
108 (Source
: in Unbounded_String
;
113 function "=" (Left
, Right
: in Unbounded_String
) return Boolean;
116 (Left
: in Unbounded_String
;
122 Right
: in Unbounded_String
)
125 function "<" (Left
, Right
: in Unbounded_String
) return Boolean;
128 (Left
: in Unbounded_String
;
134 Right
: in Unbounded_String
)
137 function "<=" (Left
, Right
: in Unbounded_String
) return Boolean;
140 (Left
: in Unbounded_String
;
146 Right
: in Unbounded_String
)
149 function ">" (Left
, Right
: in Unbounded_String
) return Boolean;
152 (Left
: in Unbounded_String
;
158 Right
: in Unbounded_String
)
161 function ">=" (Left
, Right
: in Unbounded_String
) return Boolean;
164 (Left
: in Unbounded_String
;
170 Right
: in Unbounded_String
)
173 ------------------------
174 -- Search Subprograms --
175 ------------------------
178 (Source
: in Unbounded_String
;
180 Going
: in Direction
:= Forward
;
181 Mapping
: in Maps
.Character_Mapping
:= Maps
.Identity
)
185 (Source
: in Unbounded_String
;
187 Going
: in Direction
:= Forward
;
188 Mapping
: in Maps
.Character_Mapping_Function
)
192 (Source
: in Unbounded_String
;
193 Set
: in Maps
.Character_Set
;
194 Test
: in Membership
:= Inside
;
195 Going
: in Direction
:= Forward
)
198 function Index_Non_Blank
199 (Source
: in Unbounded_String
;
200 Going
: in Direction
:= Forward
)
204 (Source
: in Unbounded_String
;
206 Mapping
: in Maps
.Character_Mapping
:= Maps
.Identity
)
210 (Source
: in Unbounded_String
;
212 Mapping
: in Maps
.Character_Mapping_Function
)
216 (Source
: in Unbounded_String
;
217 Set
: in Maps
.Character_Set
)
221 (Source
: in Unbounded_String
;
222 Set
: in Maps
.Character_Set
;
223 Test
: in Membership
;
224 First
: out Positive;
227 ------------------------------------
228 -- String Translation Subprograms --
229 ------------------------------------
232 (Source
: in Unbounded_String
;
233 Mapping
: in Maps
.Character_Mapping
)
234 return Unbounded_String
;
237 (Source
: in out Unbounded_String
;
238 Mapping
: Maps
.Character_Mapping
);
241 (Source
: in Unbounded_String
;
242 Mapping
: in Maps
.Character_Mapping_Function
)
243 return Unbounded_String
;
246 (Source
: in out Unbounded_String
;
247 Mapping
: in Maps
.Character_Mapping_Function
);
249 ---------------------------------------
250 -- String Transformation Subprograms --
251 ---------------------------------------
253 function Replace_Slice
254 (Source
: in Unbounded_String
;
258 return Unbounded_String
;
260 procedure Replace_Slice
261 (Source
: in out Unbounded_String
;
267 (Source
: in Unbounded_String
;
268 Before
: in Positive;
269 New_Item
: in String)
270 return Unbounded_String
;
273 (Source
: in out Unbounded_String
;
274 Before
: in Positive;
275 New_Item
: in String);
278 (Source
: in Unbounded_String
;
279 Position
: in Positive;
280 New_Item
: in String)
281 return Unbounded_String
;
284 (Source
: in out Unbounded_String
;
285 Position
: in Positive;
286 New_Item
: in String);
289 (Source
: in Unbounded_String
;
291 Through
: in Natural)
292 return Unbounded_String
;
295 (Source
: in out Unbounded_String
;
297 Through
: in Natural);
300 (Source
: in Unbounded_String
;
302 return Unbounded_String
;
305 (Source
: in out Unbounded_String
;
309 (Source
: in Unbounded_String
;
310 Left
: in Maps
.Character_Set
;
311 Right
: in Maps
.Character_Set
)
312 return Unbounded_String
;
315 (Source
: in out Unbounded_String
;
316 Left
: in Maps
.Character_Set
;
317 Right
: in Maps
.Character_Set
);
320 (Source
: in Unbounded_String
;
322 Pad
: in Character := Space
)
323 return Unbounded_String
;
326 (Source
: in out Unbounded_String
;
328 Pad
: in Character := Space
);
331 (Source
: in Unbounded_String
;
333 Pad
: in Character := Space
)
334 return Unbounded_String
;
337 (Source
: in out Unbounded_String
;
339 Pad
: in Character := Space
);
343 Right
: in Character)
344 return Unbounded_String
;
349 return Unbounded_String
;
353 Right
: in Unbounded_String
)
354 return Unbounded_String
;
357 pragma Inline
(Length
);
359 package AF
renames Ada
.Finalization
;
361 Null_String
: aliased String := "";
363 function To_Unbounded
(S
: String) return Unbounded_String
364 renames To_Unbounded_String
;
366 type Unbounded_String
is new AF
.Controlled
with record
367 Reference
: String_Access
:= Null_String
'Access;
371 -- The Unbounded_String is using a buffered implementation to increase
372 -- speed of the Append/Delete/Insert procedures. The Reference string
373 -- pointer above contains the current string value and extra room at the
374 -- end to be used by the next Append routine. Last is the index of the
375 -- string ending character. So the current string value is really
376 -- Reference (1 .. Last).
378 pragma Stream_Convert
(Unbounded_String
, To_Unbounded
, To_String
);
380 pragma Finalize_Storage_Only
(Unbounded_String
);
382 procedure Initialize
(Object
: in out Unbounded_String
);
383 procedure Adjust
(Object
: in out Unbounded_String
);
384 procedure Finalize
(Object
: in out Unbounded_String
);
386 -- Note: the following declaration is illegal since library level
387 -- controlled objects are not allowed in preelaborated units. See
388 -- AI-161 for a discussion of this issue and an attempt to address it.
389 -- Meanwhile, what happens in GNAT is that this check is omitted for
390 -- internal implementation units (see check in sem_cat.adb).
392 Null_Unbounded_String
: constant Unbounded_String
:=
393 (AF
.Controlled
with Reference
=> Null_String
'Access, Last
=> 0);
395 end Ada
.Strings
.Unbounded
;