Update concepts branch to revision 131834
[official-gcc.git] / gcc / ada / a-strunb.ads
blob1601f3fef7462fd57f29878e58e16a25c6cad081
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . S T R I N G S . U N B O U N D E D --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
10 -- --
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. --
14 -- --
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. --
25 -- --
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. --
32 -- --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
35 -- --
36 ------------------------------------------------------------------------------
38 with Ada.Strings.Maps;
39 with Ada.Finalization;
41 package Ada.Strings.Unbounded is
42 pragma Preelaborate;
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;
69 Source : String);
70 pragma Ada_05 (Set_Unbounded_String);
72 procedure Append
73 (Source : in out Unbounded_String;
74 New_Item : Unbounded_String);
76 procedure Append
77 (Source : in out Unbounded_String;
78 New_Item : String);
80 procedure Append
81 (Source : in out Unbounded_String;
82 New_Item : Character);
84 function "&"
85 (Left : Unbounded_String;
86 Right : Unbounded_String) return Unbounded_String;
88 function "&"
89 (Left : Unbounded_String;
90 Right : String) return Unbounded_String;
92 function "&"
93 (Left : String;
94 Right : Unbounded_String) return Unbounded_String;
96 function "&"
97 (Left : Unbounded_String;
98 Right : Character) return Unbounded_String;
100 function "&"
101 (Left : Character;
102 Right : Unbounded_String) return Unbounded_String;
104 function Element
105 (Source : Unbounded_String;
106 Index : Positive) return Character;
108 procedure Replace_Element
109 (Source : in out Unbounded_String;
110 Index : Positive;
111 By : Character);
113 function Slice
114 (Source : Unbounded_String;
115 Low : Positive;
116 High : Natural) return String;
118 function Unbounded_Slice
119 (Source : Unbounded_String;
120 Low : Positive;
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;
127 Low : Positive;
128 High : Natural);
129 pragma Ada_05 (Unbounded_Slice);
131 function "="
132 (Left : Unbounded_String;
133 Right : Unbounded_String) return Boolean;
135 function "="
136 (Left : Unbounded_String;
137 Right : String) return Boolean;
139 function "="
140 (Left : String;
141 Right : Unbounded_String) return Boolean;
143 function "<"
144 (Left : Unbounded_String;
145 Right : Unbounded_String) return Boolean;
147 function "<"
148 (Left : Unbounded_String;
149 Right : String) return Boolean;
151 function "<"
152 (Left : String;
153 Right : Unbounded_String) return Boolean;
155 function "<="
156 (Left : Unbounded_String;
157 Right : Unbounded_String) return Boolean;
159 function "<="
160 (Left : Unbounded_String;
161 Right : String) return Boolean;
163 function "<="
164 (Left : String;
165 Right : Unbounded_String) return Boolean;
167 function ">"
168 (Left : Unbounded_String;
169 Right : Unbounded_String) return Boolean;
171 function ">"
172 (Left : Unbounded_String;
173 Right : String) return Boolean;
175 function ">"
176 (Left : String;
177 Right : Unbounded_String) return Boolean;
179 function ">="
180 (Left : Unbounded_String;
181 Right : Unbounded_String) return Boolean;
183 function ">="
184 (Left : Unbounded_String;
185 Right : String) return Boolean;
187 function ">="
188 (Left : String;
189 Right : Unbounded_String) return Boolean;
191 ------------------------
192 -- Search Subprograms --
193 ------------------------
195 function Index
196 (Source : Unbounded_String;
197 Pattern : String;
198 Going : Direction := Forward;
199 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
201 function Index
202 (Source : Unbounded_String;
203 Pattern : String;
204 Going : Direction := Forward;
205 Mapping : Maps.Character_Mapping_Function) return Natural;
207 function Index
208 (Source : Unbounded_String;
209 Set : Maps.Character_Set;
210 Test : Membership := Inside;
211 Going : Direction := Forward) return Natural;
213 function Index
214 (Source : Unbounded_String;
215 Pattern : String;
216 From : Positive;
217 Going : Direction := Forward;
218 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
219 pragma Ada_05 (Index);
221 function Index
222 (Source : Unbounded_String;
223 Pattern : String;
224 From : Positive;
225 Going : Direction := Forward;
226 Mapping : Maps.Character_Mapping_Function) return Natural;
227 pragma Ada_05 (Index);
229 function Index
230 (Source : Unbounded_String;
231 Set : Maps.Character_Set;
232 From : Positive;
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;
243 From : Positive;
244 Going : Direction := Forward) return Natural;
245 pragma Ada_05 (Index_Non_Blank);
247 function Count
248 (Source : Unbounded_String;
249 Pattern : String;
250 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
252 function Count
253 (Source : Unbounded_String;
254 Pattern : String;
255 Mapping : Maps.Character_Mapping_Function) return Natural;
257 function Count
258 (Source : Unbounded_String;
259 Set : Maps.Character_Set) return Natural;
261 procedure Find_Token
262 (Source : Unbounded_String;
263 Set : Maps.Character_Set;
264 Test : Membership;
265 First : out Positive;
266 Last : out Natural);
268 ------------------------------------
269 -- String Translation Subprograms --
270 ------------------------------------
272 function Translate
273 (Source : Unbounded_String;
274 Mapping : Maps.Character_Mapping) return Unbounded_String;
276 procedure Translate
277 (Source : in out Unbounded_String;
278 Mapping : Maps.Character_Mapping);
280 function Translate
281 (Source : Unbounded_String;
282 Mapping : Maps.Character_Mapping_Function) return Unbounded_String;
284 procedure Translate
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;
294 Low : Positive;
295 High : Natural;
296 By : String) return Unbounded_String;
298 procedure Replace_Slice
299 (Source : in out Unbounded_String;
300 Low : Positive;
301 High : Natural;
302 By : String);
304 function Insert
305 (Source : Unbounded_String;
306 Before : Positive;
307 New_Item : String) return Unbounded_String;
309 procedure Insert
310 (Source : in out Unbounded_String;
311 Before : Positive;
312 New_Item : String);
314 function Overwrite
315 (Source : Unbounded_String;
316 Position : Positive;
317 New_Item : String) return Unbounded_String;
319 procedure Overwrite
320 (Source : in out Unbounded_String;
321 Position : Positive;
322 New_Item : String);
324 function Delete
325 (Source : Unbounded_String;
326 From : Positive;
327 Through : Natural) return Unbounded_String;
329 procedure Delete
330 (Source : in out Unbounded_String;
331 From : Positive;
332 Through : Natural);
334 function Trim
335 (Source : Unbounded_String;
336 Side : Trim_End) return Unbounded_String;
338 procedure Trim
339 (Source : in out Unbounded_String;
340 Side : Trim_End);
342 function Trim
343 (Source : Unbounded_String;
344 Left : Maps.Character_Set;
345 Right : Maps.Character_Set) return Unbounded_String;
347 procedure Trim
348 (Source : in out Unbounded_String;
349 Left : Maps.Character_Set;
350 Right : Maps.Character_Set);
352 function Head
353 (Source : Unbounded_String;
354 Count : Natural;
355 Pad : Character := Space) return Unbounded_String;
357 procedure Head
358 (Source : in out Unbounded_String;
359 Count : Natural;
360 Pad : Character := Space);
362 function Tail
363 (Source : Unbounded_String;
364 Count : Natural;
365 Pad : Character := Space) return Unbounded_String;
367 procedure Tail
368 (Source : in out Unbounded_String;
369 Count : Natural;
370 Pad : Character := Space);
372 function "*"
373 (Left : Natural;
374 Right : Character) return Unbounded_String;
376 function "*"
377 (Left : Natural;
378 Right : String) return Unbounded_String;
380 function "*"
381 (Left : Natural;
382 Right : Unbounded_String) return Unbounded_String;
384 private
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;
396 Last : Natural := 0;
397 end record;
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);
406 -- Provide stream routines without dragging in Ada.Streams
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 :=
427 (AF.Controlled with
428 Reference => Null_String'Access,
429 Last => 0);
430 end Ada.Strings.Unbounded;