1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . S T R I N G S . B O U N D E D --
9 -- Copyright (C) 1992-2000 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
;
40 package Ada
.Strings
.Bounded
is
41 pragma Preelaborate
(Bounded
);
45 -- Maximum length of a Bounded_String
47 package Generic_Bounded_Length
is
49 Max_Length
: constant Positive := Max
;
51 type Bounded_String
is private;
53 Null_Bounded_String
: constant Bounded_String
;
55 subtype Length_Range
is Natural range 0 .. Max_Length
;
57 function Length
(Source
: in Bounded_String
) return Length_Range
;
59 --------------------------------------------------------
60 -- Conversion, Concatenation, and Selection Functions --
61 --------------------------------------------------------
63 function To_Bounded_String
65 Drop
: in Truncation
:= Error
)
66 return Bounded_String
;
68 function To_String
(Source
: in Bounded_String
) return String;
71 (Left
, Right
: in Bounded_String
;
72 Drop
: in Truncation
:= Error
)
73 return Bounded_String
;
76 (Left
: in Bounded_String
;
78 Drop
: in Truncation
:= Error
)
79 return Bounded_String
;
83 Right
: in Bounded_String
;
84 Drop
: in Truncation
:= Error
)
85 return Bounded_String
;
88 (Left
: in Bounded_String
;
90 Drop
: in Truncation
:= Error
)
91 return Bounded_String
;
95 Right
: in Bounded_String
;
96 Drop
: in Truncation
:= Error
)
97 return Bounded_String
;
100 (Source
: in out Bounded_String
;
101 New_Item
: in Bounded_String
;
102 Drop
: in Truncation
:= Error
);
105 (Source
: in out Bounded_String
;
106 New_Item
: in String;
107 Drop
: in Truncation
:= Error
);
110 (Source
: in out Bounded_String
;
111 New_Item
: in Character;
112 Drop
: in Truncation
:= Error
);
115 (Left
, Right
: in Bounded_String
)
116 return Bounded_String
;
119 (Left
: in Bounded_String
;
121 return Bounded_String
;
125 Right
: in Bounded_String
)
126 return Bounded_String
;
129 (Left
: in Bounded_String
;
130 Right
: in Character)
131 return Bounded_String
;
134 (Left
: in Character;
135 Right
: in Bounded_String
)
136 return Bounded_String
;
139 (Source
: in Bounded_String
;
143 procedure Replace_Element
144 (Source
: in out Bounded_String
;
149 (Source
: in Bounded_String
;
154 function "=" (Left
, Right
: in Bounded_String
) return Boolean;
157 (Left
: in Bounded_String
;
163 Right
: in Bounded_String
)
166 function "<" (Left
, Right
: in Bounded_String
) return Boolean;
169 (Left
: in Bounded_String
;
175 Right
: in Bounded_String
)
178 function "<=" (Left
, Right
: in Bounded_String
) return Boolean;
181 (Left
: in Bounded_String
;
187 Right
: in Bounded_String
)
190 function ">" (Left
, Right
: in Bounded_String
) return Boolean;
193 (Left
: in Bounded_String
;
199 Right
: in Bounded_String
)
202 function ">=" (Left
, Right
: in Bounded_String
) return Boolean;
205 (Left
: in Bounded_String
;
211 Right
: in Bounded_String
)
214 ----------------------
215 -- Search Functions --
216 ----------------------
219 (Source
: in Bounded_String
;
221 Going
: in Direction
:= Forward
;
222 Mapping
: in Maps
.Character_Mapping
:= Maps
.Identity
)
226 (Source
: in Bounded_String
;
228 Going
: in Direction
:= Forward
;
229 Mapping
: in Maps
.Character_Mapping_Function
)
233 (Source
: in Bounded_String
;
234 Set
: in Maps
.Character_Set
;
235 Test
: in Membership
:= Inside
;
236 Going
: in Direction
:= Forward
)
239 function Index_Non_Blank
240 (Source
: in Bounded_String
;
241 Going
: in Direction
:= Forward
)
245 (Source
: in Bounded_String
;
247 Mapping
: in Maps
.Character_Mapping
:= Maps
.Identity
)
251 (Source
: in Bounded_String
;
253 Mapping
: in Maps
.Character_Mapping_Function
)
257 (Source
: in Bounded_String
;
258 Set
: in Maps
.Character_Set
)
262 (Source
: in Bounded_String
;
263 Set
: in Maps
.Character_Set
;
264 Test
: in Membership
;
265 First
: out Positive;
268 ------------------------------------
269 -- String Translation Subprograms --
270 ------------------------------------
273 (Source
: in Bounded_String
;
274 Mapping
: in Maps
.Character_Mapping
)
275 return Bounded_String
;
278 (Source
: in out Bounded_String
;
279 Mapping
: in Maps
.Character_Mapping
);
282 (Source
: in Bounded_String
;
283 Mapping
: in Maps
.Character_Mapping_Function
)
284 return Bounded_String
;
287 (Source
: in out Bounded_String
;
288 Mapping
: in Maps
.Character_Mapping_Function
);
290 ---------------------------------------
291 -- String Transformation Subprograms --
292 ---------------------------------------
294 function Replace_Slice
295 (Source
: in Bounded_String
;
299 Drop
: in Truncation
:= Error
)
300 return Bounded_String
;
302 procedure Replace_Slice
303 (Source
: in out Bounded_String
;
307 Drop
: in Truncation
:= Error
);
310 (Source
: in Bounded_String
;
311 Before
: in Positive;
312 New_Item
: in String;
313 Drop
: in Truncation
:= Error
)
314 return Bounded_String
;
317 (Source
: in out Bounded_String
;
318 Before
: in Positive;
319 New_Item
: in String;
320 Drop
: in Truncation
:= Error
);
323 (Source
: in Bounded_String
;
324 Position
: in Positive;
325 New_Item
: in String;
326 Drop
: in Truncation
:= Error
)
327 return Bounded_String
;
330 (Source
: in out Bounded_String
;
331 Position
: in Positive;
332 New_Item
: in String;
333 Drop
: in Truncation
:= Error
);
336 (Source
: in Bounded_String
;
338 Through
: in Natural)
339 return Bounded_String
;
342 (Source
: in out Bounded_String
;
344 Through
: in Natural);
346 ---------------------------------
347 -- String Selector Subprograms --
348 ---------------------------------
351 (Source
: in Bounded_String
;
353 return Bounded_String
;
356 (Source
: in out Bounded_String
;
360 (Source
: in Bounded_String
;
361 Left
: in Maps
.Character_Set
;
362 Right
: in Maps
.Character_Set
)
363 return Bounded_String
;
366 (Source
: in out Bounded_String
;
367 Left
: in Maps
.Character_Set
;
368 Right
: in Maps
.Character_Set
);
371 (Source
: in Bounded_String
;
373 Pad
: in Character := Space
;
374 Drop
: in Truncation
:= Error
)
375 return Bounded_String
;
378 (Source
: in out Bounded_String
;
380 Pad
: in Character := Space
;
381 Drop
: in Truncation
:= Error
);
384 (Source
: in Bounded_String
;
386 Pad
: in Character := Space
;
387 Drop
: in Truncation
:= Error
)
388 return Bounded_String
;
391 (Source
: in out Bounded_String
;
393 Pad
: in Character := Space
;
394 Drop
: in Truncation
:= Error
);
396 ------------------------------------
397 -- String Constructor Subprograms --
398 ------------------------------------
402 Right
: in Character)
403 return Bounded_String
;
408 return Bounded_String
;
412 Right
: in Bounded_String
)
413 return Bounded_String
;
418 Drop
: in Truncation
:= Error
)
419 return Bounded_String
;
424 Drop
: in Truncation
:= Error
)
425 return Bounded_String
;
429 Item
: in Bounded_String
;
430 Drop
: in Truncation
:= Error
)
431 return Bounded_String
;
435 type Bounded_String
is record
436 Length
: Length_Range
:= 0;
437 Data
: String (1 .. Max_Length
) := (1 .. Max_Length
=> ASCII
.NUL
);
440 Null_Bounded_String
: constant Bounded_String
:=
441 (Length
=> 0, Data
=> (1 .. Max_Length
=> ASCII
.NUL
));
444 -- Pragma Inline declarations (GNAT specific additions)
448 pragma Inline
("<=");
450 pragma Inline
(">=");
452 pragma Inline
(Count
);
453 pragma Inline
(Element
);
454 pragma Inline
(Find_Token
);
455 pragma Inline
(Index
);
456 pragma Inline
(Index_Non_Blank
);
457 pragma Inline
(Length
);
458 pragma Inline
(Replace_Element
);
459 pragma Inline
(Slice
);
460 pragma Inline
(To_Bounded_String
);
461 pragma Inline
(To_String
);
463 end Generic_Bounded_Length
;
465 end Ada
.Strings
.Bounded
;