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-2005, 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 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. --
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. --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
36 ------------------------------------------------------------------------------
38 with Ada
.Strings
.Wide_Maps
;
39 with Ada
.Strings
.Wide_Superbounded
;
41 package Ada
.Strings
.Wide_Bounded
is
46 -- Maximum length of a Bounded_Wide_String
48 package Generic_Bounded_Length
is
50 Max_Length
: constant Positive := Max
;
52 type Bounded_Wide_String
is private;
54 Null_Bounded_Wide_String
: constant Bounded_Wide_String
;
56 subtype Length_Range
is Natural range 0 .. Max_Length
;
58 function Length
(Source
: Bounded_Wide_String
) return Length_Range
;
60 --------------------------------------------------------
61 -- Conversion, Concatenation, and Selection Functions --
62 --------------------------------------------------------
64 function To_Bounded_Wide_String
65 (Source
: Wide_String;
66 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
68 function To_Wide_String
69 (Source
: Bounded_Wide_String
) return Wide_String;
71 procedure Set_Bounded_Wide_String
72 (Target
: out Bounded_Wide_String
;
74 Drop
: Truncation
:= Error
);
75 pragma Ada_05
(Set_Bounded_Wide_String
);
78 (Left
: Bounded_Wide_String
;
79 Right
: Bounded_Wide_String
;
80 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
83 (Left
: Bounded_Wide_String
;
85 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
89 Right
: Bounded_Wide_String
;
90 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
93 (Left
: Bounded_Wide_String
;
94 Right
: Wide_Character;
95 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
98 (Left
: Wide_Character;
99 Right
: Bounded_Wide_String
;
100 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
103 (Source
: in out Bounded_Wide_String
;
104 New_Item
: Bounded_Wide_String
;
105 Drop
: Truncation
:= Error
);
108 (Source
: in out Bounded_Wide_String
;
109 New_Item
: Wide_String;
110 Drop
: Truncation
:= Error
);
113 (Source
: in out Bounded_Wide_String
;
114 New_Item
: Wide_Character;
115 Drop
: Truncation
:= Error
);
118 (Left
: Bounded_Wide_String
;
119 Right
: Bounded_Wide_String
) return Bounded_Wide_String
;
122 (Left
: Bounded_Wide_String
;
123 Right
: Wide_String) return Bounded_Wide_String
;
127 Right
: Bounded_Wide_String
) return Bounded_Wide_String
;
130 (Left
: Bounded_Wide_String
;
131 Right
: Wide_Character) return Bounded_Wide_String
;
134 (Left
: Wide_Character;
135 Right
: Bounded_Wide_String
) return Bounded_Wide_String
;
138 (Source
: Bounded_Wide_String
;
139 Index
: Positive) return Wide_Character;
141 procedure Replace_Element
142 (Source
: in out Bounded_Wide_String
;
144 By
: Wide_Character);
147 (Source
: Bounded_Wide_String
;
149 High
: Natural) return Wide_String;
151 function Bounded_Slice
152 (Source
: Bounded_Wide_String
;
154 High
: Natural) return Bounded_Wide_String
;
155 pragma Ada_05
(Bounded_Slice
);
157 procedure Bounded_Slice
158 (Source
: Bounded_Wide_String
;
159 Target
: out Bounded_Wide_String
;
162 pragma Ada_05
(Bounded_Slice
);
165 (Left
: Bounded_Wide_String
;
166 Right
: Bounded_Wide_String
) return Boolean;
169 (Left
: Bounded_Wide_String
;
170 Right
: Wide_String) return Boolean;
174 Right
: Bounded_Wide_String
) return Boolean;
177 (Left
: Bounded_Wide_String
;
178 Right
: Bounded_Wide_String
) return Boolean;
181 (Left
: Bounded_Wide_String
;
182 Right
: Wide_String) return Boolean;
186 Right
: Bounded_Wide_String
) return Boolean;
189 (Left
: Bounded_Wide_String
;
190 Right
: Bounded_Wide_String
) return Boolean;
193 (Left
: Bounded_Wide_String
;
194 Right
: Wide_String) return Boolean;
198 Right
: Bounded_Wide_String
) return Boolean;
201 (Left
: Bounded_Wide_String
;
202 Right
: Bounded_Wide_String
) return Boolean;
205 (Left
: Bounded_Wide_String
;
206 Right
: Wide_String) return Boolean;
210 Right
: Bounded_Wide_String
) return Boolean;
213 (Left
: Bounded_Wide_String
;
214 Right
: Bounded_Wide_String
) return Boolean;
217 (Left
: Bounded_Wide_String
;
218 Right
: Wide_String) return Boolean;
222 Right
: Bounded_Wide_String
) return Boolean;
224 ----------------------
225 -- Search Functions --
226 ----------------------
229 (Source
: Bounded_Wide_String
;
230 Pattern
: Wide_String;
231 Going
: Direction
:= Forward
;
232 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
236 (Source
: Bounded_Wide_String
;
237 Pattern
: Wide_String;
238 Going
: Direction
:= Forward
;
239 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
242 (Source
: Bounded_Wide_String
;
243 Set
: Wide_Maps
.Wide_Character_Set
;
244 Test
: Membership
:= Inside
;
245 Going
: Direction
:= Forward
) return Natural;
248 (Source
: Bounded_Wide_String
;
249 Pattern
: Wide_String;
251 Going
: Direction
:= Forward
;
252 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
254 pragma Ada_05
(Index
);
257 (Source
: Bounded_Wide_String
;
258 Pattern
: Wide_String;
260 Going
: Direction
:= Forward
;
261 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
262 pragma Ada_05
(Index
);
265 (Source
: Bounded_Wide_String
;
266 Set
: Wide_Maps
.Wide_Character_Set
;
268 Test
: Membership
:= Inside
;
269 Going
: Direction
:= Forward
) return Natural;
270 pragma Ada_05
(Index
);
272 function Index_Non_Blank
273 (Source
: Bounded_Wide_String
;
274 Going
: Direction
:= Forward
) return Natural;
276 function Index_Non_Blank
277 (Source
: Bounded_Wide_String
;
279 Going
: Direction
:= Forward
) return Natural;
280 pragma Ada_05
(Index_Non_Blank
);
283 (Source
: Bounded_Wide_String
;
284 Pattern
: Wide_String;
285 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
289 (Source
: Bounded_Wide_String
;
290 Pattern
: Wide_String;
291 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
294 (Source
: Bounded_Wide_String
;
295 Set
: Wide_Maps
.Wide_Character_Set
) return Natural;
298 (Source
: Bounded_Wide_String
;
299 Set
: Wide_Maps
.Wide_Character_Set
;
301 First
: out Positive;
304 ------------------------------------
305 -- String Translation Subprograms --
306 ------------------------------------
309 (Source
: Bounded_Wide_String
;
310 Mapping
: Wide_Maps
.Wide_Character_Mapping
)
311 return Bounded_Wide_String
;
314 (Source
: in out Bounded_Wide_String
;
315 Mapping
: Wide_Maps
.Wide_Character_Mapping
);
318 (Source
: Bounded_Wide_String
;
319 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
)
320 return Bounded_Wide_String
;
323 (Source
: in out Bounded_Wide_String
;
324 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
);
326 ---------------------------------------
327 -- String Transformation Subprograms --
328 ---------------------------------------
330 function Replace_Slice
331 (Source
: Bounded_Wide_String
;
335 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
337 procedure Replace_Slice
338 (Source
: in out Bounded_Wide_String
;
342 Drop
: Truncation
:= Error
);
345 (Source
: Bounded_Wide_String
;
347 New_Item
: Wide_String;
348 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
351 (Source
: in out Bounded_Wide_String
;
353 New_Item
: Wide_String;
354 Drop
: Truncation
:= Error
);
357 (Source
: Bounded_Wide_String
;
359 New_Item
: Wide_String;
360 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
363 (Source
: in out Bounded_Wide_String
;
365 New_Item
: Wide_String;
366 Drop
: Truncation
:= Error
);
369 (Source
: Bounded_Wide_String
;
371 Through
: Natural) return Bounded_Wide_String
;
374 (Source
: in out Bounded_Wide_String
;
378 ---------------------------------
379 -- String Selector Subprograms --
380 ---------------------------------
383 (Source
: Bounded_Wide_String
;
384 Side
: Trim_End
) return Bounded_Wide_String
;
387 (Source
: in out Bounded_Wide_String
;
391 (Source
: Bounded_Wide_String
;
392 Left
: Wide_Maps
.Wide_Character_Set
;
393 Right
: Wide_Maps
.Wide_Character_Set
) return Bounded_Wide_String
;
396 (Source
: in out Bounded_Wide_String
;
397 Left
: Wide_Maps
.Wide_Character_Set
;
398 Right
: Wide_Maps
.Wide_Character_Set
);
401 (Source
: Bounded_Wide_String
;
403 Pad
: Wide_Character := Wide_Space
;
404 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
407 (Source
: in out Bounded_Wide_String
;
409 Pad
: Wide_Character := Wide_Space
;
410 Drop
: Truncation
:= Error
);
413 (Source
: Bounded_Wide_String
;
415 Pad
: Wide_Character := Wide_Space
;
416 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
419 (Source
: in out Bounded_Wide_String
;
421 Pad
: Wide_Character := Wide_Space
;
422 Drop
: Truncation
:= Error
);
424 ------------------------------------
425 -- String Constructor Subprograms --
426 ------------------------------------
430 Right
: Wide_Character) return Bounded_Wide_String
;
434 Right
: Wide_String) return Bounded_Wide_String
;
438 Right
: Bounded_Wide_String
) return Bounded_Wide_String
;
442 Item
: Wide_Character;
443 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
448 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
452 Item
: Bounded_Wide_String
;
453 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
456 -- Most of the implementation is in the separate non generic package
457 -- Ada.Strings.Wide_Superbounded. Type Bounded_Wide_String is derived
458 -- from type Wide_Superbounded.Super_String with the maximum length
459 -- constraint. In almost all cases, the routines in Wide_Superbounded
460 -- can be called with no requirement to pass the maximum length
461 -- explicitly, since there is at least one Bounded_Wide_String argument
462 -- from which the maximum length can be obtained. For all such
463 -- routines, the implementation in this private part is simply a
464 -- renaming of the corresponding routine in the super bouded package.
466 -- The five exceptions are the * and Replicate routines operating on
467 -- character values. For these cases, we have a routine in the body
468 -- that calls the superbounded routine passing the maximum length
469 -- explicitly as an extra parameter.
471 type Bounded_Wide_String
is
472 new Wide_Superbounded
.Super_String
(Max_Length
);
473 -- Deriving Bounded_Wide_String from Wide_Superbounded.Super_String is
474 -- the real trick, it ensures that the type Bounded_Wide_String
475 -- declared in the generic instantiation is compatible with the
476 -- Super_String type declared in the Wide_Superbounded package.
478 Null_Bounded_Wide_String
: constant Bounded_Wide_String
:=
479 (Max_Length
=> Max_Length
,
483 Wide_Superbounded
.Wide_NUL
));
485 pragma Inline
(To_Bounded_Wide_String
);
487 procedure Set_Bounded_Wide_String
488 (Target
: out Bounded_Wide_String
;
489 Source
: Wide_String;
490 Drop
: Truncation
:= Error
)
491 renames Set_Super_String
;
494 (Source
: Bounded_Wide_String
) return Length_Range
495 renames Super_Length
;
497 function To_Wide_String
498 (Source
: Bounded_Wide_String
) return Wide_String
499 renames Super_To_String
;
502 (Left
: Bounded_Wide_String
;
503 Right
: Bounded_Wide_String
;
504 Drop
: Truncation
:= Error
) return Bounded_Wide_String
505 renames Super_Append
;
508 (Left
: Bounded_Wide_String
;
510 Drop
: Truncation
:= Error
) return Bounded_Wide_String
511 renames Super_Append
;
515 Right
: Bounded_Wide_String
;
516 Drop
: Truncation
:= Error
) return Bounded_Wide_String
517 renames Super_Append
;
520 (Left
: Bounded_Wide_String
;
521 Right
: Wide_Character;
522 Drop
: Truncation
:= Error
) return Bounded_Wide_String
523 renames Super_Append
;
526 (Left
: Wide_Character;
527 Right
: Bounded_Wide_String
;
528 Drop
: Truncation
:= Error
) return Bounded_Wide_String
529 renames Super_Append
;
532 (Source
: in out Bounded_Wide_String
;
533 New_Item
: Bounded_Wide_String
;
534 Drop
: Truncation
:= Error
)
535 renames Super_Append
;
538 (Source
: in out Bounded_Wide_String
;
539 New_Item
: Wide_String;
540 Drop
: Truncation
:= Error
)
541 renames Super_Append
;
544 (Source
: in out Bounded_Wide_String
;
545 New_Item
: Wide_Character;
546 Drop
: Truncation
:= Error
)
547 renames Super_Append
;
550 (Left
: Bounded_Wide_String
;
551 Right
: Bounded_Wide_String
) return Bounded_Wide_String
555 (Left
: Bounded_Wide_String
;
556 Right
: Wide_String) return Bounded_Wide_String
561 Right
: Bounded_Wide_String
) return Bounded_Wide_String
565 (Left
: Bounded_Wide_String
;
566 Right
: Wide_Character) return Bounded_Wide_String
570 (Left
: Wide_Character;
571 Right
: Bounded_Wide_String
) return Bounded_Wide_String
575 (Source
: Bounded_Wide_String
;
576 Index
: Positive) return Wide_Character
577 renames Super_Element
;
579 procedure Replace_Element
580 (Source
: in out Bounded_Wide_String
;
583 renames Super_Replace_Element
;
586 (Source
: Bounded_Wide_String
;
588 High
: Natural) return Wide_String
591 function Bounded_Slice
592 (Source
: Bounded_Wide_String
;
594 High
: Natural) return Bounded_Wide_String
597 procedure Bounded_Slice
598 (Source
: Bounded_Wide_String
;
599 Target
: out Bounded_Wide_String
;
605 (Left
: Bounded_Wide_String
;
606 Right
: Bounded_Wide_String
) return Boolean
610 (Left
: Bounded_Wide_String
;
611 Right
: Wide_String) return Boolean
616 Right
: Bounded_Wide_String
) return Boolean
620 (Left
: Bounded_Wide_String
;
621 Right
: Bounded_Wide_String
) return Boolean
625 (Left
: Bounded_Wide_String
;
626 Right
: Wide_String) return Boolean
631 Right
: Bounded_Wide_String
) return Boolean
635 (Left
: Bounded_Wide_String
;
636 Right
: Bounded_Wide_String
) return Boolean
637 renames Less_Or_Equal
;
640 (Left
: Bounded_Wide_String
;
641 Right
: Wide_String) return Boolean
642 renames Less_Or_Equal
;
646 Right
: Bounded_Wide_String
) return Boolean
647 renames Less_Or_Equal
;
650 (Left
: Bounded_Wide_String
;
651 Right
: Bounded_Wide_String
) return Boolean
655 (Left
: Bounded_Wide_String
;
656 Right
: Wide_String) return Boolean
661 Right
: Bounded_Wide_String
) return Boolean
665 (Left
: Bounded_Wide_String
;
666 Right
: Bounded_Wide_String
) return Boolean
667 renames Greater_Or_Equal
;
670 (Left
: Bounded_Wide_String
;
671 Right
: Wide_String) return Boolean
672 renames Greater_Or_Equal
;
676 Right
: Bounded_Wide_String
) return Boolean
677 renames Greater_Or_Equal
;
680 (Source
: Bounded_Wide_String
;
681 Pattern
: Wide_String;
682 Going
: Direction
:= Forward
;
683 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
688 (Source
: Bounded_Wide_String
;
689 Pattern
: Wide_String;
690 Going
: Direction
:= Forward
;
691 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
695 (Source
: Bounded_Wide_String
;
696 Set
: Wide_Maps
.Wide_Character_Set
;
697 Test
: Membership
:= Inside
;
698 Going
: Direction
:= Forward
) return Natural
702 (Source
: Bounded_Wide_String
;
703 Pattern
: Wide_String;
705 Going
: Direction
:= Forward
;
706 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
711 (Source
: Bounded_Wide_String
;
712 Pattern
: Wide_String;
714 Going
: Direction
:= Forward
;
715 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
719 (Source
: Bounded_Wide_String
;
720 Set
: Wide_Maps
.Wide_Character_Set
;
722 Test
: Membership
:= Inside
;
723 Going
: Direction
:= Forward
) return Natural
726 function Index_Non_Blank
727 (Source
: Bounded_Wide_String
;
728 Going
: Direction
:= Forward
) return Natural
729 renames Super_Index_Non_Blank
;
731 function Index_Non_Blank
732 (Source
: Bounded_Wide_String
;
734 Going
: Direction
:= Forward
) return Natural
735 renames Super_Index_Non_Blank
;
738 (Source
: Bounded_Wide_String
;
739 Pattern
: Wide_String;
740 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
745 (Source
: Bounded_Wide_String
;
746 Pattern
: Wide_String;
747 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
751 (Source
: Bounded_Wide_String
;
752 Set
: Wide_Maps
.Wide_Character_Set
) return Natural
756 (Source
: Bounded_Wide_String
;
757 Set
: Wide_Maps
.Wide_Character_Set
;
759 First
: out Positive;
761 renames Super_Find_Token
;
764 (Source
: Bounded_Wide_String
;
765 Mapping
: Wide_Maps
.Wide_Character_Mapping
)
766 return Bounded_Wide_String
767 renames Super_Translate
;
770 (Source
: in out Bounded_Wide_String
;
771 Mapping
: Wide_Maps
.Wide_Character_Mapping
)
772 renames Super_Translate
;
775 (Source
: Bounded_Wide_String
;
776 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
)
777 return Bounded_Wide_String
778 renames Super_Translate
;
781 (Source
: in out Bounded_Wide_String
;
782 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
)
783 renames Super_Translate
;
785 function Replace_Slice
786 (Source
: Bounded_Wide_String
;
790 Drop
: Truncation
:= Error
) return Bounded_Wide_String
791 renames Super_Replace_Slice
;
793 procedure Replace_Slice
794 (Source
: in out Bounded_Wide_String
;
798 Drop
: Truncation
:= Error
)
799 renames Super_Replace_Slice
;
802 (Source
: Bounded_Wide_String
;
804 New_Item
: Wide_String;
805 Drop
: Truncation
:= Error
) return Bounded_Wide_String
806 renames Super_Insert
;
809 (Source
: in out Bounded_Wide_String
;
811 New_Item
: Wide_String;
812 Drop
: Truncation
:= Error
)
813 renames Super_Insert
;
816 (Source
: Bounded_Wide_String
;
818 New_Item
: Wide_String;
819 Drop
: Truncation
:= Error
) return Bounded_Wide_String
820 renames Super_Overwrite
;
823 (Source
: in out Bounded_Wide_String
;
825 New_Item
: Wide_String;
826 Drop
: Truncation
:= Error
)
827 renames Super_Overwrite
;
830 (Source
: Bounded_Wide_String
;
832 Through
: Natural) return Bounded_Wide_String
833 renames Super_Delete
;
836 (Source
: in out Bounded_Wide_String
;
839 renames Super_Delete
;
842 (Source
: Bounded_Wide_String
;
843 Side
: Trim_End
) return Bounded_Wide_String
847 (Source
: in out Bounded_Wide_String
;
852 (Source
: Bounded_Wide_String
;
853 Left
: Wide_Maps
.Wide_Character_Set
;
854 Right
: Wide_Maps
.Wide_Character_Set
) return Bounded_Wide_String
858 (Source
: in out Bounded_Wide_String
;
859 Left
: Wide_Maps
.Wide_Character_Set
;
860 Right
: Wide_Maps
.Wide_Character_Set
)
864 (Source
: Bounded_Wide_String
;
866 Pad
: Wide_Character := Wide_Space
;
867 Drop
: Truncation
:= Error
) return Bounded_Wide_String
871 (Source
: in out Bounded_Wide_String
;
873 Pad
: Wide_Character := Wide_Space
;
874 Drop
: Truncation
:= Error
)
878 (Source
: Bounded_Wide_String
;
880 Pad
: Wide_Character := Wide_Space
;
881 Drop
: Truncation
:= Error
) return Bounded_Wide_String
885 (Source
: in out Bounded_Wide_String
;
887 Pad
: Wide_Character := Wide_Space
;
888 Drop
: Truncation
:= Error
)
893 Right
: Bounded_Wide_String
) return Bounded_Wide_String
898 Item
: Bounded_Wide_String
;
899 Drop
: Truncation
:= Error
) return Bounded_Wide_String
900 renames Super_Replicate
;
902 end Generic_Bounded_Length
;
904 end Ada
.Strings
.Wide_Bounded
;