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-2009, 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
;
296 First
: out Positive;
299 ------------------------------------
300 -- String Translation Subprograms --
301 ------------------------------------
304 (Source
: Bounded_String
;
305 Mapping
: Maps
.Character_Mapping
) return Bounded_String
;
308 (Source
: in out Bounded_String
;
309 Mapping
: Maps
.Character_Mapping
);
312 (Source
: Bounded_String
;
313 Mapping
: Maps
.Character_Mapping_Function
) return Bounded_String
;
316 (Source
: in out Bounded_String
;
317 Mapping
: Maps
.Character_Mapping_Function
);
319 ---------------------------------------
320 -- String Transformation Subprograms --
321 ---------------------------------------
323 function Replace_Slice
324 (Source
: Bounded_String
;
328 Drop
: Truncation
:= Error
) return Bounded_String
;
330 procedure Replace_Slice
331 (Source
: in out Bounded_String
;
335 Drop
: Truncation
:= Error
);
338 (Source
: Bounded_String
;
341 Drop
: Truncation
:= Error
) return Bounded_String
;
344 (Source
: in out Bounded_String
;
347 Drop
: Truncation
:= Error
);
350 (Source
: Bounded_String
;
353 Drop
: Truncation
:= Error
) return Bounded_String
;
356 (Source
: in out Bounded_String
;
359 Drop
: Truncation
:= Error
);
362 (Source
: Bounded_String
;
364 Through
: Natural) return Bounded_String
;
367 (Source
: in out Bounded_String
;
371 ---------------------------------
372 -- String Selector Subprograms --
373 ---------------------------------
376 (Source
: Bounded_String
;
377 Side
: Trim_End
) return Bounded_String
;
380 (Source
: in out Bounded_String
;
384 (Source
: Bounded_String
;
385 Left
: Maps
.Character_Set
;
386 Right
: Maps
.Character_Set
) return Bounded_String
;
389 (Source
: in out Bounded_String
;
390 Left
: Maps
.Character_Set
;
391 Right
: Maps
.Character_Set
);
394 (Source
: Bounded_String
;
396 Pad
: Character := Space
;
397 Drop
: Truncation
:= Error
) return Bounded_String
;
400 (Source
: in out Bounded_String
;
402 Pad
: Character := Space
;
403 Drop
: Truncation
:= Error
);
406 (Source
: Bounded_String
;
408 Pad
: Character := Space
;
409 Drop
: Truncation
:= Error
) return Bounded_String
;
412 (Source
: in out Bounded_String
;
414 Pad
: Character := Space
;
415 Drop
: Truncation
:= Error
);
417 ------------------------------------
418 -- String Constructor Subprograms --
419 ------------------------------------
423 Right
: Character) return Bounded_String
;
427 Right
: String) return Bounded_String
;
431 Right
: Bounded_String
) return Bounded_String
;
436 Drop
: Truncation
:= Error
) return Bounded_String
;
441 Drop
: Truncation
:= Error
) return Bounded_String
;
445 Item
: Bounded_String
;
446 Drop
: Truncation
:= Error
) return Bounded_String
;
449 -- Most of the implementation is in the separate non generic package
450 -- Ada.Strings.Superbounded. Type Bounded_String is derived from type
451 -- Superbounded.Super_String with the maximum length constraint. In
452 -- almost all cases, the routines in Superbounded can be called with
453 -- no requirement to pass the maximum length explicitly, since there
454 -- is at least one Bounded_String argument from which the maximum
455 -- length can be obtained. For all such routines, the implementation
456 -- in this private part is simply a renaming of the corresponding
457 -- routine in the superbounded package.
459 -- The five exceptions are the * and Replicate routines operating on
460 -- character values. For these cases, we have a routine in the body
461 -- that calls the superbounded routine passing the maximum length
462 -- explicitly as an extra parameter.
464 type Bounded_String
is new Superbounded
.Super_String
(Max_Length
);
465 -- Deriving Bounded_String from Superbounded.Super_String is the
466 -- real trick, it ensures that the type Bounded_String declared in
467 -- the generic instantiation is compatible with the Super_String
468 -- type declared in the Superbounded package.
470 function From_String
(Source
: String) return Bounded_String
;
471 -- Private routine used only by Stream_Convert
473 pragma Stream_Convert
(Bounded_String
, From_String
, To_String
);
474 -- Provide stream routines without dragging in Ada.Streams
476 Null_Bounded_String
: constant Bounded_String
:=
477 (Max_Length
=> Max_Length
,
480 (1 .. Max_Length
=> ASCII
.NUL
));
482 pragma Inline
(To_Bounded_String
);
484 procedure Set_Bounded_String
485 (Target
: out Bounded_String
;
487 Drop
: Truncation
:= Error
)
488 renames Set_Super_String
;
491 (Source
: Bounded_String
) return Length_Range
492 renames Super_Length
;
495 (Source
: Bounded_String
) return String
496 renames Super_To_String
;
499 (Left
: Bounded_String
;
500 Right
: Bounded_String
;
501 Drop
: Truncation
:= Error
) return Bounded_String
502 renames Super_Append
;
505 (Left
: Bounded_String
;
507 Drop
: Truncation
:= Error
) return Bounded_String
508 renames Super_Append
;
512 Right
: Bounded_String
;
513 Drop
: Truncation
:= Error
) return Bounded_String
514 renames Super_Append
;
517 (Left
: Bounded_String
;
519 Drop
: Truncation
:= Error
) return Bounded_String
520 renames Super_Append
;
524 Right
: Bounded_String
;
525 Drop
: Truncation
:= Error
) return Bounded_String
526 renames Super_Append
;
529 (Source
: in out Bounded_String
;
530 New_Item
: Bounded_String
;
531 Drop
: Truncation
:= Error
)
532 renames Super_Append
;
535 (Source
: in out Bounded_String
;
537 Drop
: Truncation
:= Error
)
538 renames Super_Append
;
541 (Source
: in out Bounded_String
;
542 New_Item
: Character;
543 Drop
: Truncation
:= Error
)
544 renames Super_Append
;
547 (Left
: Bounded_String
;
548 Right
: Bounded_String
) return Bounded_String
552 (Left
: Bounded_String
;
553 Right
: String) return Bounded_String
558 Right
: Bounded_String
) return Bounded_String
562 (Left
: Bounded_String
;
563 Right
: Character) return Bounded_String
568 Right
: Bounded_String
) return Bounded_String
572 (Source
: Bounded_String
;
573 Index
: Positive) return Character
574 renames Super_Element
;
576 procedure Replace_Element
577 (Source
: in out Bounded_String
;
580 renames Super_Replace_Element
;
583 (Source
: Bounded_String
;
585 High
: Natural) return String
588 function Bounded_Slice
589 (Source
: Bounded_String
;
591 High
: Natural) return Bounded_String
594 procedure Bounded_Slice
595 (Source
: Bounded_String
;
596 Target
: out Bounded_String
;
602 (Left
: Bounded_String
;
603 Right
: Bounded_String
) return Boolean
607 (Left
: Bounded_String
;
608 Right
: String) return Boolean
613 Right
: Bounded_String
) return Boolean
617 (Left
: Bounded_String
;
618 Right
: Bounded_String
) return Boolean
622 (Left
: Bounded_String
;
623 Right
: String) return Boolean
628 Right
: Bounded_String
) return Boolean
632 (Left
: Bounded_String
;
633 Right
: Bounded_String
) return Boolean
634 renames Less_Or_Equal
;
637 (Left
: Bounded_String
;
638 Right
: String) return Boolean
639 renames Less_Or_Equal
;
643 Right
: Bounded_String
) return Boolean
644 renames Less_Or_Equal
;
647 (Left
: Bounded_String
;
648 Right
: Bounded_String
) return Boolean
652 (Left
: Bounded_String
;
653 Right
: String) return Boolean
658 Right
: Bounded_String
) return Boolean
662 (Left
: Bounded_String
;
663 Right
: Bounded_String
) return Boolean
664 renames Greater_Or_Equal
;
667 (Left
: Bounded_String
;
668 Right
: String) return Boolean
669 renames Greater_Or_Equal
;
673 Right
: Bounded_String
) return Boolean
674 renames Greater_Or_Equal
;
677 (Source
: Bounded_String
;
679 Going
: Direction
:= Forward
;
680 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural
684 (Source
: Bounded_String
;
686 Going
: Direction
:= Forward
;
687 Mapping
: Maps
.Character_Mapping_Function
) return Natural
691 (Source
: Bounded_String
;
692 Set
: Maps
.Character_Set
;
693 Test
: Membership
:= Inside
;
694 Going
: Direction
:= Forward
) return Natural
698 (Source
: Bounded_String
;
701 Going
: Direction
:= Forward
;
702 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural
706 (Source
: Bounded_String
;
709 Going
: Direction
:= Forward
;
710 Mapping
: Maps
.Character_Mapping_Function
) return Natural
714 (Source
: Bounded_String
;
715 Set
: Maps
.Character_Set
;
717 Test
: Membership
:= Inside
;
718 Going
: Direction
:= Forward
) return Natural
721 function Index_Non_Blank
722 (Source
: Bounded_String
;
723 Going
: Direction
:= Forward
) return Natural
724 renames Super_Index_Non_Blank
;
726 function Index_Non_Blank
727 (Source
: Bounded_String
;
729 Going
: Direction
:= Forward
) return Natural
730 renames Super_Index_Non_Blank
;
733 (Source
: Bounded_String
;
735 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural
739 (Source
: Bounded_String
;
741 Mapping
: Maps
.Character_Mapping_Function
) return Natural
745 (Source
: Bounded_String
;
746 Set
: Maps
.Character_Set
) return Natural
750 (Source
: Bounded_String
;
751 Set
: Maps
.Character_Set
;
753 First
: out Positive;
755 renames Super_Find_Token
;
758 (Source
: Bounded_String
;
759 Mapping
: Maps
.Character_Mapping
) return Bounded_String
760 renames Super_Translate
;
763 (Source
: in out Bounded_String
;
764 Mapping
: Maps
.Character_Mapping
)
765 renames Super_Translate
;
768 (Source
: Bounded_String
;
769 Mapping
: Maps
.Character_Mapping_Function
) return Bounded_String
770 renames Super_Translate
;
773 (Source
: in out Bounded_String
;
774 Mapping
: Maps
.Character_Mapping_Function
)
775 renames Super_Translate
;
777 function Replace_Slice
778 (Source
: Bounded_String
;
782 Drop
: Truncation
:= Error
) return Bounded_String
783 renames Super_Replace_Slice
;
785 procedure Replace_Slice
786 (Source
: in out Bounded_String
;
790 Drop
: Truncation
:= Error
)
791 renames Super_Replace_Slice
;
794 (Source
: Bounded_String
;
797 Drop
: Truncation
:= Error
) return Bounded_String
798 renames Super_Insert
;
801 (Source
: in out Bounded_String
;
804 Drop
: Truncation
:= Error
)
805 renames Super_Insert
;
808 (Source
: Bounded_String
;
811 Drop
: Truncation
:= Error
) return Bounded_String
812 renames Super_Overwrite
;
815 (Source
: in out Bounded_String
;
818 Drop
: Truncation
:= Error
)
819 renames Super_Overwrite
;
822 (Source
: Bounded_String
;
824 Through
: Natural) return Bounded_String
825 renames Super_Delete
;
828 (Source
: in out Bounded_String
;
831 renames Super_Delete
;
834 (Source
: Bounded_String
;
835 Side
: Trim_End
) return Bounded_String
839 (Source
: in out Bounded_String
;
844 (Source
: Bounded_String
;
845 Left
: Maps
.Character_Set
;
846 Right
: Maps
.Character_Set
) return Bounded_String
850 (Source
: in out Bounded_String
;
851 Left
: Maps
.Character_Set
;
852 Right
: Maps
.Character_Set
)
856 (Source
: Bounded_String
;
858 Pad
: Character := Space
;
859 Drop
: Truncation
:= Error
) return Bounded_String
863 (Source
: in out Bounded_String
;
865 Pad
: Character := Space
;
866 Drop
: Truncation
:= Error
)
870 (Source
: Bounded_String
;
872 Pad
: Character := Space
;
873 Drop
: Truncation
:= Error
) return Bounded_String
877 (Source
: in out Bounded_String
;
879 Pad
: Character := Space
;
880 Drop
: Truncation
:= Error
)
885 Right
: Bounded_String
) return Bounded_String
890 Item
: Bounded_String
;
891 Drop
: Truncation
:= Error
) return Bounded_String
892 renames Super_Replicate
;
894 end Generic_Bounded_Length
;
896 end Ada
.Strings
.Bounded
;