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-2010, 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
;
301 First
: out Positive;
303 pragma Ada_2012
(Find_Token
);
306 (Source
: Bounded_Wide_String
;
307 Set
: Wide_Maps
.Wide_Character_Set
;
309 First
: out Positive;
312 ------------------------------------
313 -- String Translation Subprograms --
314 ------------------------------------
317 (Source
: Bounded_Wide_String
;
318 Mapping
: Wide_Maps
.Wide_Character_Mapping
)
319 return Bounded_Wide_String
;
322 (Source
: in out Bounded_Wide_String
;
323 Mapping
: Wide_Maps
.Wide_Character_Mapping
);
326 (Source
: Bounded_Wide_String
;
327 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
)
328 return Bounded_Wide_String
;
331 (Source
: in out Bounded_Wide_String
;
332 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
);
334 ---------------------------------------
335 -- String Transformation Subprograms --
336 ---------------------------------------
338 function Replace_Slice
339 (Source
: Bounded_Wide_String
;
343 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
345 procedure Replace_Slice
346 (Source
: in out Bounded_Wide_String
;
350 Drop
: Truncation
:= Error
);
353 (Source
: Bounded_Wide_String
;
355 New_Item
: Wide_String;
356 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
359 (Source
: in out Bounded_Wide_String
;
361 New_Item
: Wide_String;
362 Drop
: Truncation
:= Error
);
365 (Source
: Bounded_Wide_String
;
367 New_Item
: Wide_String;
368 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
371 (Source
: in out Bounded_Wide_String
;
373 New_Item
: Wide_String;
374 Drop
: Truncation
:= Error
);
377 (Source
: Bounded_Wide_String
;
379 Through
: Natural) return Bounded_Wide_String
;
382 (Source
: in out Bounded_Wide_String
;
386 ---------------------------------
387 -- String Selector Subprograms --
388 ---------------------------------
391 (Source
: Bounded_Wide_String
;
392 Side
: Trim_End
) return Bounded_Wide_String
;
395 (Source
: in out Bounded_Wide_String
;
399 (Source
: Bounded_Wide_String
;
400 Left
: Wide_Maps
.Wide_Character_Set
;
401 Right
: Wide_Maps
.Wide_Character_Set
) return Bounded_Wide_String
;
404 (Source
: in out Bounded_Wide_String
;
405 Left
: Wide_Maps
.Wide_Character_Set
;
406 Right
: Wide_Maps
.Wide_Character_Set
);
409 (Source
: Bounded_Wide_String
;
411 Pad
: Wide_Character := Wide_Space
;
412 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
415 (Source
: in out Bounded_Wide_String
;
417 Pad
: Wide_Character := Wide_Space
;
418 Drop
: Truncation
:= Error
);
421 (Source
: Bounded_Wide_String
;
423 Pad
: Wide_Character := Wide_Space
;
424 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
427 (Source
: in out Bounded_Wide_String
;
429 Pad
: Wide_Character := Wide_Space
;
430 Drop
: Truncation
:= Error
);
432 ------------------------------------
433 -- String Constructor Subprograms --
434 ------------------------------------
438 Right
: Wide_Character) return Bounded_Wide_String
;
442 Right
: Wide_String) return Bounded_Wide_String
;
446 Right
: Bounded_Wide_String
) return Bounded_Wide_String
;
450 Item
: Wide_Character;
451 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
456 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
460 Item
: Bounded_Wide_String
;
461 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
464 -- Most of the implementation is in the separate non generic package
465 -- Ada.Strings.Wide_Superbounded. Type Bounded_Wide_String is derived
466 -- from type Wide_Superbounded.Super_String with the maximum length
467 -- constraint. In almost all cases, the routines in Wide_Superbounded
468 -- can be called with no requirement to pass the maximum length
469 -- explicitly, since there is at least one Bounded_Wide_String argument
470 -- from which the maximum length can be obtained. For all such
471 -- routines, the implementation in this private part is simply a
472 -- renaming of the corresponding routine in the super bouded package.
474 -- The five exceptions are the * and Replicate routines operating on
475 -- character values. For these cases, we have a routine in the body
476 -- that calls the superbounded routine passing the maximum length
477 -- explicitly as an extra parameter.
479 type Bounded_Wide_String
is
480 new Wide_Superbounded
.Super_String
(Max_Length
);
481 -- Deriving Bounded_Wide_String from Wide_Superbounded.Super_String is
482 -- the real trick, it ensures that the type Bounded_Wide_String
483 -- declared in the generic instantiation is compatible with the
484 -- Super_String type declared in the Wide_Superbounded package.
486 Null_Bounded_Wide_String
: constant Bounded_Wide_String
:=
487 (Max_Length
=> Max_Length
,
491 Wide_Superbounded
.Wide_NUL
));
493 pragma Inline
(To_Bounded_Wide_String
);
495 procedure Set_Bounded_Wide_String
496 (Target
: out Bounded_Wide_String
;
497 Source
: Wide_String;
498 Drop
: Truncation
:= Error
)
499 renames Set_Super_String
;
502 (Source
: Bounded_Wide_String
) return Length_Range
503 renames Super_Length
;
505 function To_Wide_String
506 (Source
: Bounded_Wide_String
) return Wide_String
507 renames Super_To_String
;
510 (Left
: Bounded_Wide_String
;
511 Right
: Bounded_Wide_String
;
512 Drop
: Truncation
:= Error
) return Bounded_Wide_String
513 renames Super_Append
;
516 (Left
: Bounded_Wide_String
;
518 Drop
: Truncation
:= Error
) return Bounded_Wide_String
519 renames Super_Append
;
523 Right
: Bounded_Wide_String
;
524 Drop
: Truncation
:= Error
) return Bounded_Wide_String
525 renames Super_Append
;
528 (Left
: Bounded_Wide_String
;
529 Right
: Wide_Character;
530 Drop
: Truncation
:= Error
) return Bounded_Wide_String
531 renames Super_Append
;
534 (Left
: Wide_Character;
535 Right
: Bounded_Wide_String
;
536 Drop
: Truncation
:= Error
) return Bounded_Wide_String
537 renames Super_Append
;
540 (Source
: in out Bounded_Wide_String
;
541 New_Item
: Bounded_Wide_String
;
542 Drop
: Truncation
:= Error
)
543 renames Super_Append
;
546 (Source
: in out Bounded_Wide_String
;
547 New_Item
: Wide_String;
548 Drop
: Truncation
:= Error
)
549 renames Super_Append
;
552 (Source
: in out Bounded_Wide_String
;
553 New_Item
: Wide_Character;
554 Drop
: Truncation
:= Error
)
555 renames Super_Append
;
558 (Left
: Bounded_Wide_String
;
559 Right
: Bounded_Wide_String
) return Bounded_Wide_String
563 (Left
: Bounded_Wide_String
;
564 Right
: Wide_String) return Bounded_Wide_String
569 Right
: Bounded_Wide_String
) return Bounded_Wide_String
573 (Left
: Bounded_Wide_String
;
574 Right
: Wide_Character) return Bounded_Wide_String
578 (Left
: Wide_Character;
579 Right
: Bounded_Wide_String
) return Bounded_Wide_String
583 (Source
: Bounded_Wide_String
;
584 Index
: Positive) return Wide_Character
585 renames Super_Element
;
587 procedure Replace_Element
588 (Source
: in out Bounded_Wide_String
;
591 renames Super_Replace_Element
;
594 (Source
: Bounded_Wide_String
;
596 High
: Natural) return Wide_String
599 function Bounded_Slice
600 (Source
: Bounded_Wide_String
;
602 High
: Natural) return Bounded_Wide_String
605 procedure Bounded_Slice
606 (Source
: Bounded_Wide_String
;
607 Target
: out Bounded_Wide_String
;
613 (Left
: Bounded_Wide_String
;
614 Right
: Bounded_Wide_String
) return Boolean
618 (Left
: Bounded_Wide_String
;
619 Right
: Wide_String) return Boolean
624 Right
: Bounded_Wide_String
) return Boolean
628 (Left
: Bounded_Wide_String
;
629 Right
: Bounded_Wide_String
) return Boolean
633 (Left
: Bounded_Wide_String
;
634 Right
: Wide_String) return Boolean
639 Right
: Bounded_Wide_String
) return Boolean
643 (Left
: Bounded_Wide_String
;
644 Right
: Bounded_Wide_String
) return Boolean
645 renames Less_Or_Equal
;
648 (Left
: Bounded_Wide_String
;
649 Right
: Wide_String) return Boolean
650 renames Less_Or_Equal
;
654 Right
: Bounded_Wide_String
) return Boolean
655 renames Less_Or_Equal
;
658 (Left
: Bounded_Wide_String
;
659 Right
: Bounded_Wide_String
) return Boolean
663 (Left
: Bounded_Wide_String
;
664 Right
: Wide_String) return Boolean
669 Right
: Bounded_Wide_String
) return Boolean
673 (Left
: Bounded_Wide_String
;
674 Right
: Bounded_Wide_String
) return Boolean
675 renames Greater_Or_Equal
;
678 (Left
: Bounded_Wide_String
;
679 Right
: Wide_String) return Boolean
680 renames Greater_Or_Equal
;
684 Right
: Bounded_Wide_String
) return Boolean
685 renames Greater_Or_Equal
;
688 (Source
: Bounded_Wide_String
;
689 Pattern
: Wide_String;
690 Going
: Direction
:= Forward
;
691 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
696 (Source
: Bounded_Wide_String
;
697 Pattern
: Wide_String;
698 Going
: Direction
:= Forward
;
699 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
703 (Source
: Bounded_Wide_String
;
704 Set
: Wide_Maps
.Wide_Character_Set
;
705 Test
: Membership
:= Inside
;
706 Going
: Direction
:= Forward
) return Natural
710 (Source
: Bounded_Wide_String
;
711 Pattern
: Wide_String;
713 Going
: Direction
:= Forward
;
714 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
719 (Source
: Bounded_Wide_String
;
720 Pattern
: Wide_String;
722 Going
: Direction
:= Forward
;
723 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
727 (Source
: Bounded_Wide_String
;
728 Set
: Wide_Maps
.Wide_Character_Set
;
730 Test
: Membership
:= Inside
;
731 Going
: Direction
:= Forward
) return Natural
734 function Index_Non_Blank
735 (Source
: Bounded_Wide_String
;
736 Going
: Direction
:= Forward
) return Natural
737 renames Super_Index_Non_Blank
;
739 function Index_Non_Blank
740 (Source
: Bounded_Wide_String
;
742 Going
: Direction
:= Forward
) return Natural
743 renames Super_Index_Non_Blank
;
746 (Source
: Bounded_Wide_String
;
747 Pattern
: Wide_String;
748 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
753 (Source
: Bounded_Wide_String
;
754 Pattern
: Wide_String;
755 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
759 (Source
: Bounded_Wide_String
;
760 Set
: Wide_Maps
.Wide_Character_Set
) return Natural
764 (Source
: Bounded_Wide_String
;
765 Set
: Wide_Maps
.Wide_Character_Set
;
768 First
: out Positive;
770 renames Super_Find_Token
;
773 (Source
: Bounded_Wide_String
;
774 Set
: Wide_Maps
.Wide_Character_Set
;
776 First
: out Positive;
778 renames Super_Find_Token
;
781 (Source
: Bounded_Wide_String
;
782 Mapping
: Wide_Maps
.Wide_Character_Mapping
)
783 return Bounded_Wide_String
784 renames Super_Translate
;
787 (Source
: in out Bounded_Wide_String
;
788 Mapping
: Wide_Maps
.Wide_Character_Mapping
)
789 renames Super_Translate
;
792 (Source
: Bounded_Wide_String
;
793 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
)
794 return Bounded_Wide_String
795 renames Super_Translate
;
798 (Source
: in out Bounded_Wide_String
;
799 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
)
800 renames Super_Translate
;
802 function Replace_Slice
803 (Source
: Bounded_Wide_String
;
807 Drop
: Truncation
:= Error
) return Bounded_Wide_String
808 renames Super_Replace_Slice
;
810 procedure Replace_Slice
811 (Source
: in out Bounded_Wide_String
;
815 Drop
: Truncation
:= Error
)
816 renames Super_Replace_Slice
;
819 (Source
: Bounded_Wide_String
;
821 New_Item
: Wide_String;
822 Drop
: Truncation
:= Error
) return Bounded_Wide_String
823 renames Super_Insert
;
826 (Source
: in out Bounded_Wide_String
;
828 New_Item
: Wide_String;
829 Drop
: Truncation
:= Error
)
830 renames Super_Insert
;
833 (Source
: Bounded_Wide_String
;
835 New_Item
: Wide_String;
836 Drop
: Truncation
:= Error
) return Bounded_Wide_String
837 renames Super_Overwrite
;
840 (Source
: in out Bounded_Wide_String
;
842 New_Item
: Wide_String;
843 Drop
: Truncation
:= Error
)
844 renames Super_Overwrite
;
847 (Source
: Bounded_Wide_String
;
849 Through
: Natural) return Bounded_Wide_String
850 renames Super_Delete
;
853 (Source
: in out Bounded_Wide_String
;
856 renames Super_Delete
;
859 (Source
: Bounded_Wide_String
;
860 Side
: Trim_End
) return Bounded_Wide_String
864 (Source
: in out Bounded_Wide_String
;
869 (Source
: Bounded_Wide_String
;
870 Left
: Wide_Maps
.Wide_Character_Set
;
871 Right
: Wide_Maps
.Wide_Character_Set
) return Bounded_Wide_String
875 (Source
: in out Bounded_Wide_String
;
876 Left
: Wide_Maps
.Wide_Character_Set
;
877 Right
: Wide_Maps
.Wide_Character_Set
)
881 (Source
: Bounded_Wide_String
;
883 Pad
: Wide_Character := Wide_Space
;
884 Drop
: Truncation
:= Error
) return Bounded_Wide_String
888 (Source
: in out Bounded_Wide_String
;
890 Pad
: Wide_Character := Wide_Space
;
891 Drop
: Truncation
:= Error
)
895 (Source
: Bounded_Wide_String
;
897 Pad
: Wide_Character := Wide_Space
;
898 Drop
: Truncation
:= Error
) return Bounded_Wide_String
902 (Source
: in out Bounded_Wide_String
;
904 Pad
: Wide_Character := Wide_Space
;
905 Drop
: Truncation
:= Error
)
910 Right
: Bounded_Wide_String
) return Bounded_Wide_String
915 Item
: Bounded_Wide_String
;
916 Drop
: Truncation
:= Error
) return Bounded_Wide_String
917 renames Super_Replicate
;
919 end Generic_Bounded_Length
;
921 end Ada
.Strings
.Wide_Bounded
;