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-2010, 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 3, 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. --
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
23 -- additional permissions described in the GCC Runtime Library Exception, --
24 -- version 3.1, as published by the Free Software Foundation. --
26 -- You should have received a copy of the GNU General Public License and --
27 -- a copy of the GCC Runtime Library Exception along with this program; --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
29 -- <http://www.gnu.org/licenses/>. --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
34 ------------------------------------------------------------------------------
36 with Ada
.Strings
.Maps
;
37 with Ada
.Strings
.Superbounded
;
39 package Ada
.Strings
.Bounded
is
44 -- Maximum length of a Bounded_String
46 package Generic_Bounded_Length
is
48 Max_Length
: constant Positive := Max
;
50 type Bounded_String
is private;
51 pragma Preelaborable_Initialization
(Bounded_String
);
53 Null_Bounded_String
: constant Bounded_String
;
55 subtype Length_Range
is Natural range 0 .. Max_Length
;
57 function Length
(Source
: Bounded_String
) return Length_Range
;
59 --------------------------------------------------------
60 -- Conversion, Concatenation, and Selection Functions --
61 --------------------------------------------------------
63 function To_Bounded_String
65 Drop
: Truncation
:= Error
) return Bounded_String
;
67 function To_String
(Source
: Bounded_String
) return String;
69 procedure Set_Bounded_String
70 (Target
: out Bounded_String
;
72 Drop
: Truncation
:= Error
);
73 pragma Ada_05
(Set_Bounded_String
);
76 (Left
: Bounded_String
;
77 Right
: Bounded_String
;
78 Drop
: Truncation
:= Error
) return Bounded_String
;
81 (Left
: Bounded_String
;
83 Drop
: Truncation
:= Error
) return Bounded_String
;
87 Right
: Bounded_String
;
88 Drop
: Truncation
:= Error
) return Bounded_String
;
91 (Left
: Bounded_String
;
93 Drop
: Truncation
:= Error
) return Bounded_String
;
97 Right
: Bounded_String
;
98 Drop
: Truncation
:= Error
) return Bounded_String
;
101 (Source
: in out Bounded_String
;
102 New_Item
: Bounded_String
;
103 Drop
: Truncation
:= Error
);
106 (Source
: in out Bounded_String
;
108 Drop
: Truncation
:= Error
);
111 (Source
: in out Bounded_String
;
112 New_Item
: Character;
113 Drop
: Truncation
:= Error
);
116 (Left
: Bounded_String
;
117 Right
: Bounded_String
) return Bounded_String
;
120 (Left
: Bounded_String
;
121 Right
: String) return Bounded_String
;
125 Right
: Bounded_String
) return Bounded_String
;
128 (Left
: Bounded_String
;
129 Right
: Character) return Bounded_String
;
133 Right
: Bounded_String
) return Bounded_String
;
136 (Source
: Bounded_String
;
137 Index
: Positive) return Character;
139 procedure Replace_Element
140 (Source
: in out Bounded_String
;
145 (Source
: Bounded_String
;
147 High
: Natural) return String;
149 function Bounded_Slice
150 (Source
: Bounded_String
;
152 High
: Natural) return Bounded_String
;
153 pragma Ada_05
(Bounded_Slice
);
155 procedure Bounded_Slice
156 (Source
: Bounded_String
;
157 Target
: out Bounded_String
;
160 pragma Ada_05
(Bounded_Slice
);
163 (Left
: Bounded_String
;
164 Right
: Bounded_String
) return Boolean;
167 (Left
: Bounded_String
;
168 Right
: String) return Boolean;
172 Right
: Bounded_String
) return Boolean;
175 (Left
: Bounded_String
;
176 Right
: Bounded_String
) return Boolean;
179 (Left
: Bounded_String
;
180 Right
: String) return Boolean;
184 Right
: Bounded_String
) return Boolean;
187 (Left
: Bounded_String
;
188 Right
: Bounded_String
) return Boolean;
191 (Left
: Bounded_String
;
192 Right
: String) return Boolean;
196 Right
: Bounded_String
) return Boolean;
199 (Left
: Bounded_String
;
200 Right
: Bounded_String
) return Boolean;
203 (Left
: Bounded_String
;
204 Right
: String) return Boolean;
208 Right
: Bounded_String
) return Boolean;
211 (Left
: Bounded_String
;
212 Right
: Bounded_String
) return Boolean;
215 (Left
: Bounded_String
;
216 Right
: String) return Boolean;
220 Right
: Bounded_String
) return Boolean;
222 ----------------------
223 -- Search Functions --
224 ----------------------
227 (Source
: Bounded_String
;
229 Going
: Direction
:= Forward
;
230 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
233 (Source
: Bounded_String
;
235 Going
: Direction
:= Forward
;
236 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
239 (Source
: Bounded_String
;
240 Set
: Maps
.Character_Set
;
241 Test
: Membership
:= Inside
;
242 Going
: Direction
:= Forward
) return Natural;
245 (Source
: Bounded_String
;
248 Going
: Direction
:= Forward
;
249 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
250 pragma Ada_05
(Index
);
253 (Source
: Bounded_String
;
256 Going
: Direction
:= Forward
;
257 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
258 pragma Ada_05
(Index
);
261 (Source
: Bounded_String
;
262 Set
: Maps
.Character_Set
;
264 Test
: Membership
:= Inside
;
265 Going
: Direction
:= Forward
) return Natural;
266 pragma Ada_05
(Index
);
268 function Index_Non_Blank
269 (Source
: Bounded_String
;
270 Going
: Direction
:= Forward
) return Natural;
272 function Index_Non_Blank
273 (Source
: Bounded_String
;
275 Going
: Direction
:= Forward
) return Natural;
276 pragma Ada_05
(Index_Non_Blank
);
279 (Source
: Bounded_String
;
281 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
284 (Source
: Bounded_String
;
286 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
289 (Source
: Bounded_String
;
290 Set
: Maps
.Character_Set
) return Natural;
293 (Source
: Bounded_String
;
294 Set
: Maps
.Character_Set
;
297 First
: out Positive;
299 pragma Ada_2012
(Find_Token
);
302 (Source
: Bounded_String
;
303 Set
: Maps
.Character_Set
;
305 First
: out Positive;
308 ------------------------------------
309 -- String Translation Subprograms --
310 ------------------------------------
313 (Source
: Bounded_String
;
314 Mapping
: Maps
.Character_Mapping
) return Bounded_String
;
317 (Source
: in out Bounded_String
;
318 Mapping
: Maps
.Character_Mapping
);
321 (Source
: Bounded_String
;
322 Mapping
: Maps
.Character_Mapping_Function
) return Bounded_String
;
325 (Source
: in out Bounded_String
;
326 Mapping
: Maps
.Character_Mapping_Function
);
328 ---------------------------------------
329 -- String Transformation Subprograms --
330 ---------------------------------------
332 function Replace_Slice
333 (Source
: Bounded_String
;
337 Drop
: Truncation
:= Error
) return Bounded_String
;
339 procedure Replace_Slice
340 (Source
: in out Bounded_String
;
344 Drop
: Truncation
:= Error
);
347 (Source
: Bounded_String
;
350 Drop
: Truncation
:= Error
) return Bounded_String
;
353 (Source
: in out Bounded_String
;
356 Drop
: Truncation
:= Error
);
359 (Source
: Bounded_String
;
362 Drop
: Truncation
:= Error
) return Bounded_String
;
365 (Source
: in out Bounded_String
;
368 Drop
: Truncation
:= Error
);
371 (Source
: Bounded_String
;
373 Through
: Natural) return Bounded_String
;
376 (Source
: in out Bounded_String
;
380 ---------------------------------
381 -- String Selector Subprograms --
382 ---------------------------------
385 (Source
: Bounded_String
;
386 Side
: Trim_End
) return Bounded_String
;
389 (Source
: in out Bounded_String
;
393 (Source
: Bounded_String
;
394 Left
: Maps
.Character_Set
;
395 Right
: Maps
.Character_Set
) return Bounded_String
;
398 (Source
: in out Bounded_String
;
399 Left
: Maps
.Character_Set
;
400 Right
: Maps
.Character_Set
);
403 (Source
: Bounded_String
;
405 Pad
: Character := Space
;
406 Drop
: Truncation
:= Error
) return Bounded_String
;
409 (Source
: in out Bounded_String
;
411 Pad
: Character := Space
;
412 Drop
: Truncation
:= Error
);
415 (Source
: Bounded_String
;
417 Pad
: Character := Space
;
418 Drop
: Truncation
:= Error
) return Bounded_String
;
421 (Source
: in out Bounded_String
;
423 Pad
: Character := Space
;
424 Drop
: Truncation
:= Error
);
426 ------------------------------------
427 -- String Constructor Subprograms --
428 ------------------------------------
432 Right
: Character) return Bounded_String
;
436 Right
: String) return Bounded_String
;
440 Right
: Bounded_String
) return Bounded_String
;
445 Drop
: Truncation
:= Error
) return Bounded_String
;
450 Drop
: Truncation
:= Error
) return Bounded_String
;
454 Item
: Bounded_String
;
455 Drop
: Truncation
:= Error
) return Bounded_String
;
458 -- Most of the implementation is in the separate non generic package
459 -- Ada.Strings.Superbounded. Type Bounded_String is derived from type
460 -- Superbounded.Super_String with the maximum length constraint. In
461 -- almost all cases, the routines in Superbounded can be called with
462 -- no requirement to pass the maximum length explicitly, since there
463 -- is at least one Bounded_String argument from which the maximum
464 -- length can be obtained. For all such routines, the implementation
465 -- in this private part is simply a renaming of the corresponding
466 -- routine in the superbounded package.
468 -- The five exceptions are the * and Replicate routines operating on
469 -- character values. For these cases, we have a routine in the body
470 -- that calls the superbounded routine passing the maximum length
471 -- explicitly as an extra parameter.
473 type Bounded_String
is new Superbounded
.Super_String
(Max_Length
);
474 -- Deriving Bounded_String from Superbounded.Super_String is the
475 -- real trick, it ensures that the type Bounded_String declared in
476 -- the generic instantiation is compatible with the Super_String
477 -- type declared in the Superbounded package.
479 function From_String
(Source
: String) return Bounded_String
;
480 -- Private routine used only by Stream_Convert
482 pragma Stream_Convert
(Bounded_String
, From_String
, To_String
);
483 -- Provide stream routines without dragging in Ada.Streams
485 Null_Bounded_String
: constant Bounded_String
:=
486 (Max_Length
=> Max_Length
,
489 (1 .. Max_Length
=> ASCII
.NUL
));
491 pragma Inline
(To_Bounded_String
);
493 procedure Set_Bounded_String
494 (Target
: out Bounded_String
;
496 Drop
: Truncation
:= Error
)
497 renames Set_Super_String
;
500 (Source
: Bounded_String
) return Length_Range
501 renames Super_Length
;
504 (Source
: Bounded_String
) return String
505 renames Super_To_String
;
508 (Left
: Bounded_String
;
509 Right
: Bounded_String
;
510 Drop
: Truncation
:= Error
) return Bounded_String
511 renames Super_Append
;
514 (Left
: Bounded_String
;
516 Drop
: Truncation
:= Error
) return Bounded_String
517 renames Super_Append
;
521 Right
: Bounded_String
;
522 Drop
: Truncation
:= Error
) return Bounded_String
523 renames Super_Append
;
526 (Left
: Bounded_String
;
528 Drop
: Truncation
:= Error
) return Bounded_String
529 renames Super_Append
;
533 Right
: Bounded_String
;
534 Drop
: Truncation
:= Error
) return Bounded_String
535 renames Super_Append
;
538 (Source
: in out Bounded_String
;
539 New_Item
: Bounded_String
;
540 Drop
: Truncation
:= Error
)
541 renames Super_Append
;
544 (Source
: in out Bounded_String
;
546 Drop
: Truncation
:= Error
)
547 renames Super_Append
;
550 (Source
: in out Bounded_String
;
551 New_Item
: Character;
552 Drop
: Truncation
:= Error
)
553 renames Super_Append
;
556 (Left
: Bounded_String
;
557 Right
: Bounded_String
) return Bounded_String
561 (Left
: Bounded_String
;
562 Right
: String) return Bounded_String
567 Right
: Bounded_String
) return Bounded_String
571 (Left
: Bounded_String
;
572 Right
: Character) return Bounded_String
577 Right
: Bounded_String
) return Bounded_String
581 (Source
: Bounded_String
;
582 Index
: Positive) return Character
583 renames Super_Element
;
585 procedure Replace_Element
586 (Source
: in out Bounded_String
;
589 renames Super_Replace_Element
;
592 (Source
: Bounded_String
;
594 High
: Natural) return String
597 function Bounded_Slice
598 (Source
: Bounded_String
;
600 High
: Natural) return Bounded_String
603 procedure Bounded_Slice
604 (Source
: Bounded_String
;
605 Target
: out Bounded_String
;
611 (Left
: Bounded_String
;
612 Right
: Bounded_String
) return Boolean
616 (Left
: Bounded_String
;
617 Right
: String) return Boolean
622 Right
: Bounded_String
) return Boolean
626 (Left
: Bounded_String
;
627 Right
: Bounded_String
) return Boolean
631 (Left
: Bounded_String
;
632 Right
: String) return Boolean
637 Right
: Bounded_String
) return Boolean
641 (Left
: Bounded_String
;
642 Right
: Bounded_String
) return Boolean
643 renames Less_Or_Equal
;
646 (Left
: Bounded_String
;
647 Right
: String) return Boolean
648 renames Less_Or_Equal
;
652 Right
: Bounded_String
) return Boolean
653 renames Less_Or_Equal
;
656 (Left
: Bounded_String
;
657 Right
: Bounded_String
) return Boolean
661 (Left
: Bounded_String
;
662 Right
: String) return Boolean
667 Right
: Bounded_String
) return Boolean
671 (Left
: Bounded_String
;
672 Right
: Bounded_String
) return Boolean
673 renames Greater_Or_Equal
;
676 (Left
: Bounded_String
;
677 Right
: String) return Boolean
678 renames Greater_Or_Equal
;
682 Right
: Bounded_String
) return Boolean
683 renames Greater_Or_Equal
;
686 (Source
: Bounded_String
;
688 Going
: Direction
:= Forward
;
689 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural
693 (Source
: Bounded_String
;
695 Going
: Direction
:= Forward
;
696 Mapping
: Maps
.Character_Mapping_Function
) return Natural
700 (Source
: Bounded_String
;
701 Set
: Maps
.Character_Set
;
702 Test
: Membership
:= Inside
;
703 Going
: Direction
:= Forward
) return Natural
707 (Source
: Bounded_String
;
710 Going
: Direction
:= Forward
;
711 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural
715 (Source
: Bounded_String
;
718 Going
: Direction
:= Forward
;
719 Mapping
: Maps
.Character_Mapping_Function
) return Natural
723 (Source
: Bounded_String
;
724 Set
: Maps
.Character_Set
;
726 Test
: Membership
:= Inside
;
727 Going
: Direction
:= Forward
) return Natural
730 function Index_Non_Blank
731 (Source
: Bounded_String
;
732 Going
: Direction
:= Forward
) return Natural
733 renames Super_Index_Non_Blank
;
735 function Index_Non_Blank
736 (Source
: Bounded_String
;
738 Going
: Direction
:= Forward
) return Natural
739 renames Super_Index_Non_Blank
;
742 (Source
: Bounded_String
;
744 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural
748 (Source
: Bounded_String
;
750 Mapping
: Maps
.Character_Mapping_Function
) return Natural
754 (Source
: Bounded_String
;
755 Set
: Maps
.Character_Set
) return Natural
759 (Source
: Bounded_String
;
760 Set
: Maps
.Character_Set
;
763 First
: out Positive;
765 renames Super_Find_Token
;
768 (Source
: Bounded_String
;
769 Set
: Maps
.Character_Set
;
771 First
: out Positive;
773 renames Super_Find_Token
;
776 (Source
: Bounded_String
;
777 Mapping
: Maps
.Character_Mapping
) return Bounded_String
778 renames Super_Translate
;
781 (Source
: in out Bounded_String
;
782 Mapping
: Maps
.Character_Mapping
)
783 renames Super_Translate
;
786 (Source
: Bounded_String
;
787 Mapping
: Maps
.Character_Mapping_Function
) return Bounded_String
788 renames Super_Translate
;
791 (Source
: in out Bounded_String
;
792 Mapping
: Maps
.Character_Mapping_Function
)
793 renames Super_Translate
;
795 function Replace_Slice
796 (Source
: Bounded_String
;
800 Drop
: Truncation
:= Error
) return Bounded_String
801 renames Super_Replace_Slice
;
803 procedure Replace_Slice
804 (Source
: in out Bounded_String
;
808 Drop
: Truncation
:= Error
)
809 renames Super_Replace_Slice
;
812 (Source
: Bounded_String
;
815 Drop
: Truncation
:= Error
) return Bounded_String
816 renames Super_Insert
;
819 (Source
: in out Bounded_String
;
822 Drop
: Truncation
:= Error
)
823 renames Super_Insert
;
826 (Source
: Bounded_String
;
829 Drop
: Truncation
:= Error
) return Bounded_String
830 renames Super_Overwrite
;
833 (Source
: in out Bounded_String
;
836 Drop
: Truncation
:= Error
)
837 renames Super_Overwrite
;
840 (Source
: Bounded_String
;
842 Through
: Natural) return Bounded_String
843 renames Super_Delete
;
846 (Source
: in out Bounded_String
;
849 renames Super_Delete
;
852 (Source
: Bounded_String
;
853 Side
: Trim_End
) return Bounded_String
857 (Source
: in out Bounded_String
;
862 (Source
: Bounded_String
;
863 Left
: Maps
.Character_Set
;
864 Right
: Maps
.Character_Set
) return Bounded_String
868 (Source
: in out Bounded_String
;
869 Left
: Maps
.Character_Set
;
870 Right
: Maps
.Character_Set
)
874 (Source
: Bounded_String
;
876 Pad
: Character := Space
;
877 Drop
: Truncation
:= Error
) return Bounded_String
881 (Source
: in out Bounded_String
;
883 Pad
: Character := Space
;
884 Drop
: Truncation
:= Error
)
888 (Source
: Bounded_String
;
890 Pad
: Character := Space
;
891 Drop
: Truncation
:= Error
) return Bounded_String
895 (Source
: in out Bounded_String
;
897 Pad
: Character := Space
;
898 Drop
: Truncation
:= Error
)
903 Right
: Bounded_String
) return Bounded_String
908 Item
: Bounded_String
;
909 Drop
: Truncation
:= Error
) return Bounded_String
910 renames Super_Replicate
;
912 end Generic_Bounded_Length
;
914 end Ada
.Strings
.Bounded
;