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-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
.Strings
.Superbounded
;
41 package Ada
.Strings
.Bounded
is
46 -- Maximum length of a Bounded_String
48 package Generic_Bounded_Length
is
50 Max_Length
: constant Positive := Max
;
52 type Bounded_String
is private;
54 Null_Bounded_String
: constant Bounded_String
;
56 subtype Length_Range
is Natural range 0 .. Max_Length
;
58 function Length
(Source
: Bounded_String
) return Length_Range
;
60 --------------------------------------------------------
61 -- Conversion, Concatenation, and Selection Functions --
62 --------------------------------------------------------
64 function To_Bounded_String
66 Drop
: Truncation
:= Error
) return Bounded_String
;
68 function To_String
(Source
: Bounded_String
) return String;
70 procedure Set_Bounded_String
71 (Target
: out Bounded_String
;
73 Drop
: Truncation
:= Error
);
74 pragma Ada_05
(Set_Bounded_String
);
77 (Left
: Bounded_String
;
78 Right
: Bounded_String
;
79 Drop
: Truncation
:= Error
) return Bounded_String
;
82 (Left
: Bounded_String
;
84 Drop
: Truncation
:= Error
) return Bounded_String
;
88 Right
: Bounded_String
;
89 Drop
: Truncation
:= Error
) return Bounded_String
;
92 (Left
: Bounded_String
;
94 Drop
: Truncation
:= Error
) return Bounded_String
;
98 Right
: Bounded_String
;
99 Drop
: Truncation
:= Error
) return Bounded_String
;
102 (Source
: in out Bounded_String
;
103 New_Item
: Bounded_String
;
104 Drop
: Truncation
:= Error
);
107 (Source
: in out Bounded_String
;
109 Drop
: Truncation
:= Error
);
112 (Source
: in out Bounded_String
;
113 New_Item
: Character;
114 Drop
: Truncation
:= Error
);
117 (Left
: Bounded_String
;
118 Right
: Bounded_String
) return Bounded_String
;
121 (Left
: Bounded_String
;
122 Right
: String) return Bounded_String
;
126 Right
: Bounded_String
) return Bounded_String
;
129 (Left
: Bounded_String
;
130 Right
: Character) return Bounded_String
;
134 Right
: Bounded_String
) return Bounded_String
;
137 (Source
: Bounded_String
;
138 Index
: Positive) return Character;
140 procedure Replace_Element
141 (Source
: in out Bounded_String
;
146 (Source
: Bounded_String
;
148 High
: Natural) return String;
150 function Bounded_Slice
151 (Source
: Bounded_String
;
153 High
: Natural) return Bounded_String
;
154 pragma Ada_05
(Bounded_Slice
);
156 procedure Bounded_Slice
157 (Source
: Bounded_String
;
158 Target
: out Bounded_String
;
161 pragma Ada_05
(Bounded_Slice
);
164 (Left
: Bounded_String
;
165 Right
: Bounded_String
) return Boolean;
168 (Left
: Bounded_String
;
169 Right
: String) return Boolean;
173 Right
: Bounded_String
) return Boolean;
176 (Left
: Bounded_String
;
177 Right
: Bounded_String
) return Boolean;
180 (Left
: Bounded_String
;
181 Right
: String) return Boolean;
185 Right
: Bounded_String
) return Boolean;
188 (Left
: Bounded_String
;
189 Right
: Bounded_String
) return Boolean;
192 (Left
: Bounded_String
;
193 Right
: String) return Boolean;
197 Right
: Bounded_String
) return Boolean;
200 (Left
: Bounded_String
;
201 Right
: Bounded_String
) return Boolean;
204 (Left
: Bounded_String
;
205 Right
: String) return Boolean;
209 Right
: Bounded_String
) return Boolean;
212 (Left
: Bounded_String
;
213 Right
: Bounded_String
) return Boolean;
216 (Left
: Bounded_String
;
217 Right
: String) return Boolean;
221 Right
: Bounded_String
) return Boolean;
223 ----------------------
224 -- Search Functions --
225 ----------------------
228 (Source
: Bounded_String
;
230 Going
: Direction
:= Forward
;
231 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
234 (Source
: Bounded_String
;
236 Going
: Direction
:= Forward
;
237 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
240 (Source
: Bounded_String
;
241 Set
: Maps
.Character_Set
;
242 Test
: Membership
:= Inside
;
243 Going
: Direction
:= Forward
) return Natural;
246 (Source
: Bounded_String
;
249 Going
: Direction
:= Forward
;
250 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
251 pragma Ada_05
(Index
);
254 (Source
: Bounded_String
;
257 Going
: Direction
:= Forward
;
258 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
259 pragma Ada_05
(Index
);
262 (Source
: Bounded_String
;
263 Set
: Maps
.Character_Set
;
265 Test
: Membership
:= Inside
;
266 Going
: Direction
:= Forward
) return Natural;
267 pragma Ada_05
(Index
);
269 function Index_Non_Blank
270 (Source
: Bounded_String
;
271 Going
: Direction
:= Forward
) return Natural;
273 function Index_Non_Blank
274 (Source
: Bounded_String
;
276 Going
: Direction
:= Forward
) return Natural;
277 pragma Ada_05
(Index_Non_Blank
);
280 (Source
: Bounded_String
;
282 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
285 (Source
: Bounded_String
;
287 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
290 (Source
: Bounded_String
;
291 Set
: Maps
.Character_Set
) return Natural;
294 (Source
: Bounded_String
;
295 Set
: Maps
.Character_Set
;
297 First
: out Positive;
300 ------------------------------------
301 -- String Translation Subprograms --
302 ------------------------------------
305 (Source
: Bounded_String
;
306 Mapping
: Maps
.Character_Mapping
) return Bounded_String
;
309 (Source
: in out Bounded_String
;
310 Mapping
: Maps
.Character_Mapping
);
313 (Source
: Bounded_String
;
314 Mapping
: Maps
.Character_Mapping_Function
) return Bounded_String
;
317 (Source
: in out Bounded_String
;
318 Mapping
: Maps
.Character_Mapping_Function
);
320 ---------------------------------------
321 -- String Transformation Subprograms --
322 ---------------------------------------
324 function Replace_Slice
325 (Source
: Bounded_String
;
329 Drop
: Truncation
:= Error
) return Bounded_String
;
331 procedure Replace_Slice
332 (Source
: in out Bounded_String
;
336 Drop
: Truncation
:= Error
);
339 (Source
: Bounded_String
;
342 Drop
: Truncation
:= Error
) return Bounded_String
;
345 (Source
: in out Bounded_String
;
348 Drop
: Truncation
:= Error
);
351 (Source
: Bounded_String
;
354 Drop
: Truncation
:= Error
) return Bounded_String
;
357 (Source
: in out Bounded_String
;
360 Drop
: Truncation
:= Error
);
363 (Source
: Bounded_String
;
365 Through
: Natural) return Bounded_String
;
368 (Source
: in out Bounded_String
;
372 ---------------------------------
373 -- String Selector Subprograms --
374 ---------------------------------
377 (Source
: Bounded_String
;
378 Side
: Trim_End
) return Bounded_String
;
381 (Source
: in out Bounded_String
;
385 (Source
: Bounded_String
;
386 Left
: Maps
.Character_Set
;
387 Right
: Maps
.Character_Set
) return Bounded_String
;
390 (Source
: in out Bounded_String
;
391 Left
: Maps
.Character_Set
;
392 Right
: Maps
.Character_Set
);
395 (Source
: Bounded_String
;
397 Pad
: Character := Space
;
398 Drop
: Truncation
:= Error
) return Bounded_String
;
401 (Source
: in out Bounded_String
;
403 Pad
: Character := Space
;
404 Drop
: Truncation
:= Error
);
407 (Source
: Bounded_String
;
409 Pad
: Character := Space
;
410 Drop
: Truncation
:= Error
) return Bounded_String
;
413 (Source
: in out Bounded_String
;
415 Pad
: Character := Space
;
416 Drop
: Truncation
:= Error
);
418 ------------------------------------
419 -- String Constructor Subprograms --
420 ------------------------------------
424 Right
: Character) return Bounded_String
;
428 Right
: String) return Bounded_String
;
432 Right
: Bounded_String
) return Bounded_String
;
437 Drop
: Truncation
:= Error
) return Bounded_String
;
442 Drop
: Truncation
:= Error
) return Bounded_String
;
446 Item
: Bounded_String
;
447 Drop
: Truncation
:= Error
) return Bounded_String
;
450 -- Most of the implementation is in the separate non generic package
451 -- Ada.Strings.Superbounded. Type Bounded_String is derived from type
452 -- Superbounded.Super_String with the maximum length constraint. In
453 -- almost all cases, the routines in Superbounded can be called with
454 -- no requirement to pass the maximum length explicitly, since there
455 -- is at least one Bounded_String argument from which the maximum
456 -- length can be obtained. For all such routines, the implementation
457 -- in this private part is simply a renaming of the corresponding
458 -- routine in the super bouded package.
460 -- The five exceptions are the * and Replicate routines operating on
461 -- character values. For these cases, we have a routine in the body
462 -- that calls the superbounded routine passing the maximum length
463 -- explicitly as an extra parameter.
465 type Bounded_String
is new Superbounded
.Super_String
(Max_Length
);
466 -- Deriving Bounded_String from Superbounded.Super_String is the
467 -- real trick, it ensures that the type Bounded_String declared in
468 -- the generic instantiation is compatible with the Super_String
469 -- type declared in the Superbounded package.
471 Null_Bounded_String
: constant Bounded_String
:=
472 (Max_Length
=> Max_Length
,
475 (1 .. Max_Length
=> ASCII
.NUL
));
477 pragma Inline
(To_Bounded_String
);
479 procedure Set_Bounded_String
480 (Target
: out Bounded_String
;
482 Drop
: Truncation
:= Error
)
483 renames Set_Super_String
;
486 (Source
: Bounded_String
) return Length_Range
487 renames Super_Length
;
490 (Source
: Bounded_String
) return String
491 renames Super_To_String
;
494 (Left
: Bounded_String
;
495 Right
: Bounded_String
;
496 Drop
: Truncation
:= Error
) return Bounded_String
497 renames Super_Append
;
500 (Left
: Bounded_String
;
502 Drop
: Truncation
:= Error
) return Bounded_String
503 renames Super_Append
;
507 Right
: Bounded_String
;
508 Drop
: Truncation
:= Error
) return Bounded_String
509 renames Super_Append
;
512 (Left
: Bounded_String
;
514 Drop
: Truncation
:= Error
) return Bounded_String
515 renames Super_Append
;
519 Right
: Bounded_String
;
520 Drop
: Truncation
:= Error
) return Bounded_String
521 renames Super_Append
;
524 (Source
: in out Bounded_String
;
525 New_Item
: Bounded_String
;
526 Drop
: Truncation
:= Error
)
527 renames Super_Append
;
530 (Source
: in out Bounded_String
;
532 Drop
: Truncation
:= Error
)
533 renames Super_Append
;
536 (Source
: in out Bounded_String
;
537 New_Item
: Character;
538 Drop
: Truncation
:= Error
)
539 renames Super_Append
;
542 (Left
: Bounded_String
;
543 Right
: Bounded_String
) return Bounded_String
547 (Left
: Bounded_String
;
548 Right
: String) return Bounded_String
553 Right
: Bounded_String
) return Bounded_String
557 (Left
: Bounded_String
;
558 Right
: Character) return Bounded_String
563 Right
: Bounded_String
) return Bounded_String
567 (Source
: Bounded_String
;
568 Index
: Positive) return Character
569 renames Super_Element
;
571 procedure Replace_Element
572 (Source
: in out Bounded_String
;
575 renames Super_Replace_Element
;
578 (Source
: Bounded_String
;
580 High
: Natural) return String
583 function Bounded_Slice
584 (Source
: Bounded_String
;
586 High
: Natural) return Bounded_String
589 procedure Bounded_Slice
590 (Source
: Bounded_String
;
591 Target
: out Bounded_String
;
597 (Left
: Bounded_String
;
598 Right
: Bounded_String
) return Boolean
602 (Left
: Bounded_String
;
603 Right
: String) return Boolean
608 Right
: Bounded_String
) return Boolean
612 (Left
: Bounded_String
;
613 Right
: Bounded_String
) return Boolean
617 (Left
: Bounded_String
;
618 Right
: String) return Boolean
623 Right
: Bounded_String
) return Boolean
627 (Left
: Bounded_String
;
628 Right
: Bounded_String
) return Boolean
629 renames Less_Or_Equal
;
632 (Left
: Bounded_String
;
633 Right
: String) return Boolean
634 renames Less_Or_Equal
;
638 Right
: Bounded_String
) return Boolean
639 renames Less_Or_Equal
;
642 (Left
: Bounded_String
;
643 Right
: Bounded_String
) return Boolean
647 (Left
: Bounded_String
;
648 Right
: String) return Boolean
653 Right
: Bounded_String
) return Boolean
657 (Left
: Bounded_String
;
658 Right
: Bounded_String
) return Boolean
659 renames Greater_Or_Equal
;
662 (Left
: Bounded_String
;
663 Right
: String) return Boolean
664 renames Greater_Or_Equal
;
668 Right
: Bounded_String
) return Boolean
669 renames Greater_Or_Equal
;
672 (Source
: Bounded_String
;
674 Going
: Direction
:= Forward
;
675 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural
679 (Source
: Bounded_String
;
681 Going
: Direction
:= Forward
;
682 Mapping
: Maps
.Character_Mapping_Function
) return Natural
686 (Source
: Bounded_String
;
687 Set
: Maps
.Character_Set
;
688 Test
: Membership
:= Inside
;
689 Going
: Direction
:= Forward
) return Natural
693 (Source
: Bounded_String
;
696 Going
: Direction
:= Forward
;
697 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural
701 (Source
: Bounded_String
;
704 Going
: Direction
:= Forward
;
705 Mapping
: Maps
.Character_Mapping_Function
) return Natural
709 (Source
: Bounded_String
;
710 Set
: Maps
.Character_Set
;
712 Test
: Membership
:= Inside
;
713 Going
: Direction
:= Forward
) return Natural
716 function Index_Non_Blank
717 (Source
: Bounded_String
;
718 Going
: Direction
:= Forward
) return Natural
719 renames Super_Index_Non_Blank
;
721 function Index_Non_Blank
722 (Source
: Bounded_String
;
724 Going
: Direction
:= Forward
) return Natural
725 renames Super_Index_Non_Blank
;
728 (Source
: Bounded_String
;
730 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural
734 (Source
: Bounded_String
;
736 Mapping
: Maps
.Character_Mapping_Function
) return Natural
740 (Source
: Bounded_String
;
741 Set
: Maps
.Character_Set
) return Natural
745 (Source
: Bounded_String
;
746 Set
: Maps
.Character_Set
;
748 First
: out Positive;
750 renames Super_Find_Token
;
753 (Source
: Bounded_String
;
754 Mapping
: Maps
.Character_Mapping
) return Bounded_String
755 renames Super_Translate
;
758 (Source
: in out Bounded_String
;
759 Mapping
: Maps
.Character_Mapping
)
760 renames Super_Translate
;
763 (Source
: Bounded_String
;
764 Mapping
: Maps
.Character_Mapping_Function
) return Bounded_String
765 renames Super_Translate
;
768 (Source
: in out Bounded_String
;
769 Mapping
: Maps
.Character_Mapping_Function
)
770 renames Super_Translate
;
772 function Replace_Slice
773 (Source
: Bounded_String
;
777 Drop
: Truncation
:= Error
) return Bounded_String
778 renames Super_Replace_Slice
;
780 procedure Replace_Slice
781 (Source
: in out Bounded_String
;
785 Drop
: Truncation
:= Error
)
786 renames Super_Replace_Slice
;
789 (Source
: Bounded_String
;
792 Drop
: Truncation
:= Error
) return Bounded_String
793 renames Super_Insert
;
796 (Source
: in out Bounded_String
;
799 Drop
: Truncation
:= Error
)
800 renames Super_Insert
;
803 (Source
: Bounded_String
;
806 Drop
: Truncation
:= Error
) return Bounded_String
807 renames Super_Overwrite
;
810 (Source
: in out Bounded_String
;
813 Drop
: Truncation
:= Error
)
814 renames Super_Overwrite
;
817 (Source
: Bounded_String
;
819 Through
: Natural) return Bounded_String
820 renames Super_Delete
;
823 (Source
: in out Bounded_String
;
826 renames Super_Delete
;
829 (Source
: Bounded_String
;
830 Side
: Trim_End
) return Bounded_String
834 (Source
: in out Bounded_String
;
839 (Source
: Bounded_String
;
840 Left
: Maps
.Character_Set
;
841 Right
: Maps
.Character_Set
) return Bounded_String
845 (Source
: in out Bounded_String
;
846 Left
: Maps
.Character_Set
;
847 Right
: Maps
.Character_Set
)
851 (Source
: Bounded_String
;
853 Pad
: Character := Space
;
854 Drop
: Truncation
:= Error
) return Bounded_String
858 (Source
: in out Bounded_String
;
860 Pad
: Character := Space
;
861 Drop
: Truncation
:= Error
)
865 (Source
: Bounded_String
;
867 Pad
: Character := Space
;
868 Drop
: Truncation
:= Error
) return Bounded_String
872 (Source
: in out Bounded_String
;
874 Pad
: Character := Space
;
875 Drop
: Truncation
:= Error
)
880 Right
: Bounded_String
) return Bounded_String
885 Item
: Bounded_String
;
886 Drop
: Truncation
:= Error
) return Bounded_String
887 renames Super_Replicate
;
889 end Generic_Bounded_Length
;
891 end Ada
.Strings
.Bounded
;