1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . S T R I N G S . W I D E _ 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
.Wide_Maps
;
37 with Ada
.Strings
.Wide_Superbounded
;
39 package Ada
.Strings
.Wide_Bounded
is
44 -- Maximum length of a Bounded_Wide_String
46 package Generic_Bounded_Length
is
48 Max_Length
: constant Positive := Max
;
50 type Bounded_Wide_String
is private;
51 pragma Preelaborable_Initialization
(Bounded_Wide_String
);
53 Null_Bounded_Wide_String
: constant Bounded_Wide_String
;
55 subtype Length_Range
is Natural range 0 .. Max_Length
;
57 function Length
(Source
: Bounded_Wide_String
) return Length_Range
;
59 --------------------------------------------------------
60 -- Conversion, Concatenation, and Selection Functions --
61 --------------------------------------------------------
63 function To_Bounded_Wide_String
64 (Source
: Wide_String;
65 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
67 function To_Wide_String
68 (Source
: Bounded_Wide_String
) return Wide_String;
70 procedure Set_Bounded_Wide_String
71 (Target
: out Bounded_Wide_String
;
73 Drop
: Truncation
:= Error
);
74 pragma Ada_05
(Set_Bounded_Wide_String
);
77 (Left
: Bounded_Wide_String
;
78 Right
: Bounded_Wide_String
;
79 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
82 (Left
: Bounded_Wide_String
;
84 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
88 Right
: Bounded_Wide_String
;
89 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
92 (Left
: Bounded_Wide_String
;
93 Right
: Wide_Character;
94 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
97 (Left
: Wide_Character;
98 Right
: Bounded_Wide_String
;
99 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
102 (Source
: in out Bounded_Wide_String
;
103 New_Item
: Bounded_Wide_String
;
104 Drop
: Truncation
:= Error
);
107 (Source
: in out Bounded_Wide_String
;
108 New_Item
: Wide_String;
109 Drop
: Truncation
:= Error
);
112 (Source
: in out Bounded_Wide_String
;
113 New_Item
: Wide_Character;
114 Drop
: Truncation
:= Error
);
117 (Left
: Bounded_Wide_String
;
118 Right
: Bounded_Wide_String
) return Bounded_Wide_String
;
121 (Left
: Bounded_Wide_String
;
122 Right
: Wide_String) return Bounded_Wide_String
;
126 Right
: Bounded_Wide_String
) return Bounded_Wide_String
;
129 (Left
: Bounded_Wide_String
;
130 Right
: Wide_Character) return Bounded_Wide_String
;
133 (Left
: Wide_Character;
134 Right
: Bounded_Wide_String
) return Bounded_Wide_String
;
137 (Source
: Bounded_Wide_String
;
138 Index
: Positive) return Wide_Character;
140 procedure Replace_Element
141 (Source
: in out Bounded_Wide_String
;
143 By
: Wide_Character);
146 (Source
: Bounded_Wide_String
;
148 High
: Natural) return Wide_String;
150 function Bounded_Slice
151 (Source
: Bounded_Wide_String
;
153 High
: Natural) return Bounded_Wide_String
;
154 pragma Ada_05
(Bounded_Slice
);
156 procedure Bounded_Slice
157 (Source
: Bounded_Wide_String
;
158 Target
: out Bounded_Wide_String
;
161 pragma Ada_05
(Bounded_Slice
);
164 (Left
: Bounded_Wide_String
;
165 Right
: Bounded_Wide_String
) return Boolean;
168 (Left
: Bounded_Wide_String
;
169 Right
: Wide_String) return Boolean;
173 Right
: Bounded_Wide_String
) return Boolean;
176 (Left
: Bounded_Wide_String
;
177 Right
: Bounded_Wide_String
) return Boolean;
180 (Left
: Bounded_Wide_String
;
181 Right
: Wide_String) return Boolean;
185 Right
: Bounded_Wide_String
) return Boolean;
188 (Left
: Bounded_Wide_String
;
189 Right
: Bounded_Wide_String
) return Boolean;
192 (Left
: Bounded_Wide_String
;
193 Right
: Wide_String) return Boolean;
197 Right
: Bounded_Wide_String
) return Boolean;
200 (Left
: Bounded_Wide_String
;
201 Right
: Bounded_Wide_String
) return Boolean;
204 (Left
: Bounded_Wide_String
;
205 Right
: Wide_String) return Boolean;
209 Right
: Bounded_Wide_String
) return Boolean;
212 (Left
: Bounded_Wide_String
;
213 Right
: Bounded_Wide_String
) return Boolean;
216 (Left
: Bounded_Wide_String
;
217 Right
: Wide_String) return Boolean;
221 Right
: Bounded_Wide_String
) return Boolean;
223 ----------------------
224 -- Search Functions --
225 ----------------------
228 (Source
: Bounded_Wide_String
;
229 Pattern
: Wide_String;
230 Going
: Direction
:= Forward
;
231 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
235 (Source
: Bounded_Wide_String
;
236 Pattern
: Wide_String;
237 Going
: Direction
:= Forward
;
238 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
241 (Source
: Bounded_Wide_String
;
242 Set
: Wide_Maps
.Wide_Character_Set
;
243 Test
: Membership
:= Inside
;
244 Going
: Direction
:= Forward
) return Natural;
247 (Source
: Bounded_Wide_String
;
248 Pattern
: Wide_String;
250 Going
: Direction
:= Forward
;
251 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
253 pragma Ada_05
(Index
);
256 (Source
: Bounded_Wide_String
;
257 Pattern
: Wide_String;
259 Going
: Direction
:= Forward
;
260 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
261 pragma Ada_05
(Index
);
264 (Source
: Bounded_Wide_String
;
265 Set
: Wide_Maps
.Wide_Character_Set
;
267 Test
: Membership
:= Inside
;
268 Going
: Direction
:= Forward
) return Natural;
269 pragma Ada_05
(Index
);
271 function Index_Non_Blank
272 (Source
: Bounded_Wide_String
;
273 Going
: Direction
:= Forward
) return Natural;
275 function Index_Non_Blank
276 (Source
: Bounded_Wide_String
;
278 Going
: Direction
:= Forward
) return Natural;
279 pragma Ada_05
(Index_Non_Blank
);
282 (Source
: Bounded_Wide_String
;
283 Pattern
: Wide_String;
284 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
288 (Source
: Bounded_Wide_String
;
289 Pattern
: Wide_String;
290 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
293 (Source
: Bounded_Wide_String
;
294 Set
: Wide_Maps
.Wide_Character_Set
) return Natural;
297 (Source
: Bounded_Wide_String
;
298 Set
: Wide_Maps
.Wide_Character_Set
;
300 First
: out Positive;
303 ------------------------------------
304 -- String Translation Subprograms --
305 ------------------------------------
308 (Source
: Bounded_Wide_String
;
309 Mapping
: Wide_Maps
.Wide_Character_Mapping
)
310 return Bounded_Wide_String
;
313 (Source
: in out Bounded_Wide_String
;
314 Mapping
: Wide_Maps
.Wide_Character_Mapping
);
317 (Source
: Bounded_Wide_String
;
318 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
)
319 return Bounded_Wide_String
;
322 (Source
: in out Bounded_Wide_String
;
323 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
);
325 ---------------------------------------
326 -- String Transformation Subprograms --
327 ---------------------------------------
329 function Replace_Slice
330 (Source
: Bounded_Wide_String
;
334 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
336 procedure Replace_Slice
337 (Source
: in out Bounded_Wide_String
;
341 Drop
: Truncation
:= Error
);
344 (Source
: Bounded_Wide_String
;
346 New_Item
: Wide_String;
347 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
350 (Source
: in out Bounded_Wide_String
;
352 New_Item
: Wide_String;
353 Drop
: Truncation
:= Error
);
356 (Source
: Bounded_Wide_String
;
358 New_Item
: Wide_String;
359 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
362 (Source
: in out Bounded_Wide_String
;
364 New_Item
: Wide_String;
365 Drop
: Truncation
:= Error
);
368 (Source
: Bounded_Wide_String
;
370 Through
: Natural) return Bounded_Wide_String
;
373 (Source
: in out Bounded_Wide_String
;
377 ---------------------------------
378 -- String Selector Subprograms --
379 ---------------------------------
382 (Source
: Bounded_Wide_String
;
383 Side
: Trim_End
) return Bounded_Wide_String
;
386 (Source
: in out Bounded_Wide_String
;
390 (Source
: Bounded_Wide_String
;
391 Left
: Wide_Maps
.Wide_Character_Set
;
392 Right
: Wide_Maps
.Wide_Character_Set
) return Bounded_Wide_String
;
395 (Source
: in out Bounded_Wide_String
;
396 Left
: Wide_Maps
.Wide_Character_Set
;
397 Right
: Wide_Maps
.Wide_Character_Set
);
400 (Source
: Bounded_Wide_String
;
402 Pad
: Wide_Character := Wide_Space
;
403 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
406 (Source
: in out Bounded_Wide_String
;
408 Pad
: Wide_Character := Wide_Space
;
409 Drop
: Truncation
:= Error
);
412 (Source
: Bounded_Wide_String
;
414 Pad
: Wide_Character := Wide_Space
;
415 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
418 (Source
: in out Bounded_Wide_String
;
420 Pad
: Wide_Character := Wide_Space
;
421 Drop
: Truncation
:= Error
);
423 ------------------------------------
424 -- String Constructor Subprograms --
425 ------------------------------------
429 Right
: Wide_Character) return Bounded_Wide_String
;
433 Right
: Wide_String) return Bounded_Wide_String
;
437 Right
: Bounded_Wide_String
) return Bounded_Wide_String
;
441 Item
: Wide_Character;
442 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
447 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
451 Item
: Bounded_Wide_String
;
452 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
455 -- Most of the implementation is in the separate non generic package
456 -- Ada.Strings.Wide_Superbounded. Type Bounded_Wide_String is derived
457 -- from type Wide_Superbounded.Super_String with the maximum length
458 -- constraint. In almost all cases, the routines in Wide_Superbounded
459 -- can be called with no requirement to pass the maximum length
460 -- explicitly, since there is at least one Bounded_Wide_String argument
461 -- from which the maximum length can be obtained. For all such
462 -- routines, the implementation in this private part is simply a
463 -- renaming of the corresponding routine in the super bouded package.
465 -- The five exceptions are the * and Replicate routines operating on
466 -- character values. For these cases, we have a routine in the body
467 -- that calls the superbounded routine passing the maximum length
468 -- explicitly as an extra parameter.
470 type Bounded_Wide_String
is
471 new Wide_Superbounded
.Super_String
(Max_Length
);
472 -- Deriving Bounded_Wide_String from Wide_Superbounded.Super_String is
473 -- the real trick, it ensures that the type Bounded_Wide_String
474 -- declared in the generic instantiation is compatible with the
475 -- Super_String type declared in the Wide_Superbounded package.
477 Null_Bounded_Wide_String
: constant Bounded_Wide_String
:=
478 (Max_Length
=> Max_Length
,
482 Wide_Superbounded
.Wide_NUL
));
484 pragma Inline
(To_Bounded_Wide_String
);
486 procedure Set_Bounded_Wide_String
487 (Target
: out Bounded_Wide_String
;
488 Source
: Wide_String;
489 Drop
: Truncation
:= Error
)
490 renames Set_Super_String
;
493 (Source
: Bounded_Wide_String
) return Length_Range
494 renames Super_Length
;
496 function To_Wide_String
497 (Source
: Bounded_Wide_String
) return Wide_String
498 renames Super_To_String
;
501 (Left
: Bounded_Wide_String
;
502 Right
: Bounded_Wide_String
;
503 Drop
: Truncation
:= Error
) return Bounded_Wide_String
504 renames Super_Append
;
507 (Left
: Bounded_Wide_String
;
509 Drop
: Truncation
:= Error
) return Bounded_Wide_String
510 renames Super_Append
;
514 Right
: Bounded_Wide_String
;
515 Drop
: Truncation
:= Error
) return Bounded_Wide_String
516 renames Super_Append
;
519 (Left
: Bounded_Wide_String
;
520 Right
: Wide_Character;
521 Drop
: Truncation
:= Error
) return Bounded_Wide_String
522 renames Super_Append
;
525 (Left
: Wide_Character;
526 Right
: Bounded_Wide_String
;
527 Drop
: Truncation
:= Error
) return Bounded_Wide_String
528 renames Super_Append
;
531 (Source
: in out Bounded_Wide_String
;
532 New_Item
: Bounded_Wide_String
;
533 Drop
: Truncation
:= Error
)
534 renames Super_Append
;
537 (Source
: in out Bounded_Wide_String
;
538 New_Item
: Wide_String;
539 Drop
: Truncation
:= Error
)
540 renames Super_Append
;
543 (Source
: in out Bounded_Wide_String
;
544 New_Item
: Wide_Character;
545 Drop
: Truncation
:= Error
)
546 renames Super_Append
;
549 (Left
: Bounded_Wide_String
;
550 Right
: Bounded_Wide_String
) return Bounded_Wide_String
554 (Left
: Bounded_Wide_String
;
555 Right
: Wide_String) return Bounded_Wide_String
560 Right
: Bounded_Wide_String
) return Bounded_Wide_String
564 (Left
: Bounded_Wide_String
;
565 Right
: Wide_Character) return Bounded_Wide_String
569 (Left
: Wide_Character;
570 Right
: Bounded_Wide_String
) return Bounded_Wide_String
574 (Source
: Bounded_Wide_String
;
575 Index
: Positive) return Wide_Character
576 renames Super_Element
;
578 procedure Replace_Element
579 (Source
: in out Bounded_Wide_String
;
582 renames Super_Replace_Element
;
585 (Source
: Bounded_Wide_String
;
587 High
: Natural) return Wide_String
590 function Bounded_Slice
591 (Source
: Bounded_Wide_String
;
593 High
: Natural) return Bounded_Wide_String
596 procedure Bounded_Slice
597 (Source
: Bounded_Wide_String
;
598 Target
: out Bounded_Wide_String
;
604 (Left
: Bounded_Wide_String
;
605 Right
: Bounded_Wide_String
) return Boolean
609 (Left
: Bounded_Wide_String
;
610 Right
: Wide_String) return Boolean
615 Right
: Bounded_Wide_String
) return Boolean
619 (Left
: Bounded_Wide_String
;
620 Right
: Bounded_Wide_String
) return Boolean
624 (Left
: Bounded_Wide_String
;
625 Right
: Wide_String) return Boolean
630 Right
: Bounded_Wide_String
) return Boolean
634 (Left
: Bounded_Wide_String
;
635 Right
: Bounded_Wide_String
) return Boolean
636 renames Less_Or_Equal
;
639 (Left
: Bounded_Wide_String
;
640 Right
: Wide_String) return Boolean
641 renames Less_Or_Equal
;
645 Right
: Bounded_Wide_String
) return Boolean
646 renames Less_Or_Equal
;
649 (Left
: Bounded_Wide_String
;
650 Right
: Bounded_Wide_String
) return Boolean
654 (Left
: Bounded_Wide_String
;
655 Right
: Wide_String) return Boolean
660 Right
: Bounded_Wide_String
) return Boolean
664 (Left
: Bounded_Wide_String
;
665 Right
: Bounded_Wide_String
) return Boolean
666 renames Greater_Or_Equal
;
669 (Left
: Bounded_Wide_String
;
670 Right
: Wide_String) return Boolean
671 renames Greater_Or_Equal
;
675 Right
: Bounded_Wide_String
) return Boolean
676 renames Greater_Or_Equal
;
679 (Source
: Bounded_Wide_String
;
680 Pattern
: Wide_String;
681 Going
: Direction
:= Forward
;
682 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
687 (Source
: Bounded_Wide_String
;
688 Pattern
: Wide_String;
689 Going
: Direction
:= Forward
;
690 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
694 (Source
: Bounded_Wide_String
;
695 Set
: Wide_Maps
.Wide_Character_Set
;
696 Test
: Membership
:= Inside
;
697 Going
: Direction
:= Forward
) return Natural
701 (Source
: Bounded_Wide_String
;
702 Pattern
: Wide_String;
704 Going
: Direction
:= Forward
;
705 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
710 (Source
: Bounded_Wide_String
;
711 Pattern
: Wide_String;
713 Going
: Direction
:= Forward
;
714 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
718 (Source
: Bounded_Wide_String
;
719 Set
: Wide_Maps
.Wide_Character_Set
;
721 Test
: Membership
:= Inside
;
722 Going
: Direction
:= Forward
) return Natural
725 function Index_Non_Blank
726 (Source
: Bounded_Wide_String
;
727 Going
: Direction
:= Forward
) return Natural
728 renames Super_Index_Non_Blank
;
730 function Index_Non_Blank
731 (Source
: Bounded_Wide_String
;
733 Going
: Direction
:= Forward
) return Natural
734 renames Super_Index_Non_Blank
;
737 (Source
: Bounded_Wide_String
;
738 Pattern
: Wide_String;
739 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
744 (Source
: Bounded_Wide_String
;
745 Pattern
: Wide_String;
746 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
750 (Source
: Bounded_Wide_String
;
751 Set
: Wide_Maps
.Wide_Character_Set
) return Natural
755 (Source
: Bounded_Wide_String
;
756 Set
: Wide_Maps
.Wide_Character_Set
;
758 First
: out Positive;
760 renames Super_Find_Token
;
763 (Source
: Bounded_Wide_String
;
764 Mapping
: Wide_Maps
.Wide_Character_Mapping
)
765 return Bounded_Wide_String
766 renames Super_Translate
;
769 (Source
: in out Bounded_Wide_String
;
770 Mapping
: Wide_Maps
.Wide_Character_Mapping
)
771 renames Super_Translate
;
774 (Source
: Bounded_Wide_String
;
775 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
)
776 return Bounded_Wide_String
777 renames Super_Translate
;
780 (Source
: in out Bounded_Wide_String
;
781 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
)
782 renames Super_Translate
;
784 function Replace_Slice
785 (Source
: Bounded_Wide_String
;
789 Drop
: Truncation
:= Error
) return Bounded_Wide_String
790 renames Super_Replace_Slice
;
792 procedure Replace_Slice
793 (Source
: in out Bounded_Wide_String
;
797 Drop
: Truncation
:= Error
)
798 renames Super_Replace_Slice
;
801 (Source
: Bounded_Wide_String
;
803 New_Item
: Wide_String;
804 Drop
: Truncation
:= Error
) return Bounded_Wide_String
805 renames Super_Insert
;
808 (Source
: in out Bounded_Wide_String
;
810 New_Item
: Wide_String;
811 Drop
: Truncation
:= Error
)
812 renames Super_Insert
;
815 (Source
: Bounded_Wide_String
;
817 New_Item
: Wide_String;
818 Drop
: Truncation
:= Error
) return Bounded_Wide_String
819 renames Super_Overwrite
;
822 (Source
: in out Bounded_Wide_String
;
824 New_Item
: Wide_String;
825 Drop
: Truncation
:= Error
)
826 renames Super_Overwrite
;
829 (Source
: Bounded_Wide_String
;
831 Through
: Natural) return Bounded_Wide_String
832 renames Super_Delete
;
835 (Source
: in out Bounded_Wide_String
;
838 renames Super_Delete
;
841 (Source
: Bounded_Wide_String
;
842 Side
: Trim_End
) return Bounded_Wide_String
846 (Source
: in out Bounded_Wide_String
;
851 (Source
: Bounded_Wide_String
;
852 Left
: Wide_Maps
.Wide_Character_Set
;
853 Right
: Wide_Maps
.Wide_Character_Set
) return Bounded_Wide_String
857 (Source
: in out Bounded_Wide_String
;
858 Left
: Wide_Maps
.Wide_Character_Set
;
859 Right
: Wide_Maps
.Wide_Character_Set
)
863 (Source
: Bounded_Wide_String
;
865 Pad
: Wide_Character := Wide_Space
;
866 Drop
: Truncation
:= Error
) return Bounded_Wide_String
870 (Source
: in out Bounded_Wide_String
;
872 Pad
: Wide_Character := Wide_Space
;
873 Drop
: Truncation
:= Error
)
877 (Source
: Bounded_Wide_String
;
879 Pad
: Wide_Character := Wide_Space
;
880 Drop
: Truncation
:= Error
) return Bounded_Wide_String
884 (Source
: in out Bounded_Wide_String
;
886 Pad
: Wide_Character := Wide_Space
;
887 Drop
: Truncation
:= Error
)
892 Right
: Bounded_Wide_String
) return Bounded_Wide_String
897 Item
: Bounded_Wide_String
;
898 Drop
: Truncation
:= Error
) return Bounded_Wide_String
899 renames Super_Replicate
;
901 end Generic_Bounded_Length
;
903 end Ada
.Strings
.Wide_Bounded
;