2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / ada / a-strbou.ads
blob7e9f54f1b0a2fcadcd1fae41fe03eee3f554a5c1
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-2003 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 : in Bounded_String) return Length_Range;
60 --------------------------------------------------------
61 -- Conversion, Concatenation, and Selection Functions --
62 --------------------------------------------------------
64 function To_Bounded_String
65 (Source : in String;
66 Drop : in Truncation := Error)
67 return Bounded_String;
69 function To_String (Source : in Bounded_String) return String;
71 function Append
72 (Left, Right : in Bounded_String;
73 Drop : in Truncation := Error)
74 return Bounded_String;
76 function Append
77 (Left : in Bounded_String;
78 Right : in String;
79 Drop : in Truncation := Error)
80 return Bounded_String;
82 function Append
83 (Left : in String;
84 Right : in Bounded_String;
85 Drop : in Truncation := Error)
86 return Bounded_String;
88 function Append
89 (Left : in Bounded_String;
90 Right : in Character;
91 Drop : in Truncation := Error)
92 return Bounded_String;
94 function Append
95 (Left : in Character;
96 Right : in Bounded_String;
97 Drop : in Truncation := Error)
98 return Bounded_String;
100 procedure Append
101 (Source : in out Bounded_String;
102 New_Item : in Bounded_String;
103 Drop : in Truncation := Error);
105 procedure Append
106 (Source : in out Bounded_String;
107 New_Item : in String;
108 Drop : in Truncation := Error);
110 procedure Append
111 (Source : in out Bounded_String;
112 New_Item : in Character;
113 Drop : in Truncation := Error);
115 function "&"
116 (Left, Right : in Bounded_String)
117 return Bounded_String;
119 function "&"
120 (Left : in Bounded_String;
121 Right : in String)
122 return Bounded_String;
124 function "&"
125 (Left : in String;
126 Right : in Bounded_String)
127 return Bounded_String;
129 function "&"
130 (Left : in Bounded_String;
131 Right : in Character)
132 return Bounded_String;
134 function "&"
135 (Left : in Character;
136 Right : in Bounded_String)
137 return Bounded_String;
139 function Element
140 (Source : in Bounded_String;
141 Index : in Positive)
142 return Character;
144 procedure Replace_Element
145 (Source : in out Bounded_String;
146 Index : in Positive;
147 By : in Character);
149 function Slice
150 (Source : in Bounded_String;
151 Low : in Positive;
152 High : in Natural)
153 return String;
155 function "=" (Left, Right : in Bounded_String) return Boolean;
157 function "="
158 (Left : in Bounded_String;
159 Right : in String)
160 return Boolean;
162 function "="
163 (Left : in String;
164 Right : in Bounded_String)
165 return Boolean;
167 function "<" (Left, Right : in Bounded_String) return Boolean;
169 function "<"
170 (Left : in Bounded_String;
171 Right : in String)
172 return Boolean;
174 function "<"
175 (Left : in String;
176 Right : in Bounded_String)
177 return Boolean;
179 function "<=" (Left, Right : in Bounded_String) return Boolean;
181 function "<="
182 (Left : in Bounded_String;
183 Right : in String)
184 return Boolean;
186 function "<="
187 (Left : in String;
188 Right : in Bounded_String)
189 return Boolean;
191 function ">" (Left, Right : in Bounded_String) return Boolean;
193 function ">"
194 (Left : in Bounded_String;
195 Right : in String)
196 return Boolean;
198 function ">"
199 (Left : in String;
200 Right : in Bounded_String)
201 return Boolean;
203 function ">=" (Left, Right : in Bounded_String) return Boolean;
205 function ">="
206 (Left : in Bounded_String;
207 Right : in String)
208 return Boolean;
210 function ">="
211 (Left : in String;
212 Right : in Bounded_String)
213 return Boolean;
215 ----------------------
216 -- Search Functions --
217 ----------------------
219 function Index
220 (Source : in Bounded_String;
221 Pattern : in String;
222 Going : in Direction := Forward;
223 Mapping : in Maps.Character_Mapping := Maps.Identity)
224 return Natural;
226 function Index
227 (Source : in Bounded_String;
228 Pattern : in String;
229 Going : in Direction := Forward;
230 Mapping : in Maps.Character_Mapping_Function)
231 return Natural;
233 function Index
234 (Source : in Bounded_String;
235 Set : in Maps.Character_Set;
236 Test : in Membership := Inside;
237 Going : in Direction := Forward)
238 return Natural;
240 function Index_Non_Blank
241 (Source : in Bounded_String;
242 Going : in Direction := Forward)
243 return Natural;
245 function Count
246 (Source : in Bounded_String;
247 Pattern : in String;
248 Mapping : in Maps.Character_Mapping := Maps.Identity)
249 return Natural;
251 function Count
252 (Source : in Bounded_String;
253 Pattern : in String;
254 Mapping : in Maps.Character_Mapping_Function)
255 return Natural;
257 function Count
258 (Source : in Bounded_String;
259 Set : in Maps.Character_Set)
260 return Natural;
262 procedure Find_Token
263 (Source : in Bounded_String;
264 Set : in Maps.Character_Set;
265 Test : in Membership;
266 First : out Positive;
267 Last : out Natural);
269 ------------------------------------
270 -- String Translation Subprograms --
271 ------------------------------------
273 function Translate
274 (Source : in Bounded_String;
275 Mapping : in Maps.Character_Mapping)
276 return Bounded_String;
278 procedure Translate
279 (Source : in out Bounded_String;
280 Mapping : in Maps.Character_Mapping);
282 function Translate
283 (Source : in Bounded_String;
284 Mapping : in Maps.Character_Mapping_Function)
285 return Bounded_String;
287 procedure Translate
288 (Source : in out Bounded_String;
289 Mapping : in Maps.Character_Mapping_Function);
291 ---------------------------------------
292 -- String Transformation Subprograms --
293 ---------------------------------------
295 function Replace_Slice
296 (Source : in Bounded_String;
297 Low : in Positive;
298 High : in Natural;
299 By : in String;
300 Drop : in Truncation := Error)
301 return Bounded_String;
303 procedure Replace_Slice
304 (Source : in out Bounded_String;
305 Low : in Positive;
306 High : in Natural;
307 By : in String;
308 Drop : in Truncation := Error);
310 function Insert
311 (Source : in Bounded_String;
312 Before : in Positive;
313 New_Item : in String;
314 Drop : in Truncation := Error)
315 return Bounded_String;
317 procedure Insert
318 (Source : in out Bounded_String;
319 Before : in Positive;
320 New_Item : in String;
321 Drop : in Truncation := Error);
323 function Overwrite
324 (Source : in Bounded_String;
325 Position : in Positive;
326 New_Item : in String;
327 Drop : in Truncation := Error)
328 return Bounded_String;
330 procedure Overwrite
331 (Source : in out Bounded_String;
332 Position : in Positive;
333 New_Item : in String;
334 Drop : in Truncation := Error);
336 function Delete
337 (Source : in Bounded_String;
338 From : in Positive;
339 Through : in Natural)
340 return Bounded_String;
342 procedure Delete
343 (Source : in out Bounded_String;
344 From : in Positive;
345 Through : in Natural);
347 ---------------------------------
348 -- String Selector Subprograms --
349 ---------------------------------
351 function Trim
352 (Source : in Bounded_String;
353 Side : in Trim_End)
354 return Bounded_String;
356 procedure Trim
357 (Source : in out Bounded_String;
358 Side : in Trim_End);
360 function Trim
361 (Source : in Bounded_String;
362 Left : in Maps.Character_Set;
363 Right : in Maps.Character_Set)
364 return Bounded_String;
366 procedure Trim
367 (Source : in out Bounded_String;
368 Left : in Maps.Character_Set;
369 Right : in Maps.Character_Set);
371 function Head
372 (Source : in Bounded_String;
373 Count : in Natural;
374 Pad : in Character := Space;
375 Drop : in Truncation := Error)
376 return Bounded_String;
378 procedure Head
379 (Source : in out Bounded_String;
380 Count : in Natural;
381 Pad : in Character := Space;
382 Drop : in Truncation := Error);
384 function Tail
385 (Source : in Bounded_String;
386 Count : in Natural;
387 Pad : in Character := Space;
388 Drop : in Truncation := Error)
389 return Bounded_String;
391 procedure Tail
392 (Source : in out Bounded_String;
393 Count : in Natural;
394 Pad : in Character := Space;
395 Drop : in Truncation := Error);
397 ------------------------------------
398 -- String Constructor Subprograms --
399 ------------------------------------
401 function "*"
402 (Left : in Natural;
403 Right : in Character)
404 return Bounded_String;
406 function "*"
407 (Left : in Natural;
408 Right : in String)
409 return Bounded_String;
411 function "*"
412 (Left : in Natural;
413 Right : in Bounded_String)
414 return Bounded_String;
416 function Replicate
417 (Count : in Natural;
418 Item : in Character;
419 Drop : in Truncation := Error)
420 return Bounded_String;
422 function Replicate
423 (Count : in Natural;
424 Item : in String;
425 Drop : in Truncation := Error)
426 return Bounded_String;
428 function Replicate
429 (Count : in Natural;
430 Item : in Bounded_String;
431 Drop : in Truncation := Error)
432 return Bounded_String;
434 private
436 -- Most of the implementation is in the non generic package
437 -- Ada.Strings.Superbounded. Type Bounded_String is derived from type
438 -- Superbounded.Super_String with the maximum length constraint.
439 -- Except for five, all subprograms are renames of subprograms that
440 -- are inherited from Superbounded.Super_String.
442 type Bounded_String is new Superbounded.Super_String (Max_Length);
444 Null_Bounded_String : constant Bounded_String :=
445 (Max_Length => Max_Length,
446 Current_Length => 0,
447 Data => (1 .. Max_Length => ASCII.NUL));
449 pragma Inline (To_Bounded_String);
451 function Length (Source : in Bounded_String) return Length_Range
452 renames Super_Length;
454 function To_String (Source : in Bounded_String) return String
455 renames Super_To_String;
457 function Append
458 (Left, Right : in Bounded_String;
459 Drop : in Truncation := Error)
460 return Bounded_String
461 renames Super_Append;
463 function Append
464 (Left : in Bounded_String;
465 Right : in String;
466 Drop : in Truncation := Error)
467 return Bounded_String
468 renames Super_Append;
470 function Append
471 (Left : in String;
472 Right : in Bounded_String;
473 Drop : in Truncation := Error)
474 return Bounded_String
475 renames Super_Append;
477 function Append
478 (Left : in Bounded_String;
479 Right : in Character;
480 Drop : in Truncation := Error)
481 return Bounded_String
482 renames Super_Append;
484 function Append
485 (Left : in Character;
486 Right : in Bounded_String;
487 Drop : in Truncation := Error)
488 return Bounded_String
489 renames Super_Append;
491 procedure Append
492 (Source : in out Bounded_String;
493 New_Item : in Bounded_String;
494 Drop : in Truncation := Error)
495 renames Super_Append;
497 procedure Append
498 (Source : in out Bounded_String;
499 New_Item : in String;
500 Drop : in Truncation := Error)
501 renames Super_Append;
503 procedure Append
504 (Source : in out Bounded_String;
505 New_Item : in Character;
506 Drop : in Truncation := Error)
507 renames Super_Append;
509 function "&"
510 (Left, Right : in Bounded_String)
511 return Bounded_String
512 renames Concat;
514 function "&"
515 (Left : in Bounded_String;
516 Right : in String)
517 return Bounded_String
518 renames Concat;
520 function "&"
521 (Left : in String;
522 Right : in Bounded_String)
523 return Bounded_String
524 renames Concat;
526 function "&"
527 (Left : in Bounded_String;
528 Right : in Character)
529 return Bounded_String
530 renames Concat;
532 function "&"
533 (Left : in Character;
534 Right : in Bounded_String)
535 return Bounded_String
536 renames Concat;
538 function Element
539 (Source : in Bounded_String;
540 Index : in Positive)
541 return Character
542 renames Super_Element;
544 procedure Replace_Element
545 (Source : in out Bounded_String;
546 Index : in Positive;
547 By : in Character)
548 renames Super_Replace_Element;
550 function Slice
551 (Source : in Bounded_String;
552 Low : in Positive;
553 High : in Natural)
554 return String
555 renames Super_Slice;
557 function "=" (Left, Right : in Bounded_String) return Boolean
558 renames Equal;
560 function "="
561 (Left : in Bounded_String;
562 Right : in String)
563 return Boolean
564 renames Equal;
566 function "="
567 (Left : in String;
568 Right : in Bounded_String)
569 return Boolean
570 renames Equal;
572 function "<" (Left, Right : in Bounded_String) return Boolean
573 renames Less;
575 function "<"
576 (Left : in Bounded_String;
577 Right : in String)
578 return Boolean
579 renames Less;
581 function "<"
582 (Left : in String;
583 Right : in Bounded_String)
584 return Boolean
585 renames Less;
587 function "<=" (Left, Right : in Bounded_String) return Boolean
588 renames Less_Or_Equal;
590 function "<="
591 (Left : in Bounded_String;
592 Right : in String)
593 return Boolean
594 renames Less_Or_Equal;
596 function "<="
597 (Left : in String;
598 Right : in Bounded_String)
599 return Boolean
600 renames Less_Or_Equal;
602 function ">" (Left, Right : in Bounded_String) return Boolean
603 renames Greater;
605 function ">"
606 (Left : in Bounded_String;
607 Right : in String)
608 return Boolean
609 renames Greater;
611 function ">"
612 (Left : in String;
613 Right : in Bounded_String)
614 return Boolean
615 renames Greater;
617 function ">=" (Left, Right : in Bounded_String) return Boolean
618 renames Greater_Or_Equal;
620 function ">="
621 (Left : in Bounded_String;
622 Right : in String)
623 return Boolean
624 renames Greater_Or_Equal;
626 function ">="
627 (Left : in String;
628 Right : in Bounded_String)
629 return Boolean
630 renames Greater_Or_Equal;
632 function Index
633 (Source : in Bounded_String;
634 Pattern : in String;
635 Going : in Direction := Forward;
636 Mapping : in Maps.Character_Mapping := Maps.Identity)
637 return Natural
638 renames Super_Index;
640 function Index
641 (Source : in Bounded_String;
642 Pattern : in String;
643 Going : in Direction := Forward;
644 Mapping : in Maps.Character_Mapping_Function)
645 return Natural
646 renames Super_Index;
648 function Index
649 (Source : in Bounded_String;
650 Set : in Maps.Character_Set;
651 Test : in Membership := Inside;
652 Going : in Direction := Forward)
653 return Natural
654 renames Super_Index;
656 function Index_Non_Blank
657 (Source : in Bounded_String;
658 Going : in Direction := Forward)
659 return Natural
660 renames Super_Index_Non_Blank;
662 function Count
663 (Source : in Bounded_String;
664 Pattern : in String;
665 Mapping : in Maps.Character_Mapping := Maps.Identity)
666 return Natural
667 renames Super_Count;
669 function Count
670 (Source : in Bounded_String;
671 Pattern : in String;
672 Mapping : in Maps.Character_Mapping_Function)
673 return Natural
674 renames Super_Count;
676 function Count
677 (Source : in Bounded_String;
678 Set : in Maps.Character_Set)
679 return Natural
680 renames Super_Count;
682 procedure Find_Token
683 (Source : in Bounded_String;
684 Set : in Maps.Character_Set;
685 Test : in Membership;
686 First : out Positive;
687 Last : out Natural)
688 renames Super_Find_Token;
690 function Translate
691 (Source : in Bounded_String;
692 Mapping : in Maps.Character_Mapping)
693 return Bounded_String
694 renames Super_Translate;
696 procedure Translate
697 (Source : in out Bounded_String;
698 Mapping : in Maps.Character_Mapping)
699 renames Super_Translate;
701 function Translate
702 (Source : in Bounded_String;
703 Mapping : in Maps.Character_Mapping_Function)
704 return Bounded_String
705 renames Super_Translate;
707 procedure Translate
708 (Source : in out Bounded_String;
709 Mapping : in Maps.Character_Mapping_Function)
710 renames Super_Translate;
712 function Replace_Slice
713 (Source : in Bounded_String;
714 Low : in Positive;
715 High : in Natural;
716 By : in String;
717 Drop : in Truncation := Error)
718 return Bounded_String
719 renames Super_Replace_Slice;
721 procedure Replace_Slice
722 (Source : in out Bounded_String;
723 Low : in Positive;
724 High : in Natural;
725 By : in String;
726 Drop : in Truncation := Error)
727 renames Super_Replace_Slice;
729 function Insert
730 (Source : in Bounded_String;
731 Before : in Positive;
732 New_Item : in String;
733 Drop : in Truncation := Error)
734 return Bounded_String
735 renames Super_Insert;
737 procedure Insert
738 (Source : in out Bounded_String;
739 Before : in Positive;
740 New_Item : in String;
741 Drop : in Truncation := Error)
742 renames Super_Insert;
744 function Overwrite
745 (Source : in Bounded_String;
746 Position : in Positive;
747 New_Item : in String;
748 Drop : in Truncation := Error)
749 return Bounded_String
750 renames Super_Overwrite;
752 procedure Overwrite
753 (Source : in out Bounded_String;
754 Position : in Positive;
755 New_Item : in String;
756 Drop : in Truncation := Error)
757 renames Super_Overwrite;
759 function Delete
760 (Source : in Bounded_String;
761 From : in Positive;
762 Through : in Natural)
763 return Bounded_String
764 renames Super_Delete;
766 procedure Delete
767 (Source : in out Bounded_String;
768 From : in Positive;
769 Through : in Natural)
770 renames Super_Delete;
772 function Trim
773 (Source : in Bounded_String;
774 Side : in Trim_End)
775 return Bounded_String
776 renames Super_Trim;
778 procedure Trim
779 (Source : in out Bounded_String;
780 Side : in Trim_End)
781 renames Super_Trim;
783 function Trim
784 (Source : in Bounded_String;
785 Left : in Maps.Character_Set;
786 Right : in Maps.Character_Set)
787 return Bounded_String
788 renames Super_Trim;
790 procedure Trim
791 (Source : in out Bounded_String;
792 Left : in Maps.Character_Set;
793 Right : in Maps.Character_Set)
794 renames Super_Trim;
796 function Head
797 (Source : in Bounded_String;
798 Count : in Natural;
799 Pad : in Character := Space;
800 Drop : in Truncation := Error)
801 return Bounded_String
802 renames Super_Head;
804 procedure Head
805 (Source : in out Bounded_String;
806 Count : in Natural;
807 Pad : in Character := Space;
808 Drop : in Truncation := Error)
809 renames Super_Head;
811 function Tail
812 (Source : in Bounded_String;
813 Count : in Natural;
814 Pad : in Character := Space;
815 Drop : in Truncation := Error)
816 return Bounded_String
817 renames Super_Tail;
819 procedure Tail
820 (Source : in out Bounded_String;
821 Count : in Natural;
822 Pad : in Character := Space;
823 Drop : in Truncation := Error)
824 renames Super_Tail;
826 function "*"
827 (Left : in Natural;
828 Right : in Bounded_String)
829 return Bounded_String
830 renames Times;
832 function Replicate
833 (Count : in Natural;
834 Item : in Bounded_String;
835 Drop : in Truncation := Error)
836 return Bounded_String
837 renames Super_Replicate;
839 end Generic_Bounded_Length;
841 end Ada.Strings.Bounded;