PR c++/43856
[official-gcc/constexpr.git] / gcc / ada / a-strbou.ads
blob3d9276399fc4078e33b850768e0bbb9839035dfe
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . S T R I N G S . B O U N D E D --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2009, 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 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. --
21 -- --
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. --
25 -- --
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/>. --
30 -- --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 -- --
34 ------------------------------------------------------------------------------
36 with Ada.Strings.Maps;
37 with Ada.Strings.Superbounded;
39 package Ada.Strings.Bounded is
40 pragma Preelaborate;
42 generic
43 Max : Positive;
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
64 (Source : 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;
71 Source : String;
72 Drop : Truncation := Error);
73 pragma Ada_05 (Set_Bounded_String);
75 function Append
76 (Left : Bounded_String;
77 Right : Bounded_String;
78 Drop : Truncation := Error) return Bounded_String;
80 function Append
81 (Left : Bounded_String;
82 Right : String;
83 Drop : Truncation := Error) return Bounded_String;
85 function Append
86 (Left : String;
87 Right : Bounded_String;
88 Drop : Truncation := Error) return Bounded_String;
90 function Append
91 (Left : Bounded_String;
92 Right : Character;
93 Drop : Truncation := Error) return Bounded_String;
95 function Append
96 (Left : Character;
97 Right : Bounded_String;
98 Drop : Truncation := Error) return Bounded_String;
100 procedure Append
101 (Source : in out Bounded_String;
102 New_Item : Bounded_String;
103 Drop : Truncation := Error);
105 procedure Append
106 (Source : in out Bounded_String;
107 New_Item : String;
108 Drop : Truncation := Error);
110 procedure Append
111 (Source : in out Bounded_String;
112 New_Item : Character;
113 Drop : Truncation := Error);
115 function "&"
116 (Left : Bounded_String;
117 Right : Bounded_String) return Bounded_String;
119 function "&"
120 (Left : Bounded_String;
121 Right : String) return Bounded_String;
123 function "&"
124 (Left : String;
125 Right : Bounded_String) return Bounded_String;
127 function "&"
128 (Left : Bounded_String;
129 Right : Character) return Bounded_String;
131 function "&"
132 (Left : Character;
133 Right : Bounded_String) return Bounded_String;
135 function Element
136 (Source : Bounded_String;
137 Index : Positive) return Character;
139 procedure Replace_Element
140 (Source : in out Bounded_String;
141 Index : Positive;
142 By : Character);
144 function Slice
145 (Source : Bounded_String;
146 Low : Positive;
147 High : Natural) return String;
149 function Bounded_Slice
150 (Source : Bounded_String;
151 Low : Positive;
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;
158 Low : Positive;
159 High : Natural);
160 pragma Ada_05 (Bounded_Slice);
162 function "="
163 (Left : Bounded_String;
164 Right : Bounded_String) return Boolean;
166 function "="
167 (Left : Bounded_String;
168 Right : String) return Boolean;
170 function "="
171 (Left : String;
172 Right : Bounded_String) return Boolean;
174 function "<"
175 (Left : Bounded_String;
176 Right : Bounded_String) return Boolean;
178 function "<"
179 (Left : Bounded_String;
180 Right : String) return Boolean;
182 function "<"
183 (Left : String;
184 Right : Bounded_String) return Boolean;
186 function "<="
187 (Left : Bounded_String;
188 Right : Bounded_String) return Boolean;
190 function "<="
191 (Left : Bounded_String;
192 Right : String) return Boolean;
194 function "<="
195 (Left : String;
196 Right : Bounded_String) return Boolean;
198 function ">"
199 (Left : Bounded_String;
200 Right : Bounded_String) return Boolean;
202 function ">"
203 (Left : Bounded_String;
204 Right : String) return Boolean;
206 function ">"
207 (Left : String;
208 Right : Bounded_String) return Boolean;
210 function ">="
211 (Left : Bounded_String;
212 Right : Bounded_String) return Boolean;
214 function ">="
215 (Left : Bounded_String;
216 Right : String) return Boolean;
218 function ">="
219 (Left : String;
220 Right : Bounded_String) return Boolean;
222 ----------------------
223 -- Search Functions --
224 ----------------------
226 function Index
227 (Source : Bounded_String;
228 Pattern : String;
229 Going : Direction := Forward;
230 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
232 function Index
233 (Source : Bounded_String;
234 Pattern : String;
235 Going : Direction := Forward;
236 Mapping : Maps.Character_Mapping_Function) return Natural;
238 function Index
239 (Source : Bounded_String;
240 Set : Maps.Character_Set;
241 Test : Membership := Inside;
242 Going : Direction := Forward) return Natural;
244 function Index
245 (Source : Bounded_String;
246 Pattern : String;
247 From : Positive;
248 Going : Direction := Forward;
249 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
250 pragma Ada_05 (Index);
252 function Index
253 (Source : Bounded_String;
254 Pattern : String;
255 From : Positive;
256 Going : Direction := Forward;
257 Mapping : Maps.Character_Mapping_Function) return Natural;
258 pragma Ada_05 (Index);
260 function Index
261 (Source : Bounded_String;
262 Set : Maps.Character_Set;
263 From : Positive;
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;
274 From : Positive;
275 Going : Direction := Forward) return Natural;
276 pragma Ada_05 (Index_Non_Blank);
278 function Count
279 (Source : Bounded_String;
280 Pattern : String;
281 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
283 function Count
284 (Source : Bounded_String;
285 Pattern : String;
286 Mapping : Maps.Character_Mapping_Function) return Natural;
288 function Count
289 (Source : Bounded_String;
290 Set : Maps.Character_Set) return Natural;
292 procedure Find_Token
293 (Source : Bounded_String;
294 Set : Maps.Character_Set;
295 Test : Membership;
296 First : out Positive;
297 Last : out Natural);
299 ------------------------------------
300 -- String Translation Subprograms --
301 ------------------------------------
303 function Translate
304 (Source : Bounded_String;
305 Mapping : Maps.Character_Mapping) return Bounded_String;
307 procedure Translate
308 (Source : in out Bounded_String;
309 Mapping : Maps.Character_Mapping);
311 function Translate
312 (Source : Bounded_String;
313 Mapping : Maps.Character_Mapping_Function) return Bounded_String;
315 procedure Translate
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;
325 Low : Positive;
326 High : Natural;
327 By : String;
328 Drop : Truncation := Error) return Bounded_String;
330 procedure Replace_Slice
331 (Source : in out Bounded_String;
332 Low : Positive;
333 High : Natural;
334 By : String;
335 Drop : Truncation := Error);
337 function Insert
338 (Source : Bounded_String;
339 Before : Positive;
340 New_Item : String;
341 Drop : Truncation := Error) return Bounded_String;
343 procedure Insert
344 (Source : in out Bounded_String;
345 Before : Positive;
346 New_Item : String;
347 Drop : Truncation := Error);
349 function Overwrite
350 (Source : Bounded_String;
351 Position : Positive;
352 New_Item : String;
353 Drop : Truncation := Error) return Bounded_String;
355 procedure Overwrite
356 (Source : in out Bounded_String;
357 Position : Positive;
358 New_Item : String;
359 Drop : Truncation := Error);
361 function Delete
362 (Source : Bounded_String;
363 From : Positive;
364 Through : Natural) return Bounded_String;
366 procedure Delete
367 (Source : in out Bounded_String;
368 From : Positive;
369 Through : Natural);
371 ---------------------------------
372 -- String Selector Subprograms --
373 ---------------------------------
375 function Trim
376 (Source : Bounded_String;
377 Side : Trim_End) return Bounded_String;
379 procedure Trim
380 (Source : in out Bounded_String;
381 Side : Trim_End);
383 function Trim
384 (Source : Bounded_String;
385 Left : Maps.Character_Set;
386 Right : Maps.Character_Set) return Bounded_String;
388 procedure Trim
389 (Source : in out Bounded_String;
390 Left : Maps.Character_Set;
391 Right : Maps.Character_Set);
393 function Head
394 (Source : Bounded_String;
395 Count : Natural;
396 Pad : Character := Space;
397 Drop : Truncation := Error) return Bounded_String;
399 procedure Head
400 (Source : in out Bounded_String;
401 Count : Natural;
402 Pad : Character := Space;
403 Drop : Truncation := Error);
405 function Tail
406 (Source : Bounded_String;
407 Count : Natural;
408 Pad : Character := Space;
409 Drop : Truncation := Error) return Bounded_String;
411 procedure Tail
412 (Source : in out Bounded_String;
413 Count : Natural;
414 Pad : Character := Space;
415 Drop : Truncation := Error);
417 ------------------------------------
418 -- String Constructor Subprograms --
419 ------------------------------------
421 function "*"
422 (Left : Natural;
423 Right : Character) return Bounded_String;
425 function "*"
426 (Left : Natural;
427 Right : String) return Bounded_String;
429 function "*"
430 (Left : Natural;
431 Right : Bounded_String) return Bounded_String;
433 function Replicate
434 (Count : Natural;
435 Item : Character;
436 Drop : Truncation := Error) return Bounded_String;
438 function Replicate
439 (Count : Natural;
440 Item : String;
441 Drop : Truncation := Error) return Bounded_String;
443 function Replicate
444 (Count : Natural;
445 Item : Bounded_String;
446 Drop : Truncation := Error) return Bounded_String;
448 private
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,
478 Current_Length => 0,
479 Data =>
480 (1 .. Max_Length => ASCII.NUL));
482 pragma Inline (To_Bounded_String);
484 procedure Set_Bounded_String
485 (Target : out Bounded_String;
486 Source : String;
487 Drop : Truncation := Error)
488 renames Set_Super_String;
490 function Length
491 (Source : Bounded_String) return Length_Range
492 renames Super_Length;
494 function To_String
495 (Source : Bounded_String) return String
496 renames Super_To_String;
498 function Append
499 (Left : Bounded_String;
500 Right : Bounded_String;
501 Drop : Truncation := Error) return Bounded_String
502 renames Super_Append;
504 function Append
505 (Left : Bounded_String;
506 Right : String;
507 Drop : Truncation := Error) return Bounded_String
508 renames Super_Append;
510 function Append
511 (Left : String;
512 Right : Bounded_String;
513 Drop : Truncation := Error) return Bounded_String
514 renames Super_Append;
516 function Append
517 (Left : Bounded_String;
518 Right : Character;
519 Drop : Truncation := Error) return Bounded_String
520 renames Super_Append;
522 function Append
523 (Left : Character;
524 Right : Bounded_String;
525 Drop : Truncation := Error) return Bounded_String
526 renames Super_Append;
528 procedure Append
529 (Source : in out Bounded_String;
530 New_Item : Bounded_String;
531 Drop : Truncation := Error)
532 renames Super_Append;
534 procedure Append
535 (Source : in out Bounded_String;
536 New_Item : String;
537 Drop : Truncation := Error)
538 renames Super_Append;
540 procedure Append
541 (Source : in out Bounded_String;
542 New_Item : Character;
543 Drop : Truncation := Error)
544 renames Super_Append;
546 function "&"
547 (Left : Bounded_String;
548 Right : Bounded_String) return Bounded_String
549 renames Concat;
551 function "&"
552 (Left : Bounded_String;
553 Right : String) return Bounded_String
554 renames Concat;
556 function "&"
557 (Left : String;
558 Right : Bounded_String) return Bounded_String
559 renames Concat;
561 function "&"
562 (Left : Bounded_String;
563 Right : Character) return Bounded_String
564 renames Concat;
566 function "&"
567 (Left : Character;
568 Right : Bounded_String) return Bounded_String
569 renames Concat;
571 function Element
572 (Source : Bounded_String;
573 Index : Positive) return Character
574 renames Super_Element;
576 procedure Replace_Element
577 (Source : in out Bounded_String;
578 Index : Positive;
579 By : Character)
580 renames Super_Replace_Element;
582 function Slice
583 (Source : Bounded_String;
584 Low : Positive;
585 High : Natural) return String
586 renames Super_Slice;
588 function Bounded_Slice
589 (Source : Bounded_String;
590 Low : Positive;
591 High : Natural) return Bounded_String
592 renames Super_Slice;
594 procedure Bounded_Slice
595 (Source : Bounded_String;
596 Target : out Bounded_String;
597 Low : Positive;
598 High : Natural)
599 renames Super_Slice;
601 function "="
602 (Left : Bounded_String;
603 Right : Bounded_String) return Boolean
604 renames Equal;
606 function "="
607 (Left : Bounded_String;
608 Right : String) return Boolean
609 renames Equal;
611 function "="
612 (Left : String;
613 Right : Bounded_String) return Boolean
614 renames Equal;
616 function "<"
617 (Left : Bounded_String;
618 Right : Bounded_String) return Boolean
619 renames Less;
621 function "<"
622 (Left : Bounded_String;
623 Right : String) return Boolean
624 renames Less;
626 function "<"
627 (Left : String;
628 Right : Bounded_String) return Boolean
629 renames Less;
631 function "<="
632 (Left : Bounded_String;
633 Right : Bounded_String) return Boolean
634 renames Less_Or_Equal;
636 function "<="
637 (Left : Bounded_String;
638 Right : String) return Boolean
639 renames Less_Or_Equal;
641 function "<="
642 (Left : String;
643 Right : Bounded_String) return Boolean
644 renames Less_Or_Equal;
646 function ">"
647 (Left : Bounded_String;
648 Right : Bounded_String) return Boolean
649 renames Greater;
651 function ">"
652 (Left : Bounded_String;
653 Right : String) return Boolean
654 renames Greater;
656 function ">"
657 (Left : String;
658 Right : Bounded_String) return Boolean
659 renames Greater;
661 function ">="
662 (Left : Bounded_String;
663 Right : Bounded_String) return Boolean
664 renames Greater_Or_Equal;
666 function ">="
667 (Left : Bounded_String;
668 Right : String) return Boolean
669 renames Greater_Or_Equal;
671 function ">="
672 (Left : String;
673 Right : Bounded_String) return Boolean
674 renames Greater_Or_Equal;
676 function Index
677 (Source : Bounded_String;
678 Pattern : String;
679 Going : Direction := Forward;
680 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
681 renames Super_Index;
683 function Index
684 (Source : Bounded_String;
685 Pattern : String;
686 Going : Direction := Forward;
687 Mapping : Maps.Character_Mapping_Function) return Natural
688 renames Super_Index;
690 function Index
691 (Source : Bounded_String;
692 Set : Maps.Character_Set;
693 Test : Membership := Inside;
694 Going : Direction := Forward) return Natural
695 renames Super_Index;
697 function Index
698 (Source : Bounded_String;
699 Pattern : String;
700 From : Positive;
701 Going : Direction := Forward;
702 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
703 renames Super_Index;
705 function Index
706 (Source : Bounded_String;
707 Pattern : String;
708 From : Positive;
709 Going : Direction := Forward;
710 Mapping : Maps.Character_Mapping_Function) return Natural
711 renames Super_Index;
713 function Index
714 (Source : Bounded_String;
715 Set : Maps.Character_Set;
716 From : Positive;
717 Test : Membership := Inside;
718 Going : Direction := Forward) return Natural
719 renames Super_Index;
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;
728 From : Positive;
729 Going : Direction := Forward) return Natural
730 renames Super_Index_Non_Blank;
732 function Count
733 (Source : Bounded_String;
734 Pattern : String;
735 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
736 renames Super_Count;
738 function Count
739 (Source : Bounded_String;
740 Pattern : String;
741 Mapping : Maps.Character_Mapping_Function) return Natural
742 renames Super_Count;
744 function Count
745 (Source : Bounded_String;
746 Set : Maps.Character_Set) return Natural
747 renames Super_Count;
749 procedure Find_Token
750 (Source : Bounded_String;
751 Set : Maps.Character_Set;
752 Test : Membership;
753 First : out Positive;
754 Last : out Natural)
755 renames Super_Find_Token;
757 function Translate
758 (Source : Bounded_String;
759 Mapping : Maps.Character_Mapping) return Bounded_String
760 renames Super_Translate;
762 procedure Translate
763 (Source : in out Bounded_String;
764 Mapping : Maps.Character_Mapping)
765 renames Super_Translate;
767 function Translate
768 (Source : Bounded_String;
769 Mapping : Maps.Character_Mapping_Function) return Bounded_String
770 renames Super_Translate;
772 procedure 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;
779 Low : Positive;
780 High : Natural;
781 By : String;
782 Drop : Truncation := Error) return Bounded_String
783 renames Super_Replace_Slice;
785 procedure Replace_Slice
786 (Source : in out Bounded_String;
787 Low : Positive;
788 High : Natural;
789 By : String;
790 Drop : Truncation := Error)
791 renames Super_Replace_Slice;
793 function Insert
794 (Source : Bounded_String;
795 Before : Positive;
796 New_Item : String;
797 Drop : Truncation := Error) return Bounded_String
798 renames Super_Insert;
800 procedure Insert
801 (Source : in out Bounded_String;
802 Before : Positive;
803 New_Item : String;
804 Drop : Truncation := Error)
805 renames Super_Insert;
807 function Overwrite
808 (Source : Bounded_String;
809 Position : Positive;
810 New_Item : String;
811 Drop : Truncation := Error) return Bounded_String
812 renames Super_Overwrite;
814 procedure Overwrite
815 (Source : in out Bounded_String;
816 Position : Positive;
817 New_Item : String;
818 Drop : Truncation := Error)
819 renames Super_Overwrite;
821 function Delete
822 (Source : Bounded_String;
823 From : Positive;
824 Through : Natural) return Bounded_String
825 renames Super_Delete;
827 procedure Delete
828 (Source : in out Bounded_String;
829 From : Positive;
830 Through : Natural)
831 renames Super_Delete;
833 function Trim
834 (Source : Bounded_String;
835 Side : Trim_End) return Bounded_String
836 renames Super_Trim;
838 procedure Trim
839 (Source : in out Bounded_String;
840 Side : Trim_End)
841 renames Super_Trim;
843 function Trim
844 (Source : Bounded_String;
845 Left : Maps.Character_Set;
846 Right : Maps.Character_Set) return Bounded_String
847 renames Super_Trim;
849 procedure Trim
850 (Source : in out Bounded_String;
851 Left : Maps.Character_Set;
852 Right : Maps.Character_Set)
853 renames Super_Trim;
855 function Head
856 (Source : Bounded_String;
857 Count : Natural;
858 Pad : Character := Space;
859 Drop : Truncation := Error) return Bounded_String
860 renames Super_Head;
862 procedure Head
863 (Source : in out Bounded_String;
864 Count : Natural;
865 Pad : Character := Space;
866 Drop : Truncation := Error)
867 renames Super_Head;
869 function Tail
870 (Source : Bounded_String;
871 Count : Natural;
872 Pad : Character := Space;
873 Drop : Truncation := Error) return Bounded_String
874 renames Super_Tail;
876 procedure Tail
877 (Source : in out Bounded_String;
878 Count : Natural;
879 Pad : Character := Space;
880 Drop : Truncation := Error)
881 renames Super_Tail;
883 function "*"
884 (Left : Natural;
885 Right : Bounded_String) return Bounded_String
886 renames Times;
888 function Replicate
889 (Count : Natural;
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;