2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ada / a-strbou.ads
blob9961b638b76cf70c00fbd4c47aed25bbd2140714
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-2008, 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 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. --
25 -- --
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. --
32 -- --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
35 -- --
36 ------------------------------------------------------------------------------
38 with Ada.Strings.Maps;
39 with Ada.Strings.Superbounded;
41 package Ada.Strings.Bounded is
42 pragma Preelaborate;
44 generic
45 Max : Positive;
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;
53 pragma Preelaborable_Initialization (Bounded_String);
55 Null_Bounded_String : constant Bounded_String;
57 subtype Length_Range is Natural range 0 .. Max_Length;
59 function Length (Source : Bounded_String) return Length_Range;
61 --------------------------------------------------------
62 -- Conversion, Concatenation, and Selection Functions --
63 --------------------------------------------------------
65 function To_Bounded_String
66 (Source : String;
67 Drop : Truncation := Error) return Bounded_String;
69 function To_String (Source : Bounded_String) return String;
71 procedure Set_Bounded_String
72 (Target : out Bounded_String;
73 Source : String;
74 Drop : Truncation := Error);
75 pragma Ada_05 (Set_Bounded_String);
77 function Append
78 (Left : Bounded_String;
79 Right : Bounded_String;
80 Drop : Truncation := Error) return Bounded_String;
82 function Append
83 (Left : Bounded_String;
84 Right : String;
85 Drop : Truncation := Error) return Bounded_String;
87 function Append
88 (Left : String;
89 Right : Bounded_String;
90 Drop : Truncation := Error) return Bounded_String;
92 function Append
93 (Left : Bounded_String;
94 Right : Character;
95 Drop : Truncation := Error) return Bounded_String;
97 function Append
98 (Left : Character;
99 Right : Bounded_String;
100 Drop : Truncation := Error) return Bounded_String;
102 procedure Append
103 (Source : in out Bounded_String;
104 New_Item : Bounded_String;
105 Drop : Truncation := Error);
107 procedure Append
108 (Source : in out Bounded_String;
109 New_Item : String;
110 Drop : Truncation := Error);
112 procedure Append
113 (Source : in out Bounded_String;
114 New_Item : Character;
115 Drop : Truncation := Error);
117 function "&"
118 (Left : Bounded_String;
119 Right : Bounded_String) return Bounded_String;
121 function "&"
122 (Left : Bounded_String;
123 Right : String) return Bounded_String;
125 function "&"
126 (Left : String;
127 Right : Bounded_String) return Bounded_String;
129 function "&"
130 (Left : Bounded_String;
131 Right : Character) return Bounded_String;
133 function "&"
134 (Left : Character;
135 Right : Bounded_String) return Bounded_String;
137 function Element
138 (Source : Bounded_String;
139 Index : Positive) return Character;
141 procedure Replace_Element
142 (Source : in out Bounded_String;
143 Index : Positive;
144 By : Character);
146 function Slice
147 (Source : Bounded_String;
148 Low : Positive;
149 High : Natural) return String;
151 function Bounded_Slice
152 (Source : Bounded_String;
153 Low : Positive;
154 High : Natural) return Bounded_String;
155 pragma Ada_05 (Bounded_Slice);
157 procedure Bounded_Slice
158 (Source : Bounded_String;
159 Target : out Bounded_String;
160 Low : Positive;
161 High : Natural);
162 pragma Ada_05 (Bounded_Slice);
164 function "="
165 (Left : Bounded_String;
166 Right : Bounded_String) return Boolean;
168 function "="
169 (Left : Bounded_String;
170 Right : String) return Boolean;
172 function "="
173 (Left : String;
174 Right : Bounded_String) return Boolean;
176 function "<"
177 (Left : Bounded_String;
178 Right : Bounded_String) return Boolean;
180 function "<"
181 (Left : Bounded_String;
182 Right : String) return Boolean;
184 function "<"
185 (Left : String;
186 Right : Bounded_String) return Boolean;
188 function "<="
189 (Left : Bounded_String;
190 Right : Bounded_String) return Boolean;
192 function "<="
193 (Left : Bounded_String;
194 Right : String) return Boolean;
196 function "<="
197 (Left : String;
198 Right : Bounded_String) return Boolean;
200 function ">"
201 (Left : Bounded_String;
202 Right : Bounded_String) return Boolean;
204 function ">"
205 (Left : Bounded_String;
206 Right : String) return Boolean;
208 function ">"
209 (Left : String;
210 Right : Bounded_String) return Boolean;
212 function ">="
213 (Left : Bounded_String;
214 Right : Bounded_String) return Boolean;
216 function ">="
217 (Left : Bounded_String;
218 Right : String) return Boolean;
220 function ">="
221 (Left : String;
222 Right : Bounded_String) return Boolean;
224 ----------------------
225 -- Search Functions --
226 ----------------------
228 function Index
229 (Source : Bounded_String;
230 Pattern : String;
231 Going : Direction := Forward;
232 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
234 function Index
235 (Source : Bounded_String;
236 Pattern : String;
237 Going : Direction := Forward;
238 Mapping : Maps.Character_Mapping_Function) return Natural;
240 function Index
241 (Source : Bounded_String;
242 Set : Maps.Character_Set;
243 Test : Membership := Inside;
244 Going : Direction := Forward) return Natural;
246 function Index
247 (Source : Bounded_String;
248 Pattern : String;
249 From : Positive;
250 Going : Direction := Forward;
251 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
252 pragma Ada_05 (Index);
254 function Index
255 (Source : Bounded_String;
256 Pattern : String;
257 From : Positive;
258 Going : Direction := Forward;
259 Mapping : Maps.Character_Mapping_Function) return Natural;
260 pragma Ada_05 (Index);
262 function Index
263 (Source : Bounded_String;
264 Set : Maps.Character_Set;
265 From : Positive;
266 Test : Membership := Inside;
267 Going : Direction := Forward) return Natural;
268 pragma Ada_05 (Index);
270 function Index_Non_Blank
271 (Source : Bounded_String;
272 Going : Direction := Forward) return Natural;
274 function Index_Non_Blank
275 (Source : Bounded_String;
276 From : Positive;
277 Going : Direction := Forward) return Natural;
278 pragma Ada_05 (Index_Non_Blank);
280 function Count
281 (Source : Bounded_String;
282 Pattern : String;
283 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
285 function Count
286 (Source : Bounded_String;
287 Pattern : String;
288 Mapping : Maps.Character_Mapping_Function) return Natural;
290 function Count
291 (Source : Bounded_String;
292 Set : Maps.Character_Set) return Natural;
294 procedure Find_Token
295 (Source : Bounded_String;
296 Set : Maps.Character_Set;
297 Test : Membership;
298 First : out Positive;
299 Last : out Natural);
301 ------------------------------------
302 -- String Translation Subprograms --
303 ------------------------------------
305 function Translate
306 (Source : Bounded_String;
307 Mapping : Maps.Character_Mapping) return Bounded_String;
309 procedure Translate
310 (Source : in out Bounded_String;
311 Mapping : Maps.Character_Mapping);
313 function Translate
314 (Source : Bounded_String;
315 Mapping : Maps.Character_Mapping_Function) return Bounded_String;
317 procedure Translate
318 (Source : in out Bounded_String;
319 Mapping : Maps.Character_Mapping_Function);
321 ---------------------------------------
322 -- String Transformation Subprograms --
323 ---------------------------------------
325 function Replace_Slice
326 (Source : Bounded_String;
327 Low : Positive;
328 High : Natural;
329 By : String;
330 Drop : Truncation := Error) return Bounded_String;
332 procedure Replace_Slice
333 (Source : in out Bounded_String;
334 Low : Positive;
335 High : Natural;
336 By : String;
337 Drop : Truncation := Error);
339 function Insert
340 (Source : Bounded_String;
341 Before : Positive;
342 New_Item : String;
343 Drop : Truncation := Error) return Bounded_String;
345 procedure Insert
346 (Source : in out Bounded_String;
347 Before : Positive;
348 New_Item : String;
349 Drop : Truncation := Error);
351 function Overwrite
352 (Source : Bounded_String;
353 Position : Positive;
354 New_Item : String;
355 Drop : Truncation := Error) return Bounded_String;
357 procedure Overwrite
358 (Source : in out Bounded_String;
359 Position : Positive;
360 New_Item : String;
361 Drop : Truncation := Error);
363 function Delete
364 (Source : Bounded_String;
365 From : Positive;
366 Through : Natural) return Bounded_String;
368 procedure Delete
369 (Source : in out Bounded_String;
370 From : Positive;
371 Through : Natural);
373 ---------------------------------
374 -- String Selector Subprograms --
375 ---------------------------------
377 function Trim
378 (Source : Bounded_String;
379 Side : Trim_End) return Bounded_String;
381 procedure Trim
382 (Source : in out Bounded_String;
383 Side : Trim_End);
385 function Trim
386 (Source : Bounded_String;
387 Left : Maps.Character_Set;
388 Right : Maps.Character_Set) return Bounded_String;
390 procedure Trim
391 (Source : in out Bounded_String;
392 Left : Maps.Character_Set;
393 Right : Maps.Character_Set);
395 function Head
396 (Source : Bounded_String;
397 Count : Natural;
398 Pad : Character := Space;
399 Drop : Truncation := Error) return Bounded_String;
401 procedure Head
402 (Source : in out Bounded_String;
403 Count : Natural;
404 Pad : Character := Space;
405 Drop : Truncation := Error);
407 function Tail
408 (Source : Bounded_String;
409 Count : Natural;
410 Pad : Character := Space;
411 Drop : Truncation := Error) return Bounded_String;
413 procedure Tail
414 (Source : in out Bounded_String;
415 Count : Natural;
416 Pad : Character := Space;
417 Drop : Truncation := Error);
419 ------------------------------------
420 -- String Constructor Subprograms --
421 ------------------------------------
423 function "*"
424 (Left : Natural;
425 Right : Character) return Bounded_String;
427 function "*"
428 (Left : Natural;
429 Right : String) return Bounded_String;
431 function "*"
432 (Left : Natural;
433 Right : Bounded_String) return Bounded_String;
435 function Replicate
436 (Count : Natural;
437 Item : Character;
438 Drop : Truncation := Error) return Bounded_String;
440 function Replicate
441 (Count : Natural;
442 Item : String;
443 Drop : Truncation := Error) return Bounded_String;
445 function Replicate
446 (Count : Natural;
447 Item : Bounded_String;
448 Drop : Truncation := Error) return Bounded_String;
450 private
451 -- Most of the implementation is in the separate non generic package
452 -- Ada.Strings.Superbounded. Type Bounded_String is derived from type
453 -- Superbounded.Super_String with the maximum length constraint. In
454 -- almost all cases, the routines in Superbounded can be called with
455 -- no requirement to pass the maximum length explicitly, since there
456 -- is at least one Bounded_String argument from which the maximum
457 -- length can be obtained. For all such routines, the implementation
458 -- in this private part is simply a renaming of the corresponding
459 -- routine in the superbounded package.
461 -- The five exceptions are the * and Replicate routines operating on
462 -- character values. For these cases, we have a routine in the body
463 -- that calls the superbounded routine passing the maximum length
464 -- explicitly as an extra parameter.
466 type Bounded_String is new Superbounded.Super_String (Max_Length);
467 -- Deriving Bounded_String from Superbounded.Super_String is the
468 -- real trick, it ensures that the type Bounded_String declared in
469 -- the generic instantiation is compatible with the Super_String
470 -- type declared in the Superbounded package.
472 function From_String (Source : String) return Bounded_String;
473 -- Private routine used only by Stream_Convert
475 pragma Stream_Convert (Bounded_String, From_String, To_String);
476 -- Provide stream routines without dragging in Ada.Streams
478 Null_Bounded_String : constant Bounded_String :=
479 (Max_Length => Max_Length,
480 Current_Length => 0,
481 Data =>
482 (1 .. Max_Length => ASCII.NUL));
484 pragma Inline (To_Bounded_String);
486 procedure Set_Bounded_String
487 (Target : out Bounded_String;
488 Source : String;
489 Drop : Truncation := Error)
490 renames Set_Super_String;
492 function Length
493 (Source : Bounded_String) return Length_Range
494 renames Super_Length;
496 function To_String
497 (Source : Bounded_String) return String
498 renames Super_To_String;
500 function Append
501 (Left : Bounded_String;
502 Right : Bounded_String;
503 Drop : Truncation := Error) return Bounded_String
504 renames Super_Append;
506 function Append
507 (Left : Bounded_String;
508 Right : String;
509 Drop : Truncation := Error) return Bounded_String
510 renames Super_Append;
512 function Append
513 (Left : String;
514 Right : Bounded_String;
515 Drop : Truncation := Error) return Bounded_String
516 renames Super_Append;
518 function Append
519 (Left : Bounded_String;
520 Right : Character;
521 Drop : Truncation := Error) return Bounded_String
522 renames Super_Append;
524 function Append
525 (Left : Character;
526 Right : Bounded_String;
527 Drop : Truncation := Error) return Bounded_String
528 renames Super_Append;
530 procedure Append
531 (Source : in out Bounded_String;
532 New_Item : Bounded_String;
533 Drop : Truncation := Error)
534 renames Super_Append;
536 procedure Append
537 (Source : in out Bounded_String;
538 New_Item : String;
539 Drop : Truncation := Error)
540 renames Super_Append;
542 procedure Append
543 (Source : in out Bounded_String;
544 New_Item : Character;
545 Drop : Truncation := Error)
546 renames Super_Append;
548 function "&"
549 (Left : Bounded_String;
550 Right : Bounded_String) return Bounded_String
551 renames Concat;
553 function "&"
554 (Left : Bounded_String;
555 Right : String) return Bounded_String
556 renames Concat;
558 function "&"
559 (Left : String;
560 Right : Bounded_String) return Bounded_String
561 renames Concat;
563 function "&"
564 (Left : Bounded_String;
565 Right : Character) return Bounded_String
566 renames Concat;
568 function "&"
569 (Left : Character;
570 Right : Bounded_String) return Bounded_String
571 renames Concat;
573 function Element
574 (Source : Bounded_String;
575 Index : Positive) return Character
576 renames Super_Element;
578 procedure Replace_Element
579 (Source : in out Bounded_String;
580 Index : Positive;
581 By : Character)
582 renames Super_Replace_Element;
584 function Slice
585 (Source : Bounded_String;
586 Low : Positive;
587 High : Natural) return String
588 renames Super_Slice;
590 function Bounded_Slice
591 (Source : Bounded_String;
592 Low : Positive;
593 High : Natural) return Bounded_String
594 renames Super_Slice;
596 procedure Bounded_Slice
597 (Source : Bounded_String;
598 Target : out Bounded_String;
599 Low : Positive;
600 High : Natural)
601 renames Super_Slice;
603 function "="
604 (Left : Bounded_String;
605 Right : Bounded_String) return Boolean
606 renames Equal;
608 function "="
609 (Left : Bounded_String;
610 Right : String) return Boolean
611 renames Equal;
613 function "="
614 (Left : String;
615 Right : Bounded_String) return Boolean
616 renames Equal;
618 function "<"
619 (Left : Bounded_String;
620 Right : Bounded_String) return Boolean
621 renames Less;
623 function "<"
624 (Left : Bounded_String;
625 Right : String) return Boolean
626 renames Less;
628 function "<"
629 (Left : String;
630 Right : Bounded_String) return Boolean
631 renames Less;
633 function "<="
634 (Left : Bounded_String;
635 Right : Bounded_String) return Boolean
636 renames Less_Or_Equal;
638 function "<="
639 (Left : Bounded_String;
640 Right : String) return Boolean
641 renames Less_Or_Equal;
643 function "<="
644 (Left : String;
645 Right : Bounded_String) return Boolean
646 renames Less_Or_Equal;
648 function ">"
649 (Left : Bounded_String;
650 Right : Bounded_String) return Boolean
651 renames Greater;
653 function ">"
654 (Left : Bounded_String;
655 Right : String) return Boolean
656 renames Greater;
658 function ">"
659 (Left : String;
660 Right : Bounded_String) return Boolean
661 renames Greater;
663 function ">="
664 (Left : Bounded_String;
665 Right : Bounded_String) return Boolean
666 renames Greater_Or_Equal;
668 function ">="
669 (Left : Bounded_String;
670 Right : String) return Boolean
671 renames Greater_Or_Equal;
673 function ">="
674 (Left : String;
675 Right : Bounded_String) return Boolean
676 renames Greater_Or_Equal;
678 function Index
679 (Source : Bounded_String;
680 Pattern : String;
681 Going : Direction := Forward;
682 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
683 renames Super_Index;
685 function Index
686 (Source : Bounded_String;
687 Pattern : String;
688 Going : Direction := Forward;
689 Mapping : Maps.Character_Mapping_Function) return Natural
690 renames Super_Index;
692 function Index
693 (Source : Bounded_String;
694 Set : Maps.Character_Set;
695 Test : Membership := Inside;
696 Going : Direction := Forward) return Natural
697 renames Super_Index;
699 function Index
700 (Source : Bounded_String;
701 Pattern : String;
702 From : Positive;
703 Going : Direction := Forward;
704 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
705 renames Super_Index;
707 function Index
708 (Source : Bounded_String;
709 Pattern : String;
710 From : Positive;
711 Going : Direction := Forward;
712 Mapping : Maps.Character_Mapping_Function) return Natural
713 renames Super_Index;
715 function Index
716 (Source : Bounded_String;
717 Set : Maps.Character_Set;
718 From : Positive;
719 Test : Membership := Inside;
720 Going : Direction := Forward) return Natural
721 renames Super_Index;
723 function Index_Non_Blank
724 (Source : Bounded_String;
725 Going : Direction := Forward) return Natural
726 renames Super_Index_Non_Blank;
728 function Index_Non_Blank
729 (Source : Bounded_String;
730 From : Positive;
731 Going : Direction := Forward) return Natural
732 renames Super_Index_Non_Blank;
734 function Count
735 (Source : Bounded_String;
736 Pattern : String;
737 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
738 renames Super_Count;
740 function Count
741 (Source : Bounded_String;
742 Pattern : String;
743 Mapping : Maps.Character_Mapping_Function) return Natural
744 renames Super_Count;
746 function Count
747 (Source : Bounded_String;
748 Set : Maps.Character_Set) return Natural
749 renames Super_Count;
751 procedure Find_Token
752 (Source : Bounded_String;
753 Set : Maps.Character_Set;
754 Test : Membership;
755 First : out Positive;
756 Last : out Natural)
757 renames Super_Find_Token;
759 function Translate
760 (Source : Bounded_String;
761 Mapping : Maps.Character_Mapping) return Bounded_String
762 renames Super_Translate;
764 procedure Translate
765 (Source : in out Bounded_String;
766 Mapping : Maps.Character_Mapping)
767 renames Super_Translate;
769 function Translate
770 (Source : Bounded_String;
771 Mapping : Maps.Character_Mapping_Function) return Bounded_String
772 renames Super_Translate;
774 procedure Translate
775 (Source : in out Bounded_String;
776 Mapping : Maps.Character_Mapping_Function)
777 renames Super_Translate;
779 function Replace_Slice
780 (Source : Bounded_String;
781 Low : Positive;
782 High : Natural;
783 By : String;
784 Drop : Truncation := Error) return Bounded_String
785 renames Super_Replace_Slice;
787 procedure Replace_Slice
788 (Source : in out Bounded_String;
789 Low : Positive;
790 High : Natural;
791 By : String;
792 Drop : Truncation := Error)
793 renames Super_Replace_Slice;
795 function Insert
796 (Source : Bounded_String;
797 Before : Positive;
798 New_Item : String;
799 Drop : Truncation := Error) return Bounded_String
800 renames Super_Insert;
802 procedure Insert
803 (Source : in out Bounded_String;
804 Before : Positive;
805 New_Item : String;
806 Drop : Truncation := Error)
807 renames Super_Insert;
809 function Overwrite
810 (Source : Bounded_String;
811 Position : Positive;
812 New_Item : String;
813 Drop : Truncation := Error) return Bounded_String
814 renames Super_Overwrite;
816 procedure Overwrite
817 (Source : in out Bounded_String;
818 Position : Positive;
819 New_Item : String;
820 Drop : Truncation := Error)
821 renames Super_Overwrite;
823 function Delete
824 (Source : Bounded_String;
825 From : Positive;
826 Through : Natural) return Bounded_String
827 renames Super_Delete;
829 procedure Delete
830 (Source : in out Bounded_String;
831 From : Positive;
832 Through : Natural)
833 renames Super_Delete;
835 function Trim
836 (Source : Bounded_String;
837 Side : Trim_End) return Bounded_String
838 renames Super_Trim;
840 procedure Trim
841 (Source : in out Bounded_String;
842 Side : Trim_End)
843 renames Super_Trim;
845 function Trim
846 (Source : Bounded_String;
847 Left : Maps.Character_Set;
848 Right : Maps.Character_Set) return Bounded_String
849 renames Super_Trim;
851 procedure Trim
852 (Source : in out Bounded_String;
853 Left : Maps.Character_Set;
854 Right : Maps.Character_Set)
855 renames Super_Trim;
857 function Head
858 (Source : Bounded_String;
859 Count : Natural;
860 Pad : Character := Space;
861 Drop : Truncation := Error) return Bounded_String
862 renames Super_Head;
864 procedure Head
865 (Source : in out Bounded_String;
866 Count : Natural;
867 Pad : Character := Space;
868 Drop : Truncation := Error)
869 renames Super_Head;
871 function Tail
872 (Source : Bounded_String;
873 Count : Natural;
874 Pad : Character := Space;
875 Drop : Truncation := Error) return Bounded_String
876 renames Super_Tail;
878 procedure Tail
879 (Source : in out Bounded_String;
880 Count : Natural;
881 Pad : Character := Space;
882 Drop : Truncation := Error)
883 renames Super_Tail;
885 function "*"
886 (Left : Natural;
887 Right : Bounded_String) return Bounded_String
888 renames Times;
890 function Replicate
891 (Count : Natural;
892 Item : Bounded_String;
893 Drop : Truncation := Error) return Bounded_String
894 renames Super_Replicate;
896 end Generic_Bounded_Length;
898 end Ada.Strings.Bounded;