Merge from the pain train
[official-gcc.git] / gcc / ada / a-strbou.ads
blob5b8346ad1027e3e54d9a84f8771d74c161c7b3c6
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-2005 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, 59 Temple Place - Suite 330, Boston, --
24 -- MA 02111-1307, 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 (Bounded);
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;
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
65 (Source : 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;
72 Source : String;
73 Drop : Truncation := Error);
74 pragma Ada_05 (Set_Bounded_String);
76 function Append
77 (Left : Bounded_String;
78 Right : Bounded_String;
79 Drop : Truncation := Error) return Bounded_String;
81 function Append
82 (Left : Bounded_String;
83 Right : String;
84 Drop : Truncation := Error) return Bounded_String;
86 function Append
87 (Left : String;
88 Right : Bounded_String;
89 Drop : Truncation := Error) return Bounded_String;
91 function Append
92 (Left : Bounded_String;
93 Right : Character;
94 Drop : Truncation := Error) return Bounded_String;
96 function Append
97 (Left : Character;
98 Right : Bounded_String;
99 Drop : Truncation := Error) return Bounded_String;
101 procedure Append
102 (Source : in out Bounded_String;
103 New_Item : Bounded_String;
104 Drop : Truncation := Error);
106 procedure Append
107 (Source : in out Bounded_String;
108 New_Item : String;
109 Drop : Truncation := Error);
111 procedure Append
112 (Source : in out Bounded_String;
113 New_Item : Character;
114 Drop : Truncation := Error);
116 function "&"
117 (Left : Bounded_String;
118 Right : Bounded_String) return Bounded_String;
120 function "&"
121 (Left : Bounded_String;
122 Right : String) return Bounded_String;
124 function "&"
125 (Left : String;
126 Right : Bounded_String) return Bounded_String;
128 function "&"
129 (Left : Bounded_String;
130 Right : Character) return Bounded_String;
132 function "&"
133 (Left : Character;
134 Right : Bounded_String) return Bounded_String;
136 function Element
137 (Source : Bounded_String;
138 Index : Positive) return Character;
140 procedure Replace_Element
141 (Source : in out Bounded_String;
142 Index : Positive;
143 By : Character);
145 function Slice
146 (Source : Bounded_String;
147 Low : Positive;
148 High : Natural) return String;
150 function Bounded_Slice
151 (Source : Bounded_String;
152 Low : Positive;
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;
159 Low : Positive;
160 High : Natural);
161 pragma Ada_05 (Bounded_Slice);
163 function "="
164 (Left : Bounded_String;
165 Right : Bounded_String) return Boolean;
167 function "="
168 (Left : Bounded_String;
169 Right : String) return Boolean;
171 function "="
172 (Left : String;
173 Right : Bounded_String) return Boolean;
175 function "<"
176 (Left : Bounded_String;
177 Right : Bounded_String) return Boolean;
179 function "<"
180 (Left : Bounded_String;
181 Right : String) return Boolean;
183 function "<"
184 (Left : String;
185 Right : Bounded_String) return Boolean;
187 function "<="
188 (Left : Bounded_String;
189 Right : Bounded_String) return Boolean;
191 function "<="
192 (Left : Bounded_String;
193 Right : String) return Boolean;
195 function "<="
196 (Left : String;
197 Right : Bounded_String) return Boolean;
199 function ">"
200 (Left : Bounded_String;
201 Right : Bounded_String) return Boolean;
203 function ">"
204 (Left : Bounded_String;
205 Right : String) return Boolean;
207 function ">"
208 (Left : String;
209 Right : Bounded_String) return Boolean;
211 function ">="
212 (Left : Bounded_String;
213 Right : Bounded_String) return Boolean;
215 function ">="
216 (Left : Bounded_String;
217 Right : String) return Boolean;
219 function ">="
220 (Left : String;
221 Right : Bounded_String) return Boolean;
223 ----------------------
224 -- Search Functions --
225 ----------------------
227 function Index
228 (Source : Bounded_String;
229 Pattern : String;
230 Going : Direction := Forward;
231 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
233 function Index
234 (Source : Bounded_String;
235 Pattern : String;
236 Going : Direction := Forward;
237 Mapping : Maps.Character_Mapping_Function) return Natural;
239 function Index
240 (Source : Bounded_String;
241 Set : Maps.Character_Set;
242 Test : Membership := Inside;
243 Going : Direction := Forward) return Natural;
245 function Index
246 (Source : Bounded_String;
247 Pattern : String;
248 From : Positive;
249 Going : Direction := Forward;
250 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
251 pragma Ada_05 (Index);
253 function Index
254 (Source : Bounded_String;
255 Pattern : String;
256 From : Positive;
257 Going : Direction := Forward;
258 Mapping : Maps.Character_Mapping_Function) return Natural;
259 pragma Ada_05 (Index);
261 function Index
262 (Source : Bounded_String;
263 Set : Maps.Character_Set;
264 From : Positive;
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;
275 From : Positive;
276 Going : Direction := Forward) return Natural;
277 pragma Ada_05 (Index_Non_Blank);
279 function Count
280 (Source : Bounded_String;
281 Pattern : String;
282 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural;
284 function Count
285 (Source : Bounded_String;
286 Pattern : String;
287 Mapping : Maps.Character_Mapping_Function) return Natural;
289 function Count
290 (Source : Bounded_String;
291 Set : Maps.Character_Set) return Natural;
293 procedure Find_Token
294 (Source : Bounded_String;
295 Set : Maps.Character_Set;
296 Test : Membership;
297 First : out Positive;
298 Last : out Natural);
300 ------------------------------------
301 -- String Translation Subprograms --
302 ------------------------------------
304 function Translate
305 (Source : Bounded_String;
306 Mapping : Maps.Character_Mapping) return Bounded_String;
308 procedure Translate
309 (Source : in out Bounded_String;
310 Mapping : Maps.Character_Mapping);
312 function Translate
313 (Source : Bounded_String;
314 Mapping : Maps.Character_Mapping_Function) return Bounded_String;
316 procedure Translate
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;
326 Low : Positive;
327 High : Natural;
328 By : String;
329 Drop : Truncation := Error) return Bounded_String;
331 procedure Replace_Slice
332 (Source : in out Bounded_String;
333 Low : Positive;
334 High : Natural;
335 By : String;
336 Drop : Truncation := Error);
338 function Insert
339 (Source : Bounded_String;
340 Before : Positive;
341 New_Item : String;
342 Drop : Truncation := Error) return Bounded_String;
344 procedure Insert
345 (Source : in out Bounded_String;
346 Before : Positive;
347 New_Item : String;
348 Drop : Truncation := Error);
350 function Overwrite
351 (Source : Bounded_String;
352 Position : Positive;
353 New_Item : String;
354 Drop : Truncation := Error) return Bounded_String;
356 procedure Overwrite
357 (Source : in out Bounded_String;
358 Position : Positive;
359 New_Item : String;
360 Drop : Truncation := Error);
362 function Delete
363 (Source : Bounded_String;
364 From : Positive;
365 Through : Natural) return Bounded_String;
367 procedure Delete
368 (Source : in out Bounded_String;
369 From : Positive;
370 Through : Natural);
372 ---------------------------------
373 -- String Selector Subprograms --
374 ---------------------------------
376 function Trim
377 (Source : Bounded_String;
378 Side : Trim_End) return Bounded_String;
380 procedure Trim
381 (Source : in out Bounded_String;
382 Side : Trim_End);
384 function Trim
385 (Source : Bounded_String;
386 Left : Maps.Character_Set;
387 Right : Maps.Character_Set) return Bounded_String;
389 procedure Trim
390 (Source : in out Bounded_String;
391 Left : Maps.Character_Set;
392 Right : Maps.Character_Set);
394 function Head
395 (Source : Bounded_String;
396 Count : Natural;
397 Pad : Character := Space;
398 Drop : Truncation := Error) return Bounded_String;
400 procedure Head
401 (Source : in out Bounded_String;
402 Count : Natural;
403 Pad : Character := Space;
404 Drop : Truncation := Error);
406 function Tail
407 (Source : Bounded_String;
408 Count : Natural;
409 Pad : Character := Space;
410 Drop : Truncation := Error) return Bounded_String;
412 procedure Tail
413 (Source : in out Bounded_String;
414 Count : Natural;
415 Pad : Character := Space;
416 Drop : Truncation := Error);
418 ------------------------------------
419 -- String Constructor Subprograms --
420 ------------------------------------
422 function "*"
423 (Left : Natural;
424 Right : Character) return Bounded_String;
426 function "*"
427 (Left : Natural;
428 Right : String) return Bounded_String;
430 function "*"
431 (Left : Natural;
432 Right : Bounded_String) return Bounded_String;
434 function Replicate
435 (Count : Natural;
436 Item : Character;
437 Drop : Truncation := Error) return Bounded_String;
439 function Replicate
440 (Count : Natural;
441 Item : String;
442 Drop : Truncation := Error) return Bounded_String;
444 function Replicate
445 (Count : Natural;
446 Item : Bounded_String;
447 Drop : Truncation := Error) return Bounded_String;
449 private
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,
473 Current_Length => 0,
474 Data =>
475 (1 .. Max_Length => ASCII.NUL));
477 pragma Inline (To_Bounded_String);
479 procedure Set_Bounded_String
480 (Target : out Bounded_String;
481 Source : String;
482 Drop : Truncation := Error)
483 renames Set_Super_String;
485 function Length
486 (Source : Bounded_String) return Length_Range
487 renames Super_Length;
489 function To_String
490 (Source : Bounded_String) return String
491 renames Super_To_String;
493 function Append
494 (Left : Bounded_String;
495 Right : Bounded_String;
496 Drop : Truncation := Error) return Bounded_String
497 renames Super_Append;
499 function Append
500 (Left : Bounded_String;
501 Right : String;
502 Drop : Truncation := Error) return Bounded_String
503 renames Super_Append;
505 function Append
506 (Left : String;
507 Right : Bounded_String;
508 Drop : Truncation := Error) return Bounded_String
509 renames Super_Append;
511 function Append
512 (Left : Bounded_String;
513 Right : Character;
514 Drop : Truncation := Error) return Bounded_String
515 renames Super_Append;
517 function Append
518 (Left : Character;
519 Right : Bounded_String;
520 Drop : Truncation := Error) return Bounded_String
521 renames Super_Append;
523 procedure Append
524 (Source : in out Bounded_String;
525 New_Item : Bounded_String;
526 Drop : Truncation := Error)
527 renames Super_Append;
529 procedure Append
530 (Source : in out Bounded_String;
531 New_Item : String;
532 Drop : Truncation := Error)
533 renames Super_Append;
535 procedure Append
536 (Source : in out Bounded_String;
537 New_Item : Character;
538 Drop : Truncation := Error)
539 renames Super_Append;
541 function "&"
542 (Left : Bounded_String;
543 Right : Bounded_String) return Bounded_String
544 renames Concat;
546 function "&"
547 (Left : Bounded_String;
548 Right : String) return Bounded_String
549 renames Concat;
551 function "&"
552 (Left : String;
553 Right : Bounded_String) return Bounded_String
554 renames Concat;
556 function "&"
557 (Left : Bounded_String;
558 Right : Character) return Bounded_String
559 renames Concat;
561 function "&"
562 (Left : Character;
563 Right : Bounded_String) return Bounded_String
564 renames Concat;
566 function Element
567 (Source : Bounded_String;
568 Index : Positive) return Character
569 renames Super_Element;
571 procedure Replace_Element
572 (Source : in out Bounded_String;
573 Index : Positive;
574 By : Character)
575 renames Super_Replace_Element;
577 function Slice
578 (Source : Bounded_String;
579 Low : Positive;
580 High : Natural) return String
581 renames Super_Slice;
583 function Bounded_Slice
584 (Source : Bounded_String;
585 Low : Positive;
586 High : Natural) return Bounded_String
587 renames Super_Slice;
589 procedure Bounded_Slice
590 (Source : Bounded_String;
591 Target : out Bounded_String;
592 Low : Positive;
593 High : Natural)
594 renames Super_Slice;
596 function "="
597 (Left : Bounded_String;
598 Right : Bounded_String) return Boolean
599 renames Equal;
601 function "="
602 (Left : Bounded_String;
603 Right : String) return Boolean
604 renames Equal;
606 function "="
607 (Left : String;
608 Right : Bounded_String) return Boolean
609 renames Equal;
611 function "<"
612 (Left : Bounded_String;
613 Right : Bounded_String) return Boolean
614 renames Less;
616 function "<"
617 (Left : Bounded_String;
618 Right : String) return Boolean
619 renames Less;
621 function "<"
622 (Left : String;
623 Right : Bounded_String) return Boolean
624 renames Less;
626 function "<="
627 (Left : Bounded_String;
628 Right : Bounded_String) return Boolean
629 renames Less_Or_Equal;
631 function "<="
632 (Left : Bounded_String;
633 Right : String) return Boolean
634 renames Less_Or_Equal;
636 function "<="
637 (Left : String;
638 Right : Bounded_String) return Boolean
639 renames Less_Or_Equal;
641 function ">"
642 (Left : Bounded_String;
643 Right : Bounded_String) return Boolean
644 renames Greater;
646 function ">"
647 (Left : Bounded_String;
648 Right : String) return Boolean
649 renames Greater;
651 function ">"
652 (Left : String;
653 Right : Bounded_String) return Boolean
654 renames Greater;
656 function ">="
657 (Left : Bounded_String;
658 Right : Bounded_String) return Boolean
659 renames Greater_Or_Equal;
661 function ">="
662 (Left : Bounded_String;
663 Right : String) return Boolean
664 renames Greater_Or_Equal;
666 function ">="
667 (Left : String;
668 Right : Bounded_String) return Boolean
669 renames Greater_Or_Equal;
671 function Index
672 (Source : Bounded_String;
673 Pattern : String;
674 Going : Direction := Forward;
675 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
676 renames Super_Index;
678 function Index
679 (Source : Bounded_String;
680 Pattern : String;
681 Going : Direction := Forward;
682 Mapping : Maps.Character_Mapping_Function) return Natural
683 renames Super_Index;
685 function Index
686 (Source : Bounded_String;
687 Set : Maps.Character_Set;
688 Test : Membership := Inside;
689 Going : Direction := Forward) return Natural
690 renames Super_Index;
692 function Index
693 (Source : Bounded_String;
694 Pattern : String;
695 From : Positive;
696 Going : Direction := Forward;
697 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
698 renames Super_Index;
700 function Index
701 (Source : Bounded_String;
702 Pattern : String;
703 From : Positive;
704 Going : Direction := Forward;
705 Mapping : Maps.Character_Mapping_Function) return Natural
706 renames Super_Index;
708 function Index
709 (Source : Bounded_String;
710 Set : Maps.Character_Set;
711 From : Positive;
712 Test : Membership := Inside;
713 Going : Direction := Forward) return Natural
714 renames Super_Index;
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;
723 From : Positive;
724 Going : Direction := Forward) return Natural
725 renames Super_Index_Non_Blank;
727 function Count
728 (Source : Bounded_String;
729 Pattern : String;
730 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
731 renames Super_Count;
733 function Count
734 (Source : Bounded_String;
735 Pattern : String;
736 Mapping : Maps.Character_Mapping_Function) return Natural
737 renames Super_Count;
739 function Count
740 (Source : Bounded_String;
741 Set : Maps.Character_Set) return Natural
742 renames Super_Count;
744 procedure Find_Token
745 (Source : Bounded_String;
746 Set : Maps.Character_Set;
747 Test : Membership;
748 First : out Positive;
749 Last : out Natural)
750 renames Super_Find_Token;
752 function Translate
753 (Source : Bounded_String;
754 Mapping : Maps.Character_Mapping) return Bounded_String
755 renames Super_Translate;
757 procedure Translate
758 (Source : in out Bounded_String;
759 Mapping : Maps.Character_Mapping)
760 renames Super_Translate;
762 function Translate
763 (Source : Bounded_String;
764 Mapping : Maps.Character_Mapping_Function) return Bounded_String
765 renames Super_Translate;
767 procedure 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;
774 Low : Positive;
775 High : Natural;
776 By : String;
777 Drop : Truncation := Error) return Bounded_String
778 renames Super_Replace_Slice;
780 procedure Replace_Slice
781 (Source : in out Bounded_String;
782 Low : Positive;
783 High : Natural;
784 By : String;
785 Drop : Truncation := Error)
786 renames Super_Replace_Slice;
788 function Insert
789 (Source : Bounded_String;
790 Before : Positive;
791 New_Item : String;
792 Drop : Truncation := Error) return Bounded_String
793 renames Super_Insert;
795 procedure Insert
796 (Source : in out Bounded_String;
797 Before : Positive;
798 New_Item : String;
799 Drop : Truncation := Error)
800 renames Super_Insert;
802 function Overwrite
803 (Source : Bounded_String;
804 Position : Positive;
805 New_Item : String;
806 Drop : Truncation := Error) return Bounded_String
807 renames Super_Overwrite;
809 procedure Overwrite
810 (Source : in out Bounded_String;
811 Position : Positive;
812 New_Item : String;
813 Drop : Truncation := Error)
814 renames Super_Overwrite;
816 function Delete
817 (Source : Bounded_String;
818 From : Positive;
819 Through : Natural) return Bounded_String
820 renames Super_Delete;
822 procedure Delete
823 (Source : in out Bounded_String;
824 From : Positive;
825 Through : Natural)
826 renames Super_Delete;
828 function Trim
829 (Source : Bounded_String;
830 Side : Trim_End) return Bounded_String
831 renames Super_Trim;
833 procedure Trim
834 (Source : in out Bounded_String;
835 Side : Trim_End)
836 renames Super_Trim;
838 function Trim
839 (Source : Bounded_String;
840 Left : Maps.Character_Set;
841 Right : Maps.Character_Set) return Bounded_String
842 renames Super_Trim;
844 procedure Trim
845 (Source : in out Bounded_String;
846 Left : Maps.Character_Set;
847 Right : Maps.Character_Set)
848 renames Super_Trim;
850 function Head
851 (Source : Bounded_String;
852 Count : Natural;
853 Pad : Character := Space;
854 Drop : Truncation := Error) return Bounded_String
855 renames Super_Head;
857 procedure Head
858 (Source : in out Bounded_String;
859 Count : Natural;
860 Pad : Character := Space;
861 Drop : Truncation := Error)
862 renames Super_Head;
864 function Tail
865 (Source : Bounded_String;
866 Count : Natural;
867 Pad : Character := Space;
868 Drop : Truncation := Error) return Bounded_String
869 renames Super_Tail;
871 procedure Tail
872 (Source : in out Bounded_String;
873 Count : Natural;
874 Pad : Character := Space;
875 Drop : Truncation := Error)
876 renames Super_Tail;
878 function "*"
879 (Left : Natural;
880 Right : Bounded_String) return Bounded_String
881 renames Times;
883 function Replicate
884 (Count : Natural;
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;