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-2006, 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;
53 pragma Preelaborable_Initialization
(Bounded_Wide_String
);
55 Null_Bounded_Wide_String
: constant Bounded_Wide_String
;
57 subtype Length_Range
is Natural range 0 .. Max_Length
;
59 function Length
(Source
: Bounded_Wide_String
) return Length_Range
;
61 --------------------------------------------------------
62 -- Conversion, Concatenation, and Selection Functions --
63 --------------------------------------------------------
65 function To_Bounded_Wide_String
66 (Source
: Wide_String;
67 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
69 function To_Wide_String
70 (Source
: Bounded_Wide_String
) return Wide_String;
72 procedure Set_Bounded_Wide_String
73 (Target
: out Bounded_Wide_String
;
75 Drop
: Truncation
:= Error
);
76 pragma Ada_05
(Set_Bounded_Wide_String
);
79 (Left
: Bounded_Wide_String
;
80 Right
: Bounded_Wide_String
;
81 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
84 (Left
: Bounded_Wide_String
;
86 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
90 Right
: Bounded_Wide_String
;
91 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
94 (Left
: Bounded_Wide_String
;
95 Right
: Wide_Character;
96 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
99 (Left
: Wide_Character;
100 Right
: Bounded_Wide_String
;
101 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
104 (Source
: in out Bounded_Wide_String
;
105 New_Item
: Bounded_Wide_String
;
106 Drop
: Truncation
:= Error
);
109 (Source
: in out Bounded_Wide_String
;
110 New_Item
: Wide_String;
111 Drop
: Truncation
:= Error
);
114 (Source
: in out Bounded_Wide_String
;
115 New_Item
: Wide_Character;
116 Drop
: Truncation
:= Error
);
119 (Left
: Bounded_Wide_String
;
120 Right
: Bounded_Wide_String
) return Bounded_Wide_String
;
123 (Left
: Bounded_Wide_String
;
124 Right
: Wide_String) return Bounded_Wide_String
;
128 Right
: Bounded_Wide_String
) return Bounded_Wide_String
;
131 (Left
: Bounded_Wide_String
;
132 Right
: Wide_Character) return Bounded_Wide_String
;
135 (Left
: Wide_Character;
136 Right
: Bounded_Wide_String
) return Bounded_Wide_String
;
139 (Source
: Bounded_Wide_String
;
140 Index
: Positive) return Wide_Character;
142 procedure Replace_Element
143 (Source
: in out Bounded_Wide_String
;
145 By
: Wide_Character);
148 (Source
: Bounded_Wide_String
;
150 High
: Natural) return Wide_String;
152 function Bounded_Slice
153 (Source
: Bounded_Wide_String
;
155 High
: Natural) return Bounded_Wide_String
;
156 pragma Ada_05
(Bounded_Slice
);
158 procedure Bounded_Slice
159 (Source
: Bounded_Wide_String
;
160 Target
: out Bounded_Wide_String
;
163 pragma Ada_05
(Bounded_Slice
);
166 (Left
: Bounded_Wide_String
;
167 Right
: Bounded_Wide_String
) return Boolean;
170 (Left
: Bounded_Wide_String
;
171 Right
: Wide_String) return Boolean;
175 Right
: Bounded_Wide_String
) return Boolean;
178 (Left
: Bounded_Wide_String
;
179 Right
: Bounded_Wide_String
) return Boolean;
182 (Left
: Bounded_Wide_String
;
183 Right
: Wide_String) return Boolean;
187 Right
: Bounded_Wide_String
) return Boolean;
190 (Left
: Bounded_Wide_String
;
191 Right
: Bounded_Wide_String
) return Boolean;
194 (Left
: Bounded_Wide_String
;
195 Right
: Wide_String) return Boolean;
199 Right
: Bounded_Wide_String
) return Boolean;
202 (Left
: Bounded_Wide_String
;
203 Right
: Bounded_Wide_String
) return Boolean;
206 (Left
: Bounded_Wide_String
;
207 Right
: Wide_String) return Boolean;
211 Right
: Bounded_Wide_String
) return Boolean;
214 (Left
: Bounded_Wide_String
;
215 Right
: Bounded_Wide_String
) return Boolean;
218 (Left
: Bounded_Wide_String
;
219 Right
: Wide_String) return Boolean;
223 Right
: Bounded_Wide_String
) return Boolean;
225 ----------------------
226 -- Search Functions --
227 ----------------------
230 (Source
: Bounded_Wide_String
;
231 Pattern
: Wide_String;
232 Going
: Direction
:= Forward
;
233 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
237 (Source
: Bounded_Wide_String
;
238 Pattern
: Wide_String;
239 Going
: Direction
:= Forward
;
240 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
243 (Source
: Bounded_Wide_String
;
244 Set
: Wide_Maps
.Wide_Character_Set
;
245 Test
: Membership
:= Inside
;
246 Going
: Direction
:= Forward
) return Natural;
249 (Source
: Bounded_Wide_String
;
250 Pattern
: Wide_String;
252 Going
: Direction
:= Forward
;
253 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
255 pragma Ada_05
(Index
);
258 (Source
: Bounded_Wide_String
;
259 Pattern
: Wide_String;
261 Going
: Direction
:= Forward
;
262 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
263 pragma Ada_05
(Index
);
266 (Source
: Bounded_Wide_String
;
267 Set
: Wide_Maps
.Wide_Character_Set
;
269 Test
: Membership
:= Inside
;
270 Going
: Direction
:= Forward
) return Natural;
271 pragma Ada_05
(Index
);
273 function Index_Non_Blank
274 (Source
: Bounded_Wide_String
;
275 Going
: Direction
:= Forward
) return Natural;
277 function Index_Non_Blank
278 (Source
: Bounded_Wide_String
;
280 Going
: Direction
:= Forward
) return Natural;
281 pragma Ada_05
(Index_Non_Blank
);
284 (Source
: Bounded_Wide_String
;
285 Pattern
: Wide_String;
286 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
290 (Source
: Bounded_Wide_String
;
291 Pattern
: Wide_String;
292 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
295 (Source
: Bounded_Wide_String
;
296 Set
: Wide_Maps
.Wide_Character_Set
) return Natural;
299 (Source
: Bounded_Wide_String
;
300 Set
: Wide_Maps
.Wide_Character_Set
;
302 First
: out Positive;
305 ------------------------------------
306 -- String Translation Subprograms --
307 ------------------------------------
310 (Source
: Bounded_Wide_String
;
311 Mapping
: Wide_Maps
.Wide_Character_Mapping
)
312 return Bounded_Wide_String
;
315 (Source
: in out Bounded_Wide_String
;
316 Mapping
: Wide_Maps
.Wide_Character_Mapping
);
319 (Source
: Bounded_Wide_String
;
320 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
)
321 return Bounded_Wide_String
;
324 (Source
: in out Bounded_Wide_String
;
325 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
);
327 ---------------------------------------
328 -- String Transformation Subprograms --
329 ---------------------------------------
331 function Replace_Slice
332 (Source
: Bounded_Wide_String
;
336 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
338 procedure Replace_Slice
339 (Source
: in out Bounded_Wide_String
;
343 Drop
: Truncation
:= Error
);
346 (Source
: Bounded_Wide_String
;
348 New_Item
: Wide_String;
349 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
352 (Source
: in out Bounded_Wide_String
;
354 New_Item
: Wide_String;
355 Drop
: Truncation
:= Error
);
358 (Source
: Bounded_Wide_String
;
360 New_Item
: Wide_String;
361 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
364 (Source
: in out Bounded_Wide_String
;
366 New_Item
: Wide_String;
367 Drop
: Truncation
:= Error
);
370 (Source
: Bounded_Wide_String
;
372 Through
: Natural) return Bounded_Wide_String
;
375 (Source
: in out Bounded_Wide_String
;
379 ---------------------------------
380 -- String Selector Subprograms --
381 ---------------------------------
384 (Source
: Bounded_Wide_String
;
385 Side
: Trim_End
) return Bounded_Wide_String
;
388 (Source
: in out Bounded_Wide_String
;
392 (Source
: Bounded_Wide_String
;
393 Left
: Wide_Maps
.Wide_Character_Set
;
394 Right
: Wide_Maps
.Wide_Character_Set
) return Bounded_Wide_String
;
397 (Source
: in out Bounded_Wide_String
;
398 Left
: Wide_Maps
.Wide_Character_Set
;
399 Right
: Wide_Maps
.Wide_Character_Set
);
402 (Source
: Bounded_Wide_String
;
404 Pad
: Wide_Character := Wide_Space
;
405 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
408 (Source
: in out Bounded_Wide_String
;
410 Pad
: Wide_Character := Wide_Space
;
411 Drop
: Truncation
:= Error
);
414 (Source
: Bounded_Wide_String
;
416 Pad
: Wide_Character := Wide_Space
;
417 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
420 (Source
: in out Bounded_Wide_String
;
422 Pad
: Wide_Character := Wide_Space
;
423 Drop
: Truncation
:= Error
);
425 ------------------------------------
426 -- String Constructor Subprograms --
427 ------------------------------------
431 Right
: Wide_Character) return Bounded_Wide_String
;
435 Right
: Wide_String) return Bounded_Wide_String
;
439 Right
: Bounded_Wide_String
) return Bounded_Wide_String
;
443 Item
: Wide_Character;
444 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
449 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
453 Item
: Bounded_Wide_String
;
454 Drop
: Truncation
:= Error
) return Bounded_Wide_String
;
457 -- Most of the implementation is in the separate non generic package
458 -- Ada.Strings.Wide_Superbounded. Type Bounded_Wide_String is derived
459 -- from type Wide_Superbounded.Super_String with the maximum length
460 -- constraint. In almost all cases, the routines in Wide_Superbounded
461 -- can be called with no requirement to pass the maximum length
462 -- explicitly, since there is at least one Bounded_Wide_String argument
463 -- from which the maximum length can be obtained. For all such
464 -- routines, the implementation in this private part is simply a
465 -- renaming of the corresponding routine in the super bouded package.
467 -- The five exceptions are the * and Replicate routines operating on
468 -- character values. For these cases, we have a routine in the body
469 -- that calls the superbounded routine passing the maximum length
470 -- explicitly as an extra parameter.
472 type Bounded_Wide_String
is
473 new Wide_Superbounded
.Super_String
(Max_Length
);
474 -- Deriving Bounded_Wide_String from Wide_Superbounded.Super_String is
475 -- the real trick, it ensures that the type Bounded_Wide_String
476 -- declared in the generic instantiation is compatible with the
477 -- Super_String type declared in the Wide_Superbounded package.
479 Null_Bounded_Wide_String
: constant Bounded_Wide_String
:=
480 (Max_Length
=> Max_Length
,
484 Wide_Superbounded
.Wide_NUL
));
486 pragma Inline
(To_Bounded_Wide_String
);
488 procedure Set_Bounded_Wide_String
489 (Target
: out Bounded_Wide_String
;
490 Source
: Wide_String;
491 Drop
: Truncation
:= Error
)
492 renames Set_Super_String
;
495 (Source
: Bounded_Wide_String
) return Length_Range
496 renames Super_Length
;
498 function To_Wide_String
499 (Source
: Bounded_Wide_String
) return Wide_String
500 renames Super_To_String
;
503 (Left
: Bounded_Wide_String
;
504 Right
: Bounded_Wide_String
;
505 Drop
: Truncation
:= Error
) return Bounded_Wide_String
506 renames Super_Append
;
509 (Left
: Bounded_Wide_String
;
511 Drop
: Truncation
:= Error
) return Bounded_Wide_String
512 renames Super_Append
;
516 Right
: Bounded_Wide_String
;
517 Drop
: Truncation
:= Error
) return Bounded_Wide_String
518 renames Super_Append
;
521 (Left
: Bounded_Wide_String
;
522 Right
: Wide_Character;
523 Drop
: Truncation
:= Error
) return Bounded_Wide_String
524 renames Super_Append
;
527 (Left
: Wide_Character;
528 Right
: Bounded_Wide_String
;
529 Drop
: Truncation
:= Error
) return Bounded_Wide_String
530 renames Super_Append
;
533 (Source
: in out Bounded_Wide_String
;
534 New_Item
: Bounded_Wide_String
;
535 Drop
: Truncation
:= Error
)
536 renames Super_Append
;
539 (Source
: in out Bounded_Wide_String
;
540 New_Item
: Wide_String;
541 Drop
: Truncation
:= Error
)
542 renames Super_Append
;
545 (Source
: in out Bounded_Wide_String
;
546 New_Item
: Wide_Character;
547 Drop
: Truncation
:= Error
)
548 renames Super_Append
;
551 (Left
: Bounded_Wide_String
;
552 Right
: Bounded_Wide_String
) return Bounded_Wide_String
556 (Left
: Bounded_Wide_String
;
557 Right
: Wide_String) return Bounded_Wide_String
562 Right
: Bounded_Wide_String
) return Bounded_Wide_String
566 (Left
: Bounded_Wide_String
;
567 Right
: Wide_Character) return Bounded_Wide_String
571 (Left
: Wide_Character;
572 Right
: Bounded_Wide_String
) return Bounded_Wide_String
576 (Source
: Bounded_Wide_String
;
577 Index
: Positive) return Wide_Character
578 renames Super_Element
;
580 procedure Replace_Element
581 (Source
: in out Bounded_Wide_String
;
584 renames Super_Replace_Element
;
587 (Source
: Bounded_Wide_String
;
589 High
: Natural) return Wide_String
592 function Bounded_Slice
593 (Source
: Bounded_Wide_String
;
595 High
: Natural) return Bounded_Wide_String
598 procedure Bounded_Slice
599 (Source
: Bounded_Wide_String
;
600 Target
: out Bounded_Wide_String
;
606 (Left
: Bounded_Wide_String
;
607 Right
: Bounded_Wide_String
) return Boolean
611 (Left
: Bounded_Wide_String
;
612 Right
: Wide_String) return Boolean
617 Right
: Bounded_Wide_String
) return Boolean
621 (Left
: Bounded_Wide_String
;
622 Right
: Bounded_Wide_String
) return Boolean
626 (Left
: Bounded_Wide_String
;
627 Right
: Wide_String) return Boolean
632 Right
: Bounded_Wide_String
) return Boolean
636 (Left
: Bounded_Wide_String
;
637 Right
: Bounded_Wide_String
) return Boolean
638 renames Less_Or_Equal
;
641 (Left
: Bounded_Wide_String
;
642 Right
: Wide_String) return Boolean
643 renames Less_Or_Equal
;
647 Right
: Bounded_Wide_String
) return Boolean
648 renames Less_Or_Equal
;
651 (Left
: Bounded_Wide_String
;
652 Right
: Bounded_Wide_String
) return Boolean
656 (Left
: Bounded_Wide_String
;
657 Right
: Wide_String) return Boolean
662 Right
: Bounded_Wide_String
) return Boolean
666 (Left
: Bounded_Wide_String
;
667 Right
: Bounded_Wide_String
) return Boolean
668 renames Greater_Or_Equal
;
671 (Left
: Bounded_Wide_String
;
672 Right
: Wide_String) return Boolean
673 renames Greater_Or_Equal
;
677 Right
: Bounded_Wide_String
) return Boolean
678 renames Greater_Or_Equal
;
681 (Source
: Bounded_Wide_String
;
682 Pattern
: Wide_String;
683 Going
: Direction
:= Forward
;
684 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
689 (Source
: Bounded_Wide_String
;
690 Pattern
: Wide_String;
691 Going
: Direction
:= Forward
;
692 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
696 (Source
: Bounded_Wide_String
;
697 Set
: Wide_Maps
.Wide_Character_Set
;
698 Test
: Membership
:= Inside
;
699 Going
: Direction
:= Forward
) return Natural
703 (Source
: Bounded_Wide_String
;
704 Pattern
: Wide_String;
706 Going
: Direction
:= Forward
;
707 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
712 (Source
: Bounded_Wide_String
;
713 Pattern
: Wide_String;
715 Going
: Direction
:= Forward
;
716 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
720 (Source
: Bounded_Wide_String
;
721 Set
: Wide_Maps
.Wide_Character_Set
;
723 Test
: Membership
:= Inside
;
724 Going
: Direction
:= Forward
) return Natural
727 function Index_Non_Blank
728 (Source
: Bounded_Wide_String
;
729 Going
: Direction
:= Forward
) return Natural
730 renames Super_Index_Non_Blank
;
732 function Index_Non_Blank
733 (Source
: Bounded_Wide_String
;
735 Going
: Direction
:= Forward
) return Natural
736 renames Super_Index_Non_Blank
;
739 (Source
: Bounded_Wide_String
;
740 Pattern
: Wide_String;
741 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
746 (Source
: Bounded_Wide_String
;
747 Pattern
: Wide_String;
748 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
752 (Source
: Bounded_Wide_String
;
753 Set
: Wide_Maps
.Wide_Character_Set
) return Natural
757 (Source
: Bounded_Wide_String
;
758 Set
: Wide_Maps
.Wide_Character_Set
;
760 First
: out Positive;
762 renames Super_Find_Token
;
765 (Source
: Bounded_Wide_String
;
766 Mapping
: Wide_Maps
.Wide_Character_Mapping
)
767 return Bounded_Wide_String
768 renames Super_Translate
;
771 (Source
: in out Bounded_Wide_String
;
772 Mapping
: Wide_Maps
.Wide_Character_Mapping
)
773 renames Super_Translate
;
776 (Source
: Bounded_Wide_String
;
777 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
)
778 return Bounded_Wide_String
779 renames Super_Translate
;
782 (Source
: in out Bounded_Wide_String
;
783 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
)
784 renames Super_Translate
;
786 function Replace_Slice
787 (Source
: Bounded_Wide_String
;
791 Drop
: Truncation
:= Error
) return Bounded_Wide_String
792 renames Super_Replace_Slice
;
794 procedure Replace_Slice
795 (Source
: in out Bounded_Wide_String
;
799 Drop
: Truncation
:= Error
)
800 renames Super_Replace_Slice
;
803 (Source
: Bounded_Wide_String
;
805 New_Item
: Wide_String;
806 Drop
: Truncation
:= Error
) return Bounded_Wide_String
807 renames Super_Insert
;
810 (Source
: in out Bounded_Wide_String
;
812 New_Item
: Wide_String;
813 Drop
: Truncation
:= Error
)
814 renames Super_Insert
;
817 (Source
: Bounded_Wide_String
;
819 New_Item
: Wide_String;
820 Drop
: Truncation
:= Error
) return Bounded_Wide_String
821 renames Super_Overwrite
;
824 (Source
: in out Bounded_Wide_String
;
826 New_Item
: Wide_String;
827 Drop
: Truncation
:= Error
)
828 renames Super_Overwrite
;
831 (Source
: Bounded_Wide_String
;
833 Through
: Natural) return Bounded_Wide_String
834 renames Super_Delete
;
837 (Source
: in out Bounded_Wide_String
;
840 renames Super_Delete
;
843 (Source
: Bounded_Wide_String
;
844 Side
: Trim_End
) return Bounded_Wide_String
848 (Source
: in out Bounded_Wide_String
;
853 (Source
: Bounded_Wide_String
;
854 Left
: Wide_Maps
.Wide_Character_Set
;
855 Right
: Wide_Maps
.Wide_Character_Set
) return Bounded_Wide_String
859 (Source
: in out Bounded_Wide_String
;
860 Left
: Wide_Maps
.Wide_Character_Set
;
861 Right
: Wide_Maps
.Wide_Character_Set
)
865 (Source
: Bounded_Wide_String
;
867 Pad
: Wide_Character := Wide_Space
;
868 Drop
: Truncation
:= Error
) return Bounded_Wide_String
872 (Source
: in out Bounded_Wide_String
;
874 Pad
: Wide_Character := Wide_Space
;
875 Drop
: Truncation
:= Error
)
879 (Source
: Bounded_Wide_String
;
881 Pad
: Wide_Character := Wide_Space
;
882 Drop
: Truncation
:= Error
) return Bounded_Wide_String
886 (Source
: in out Bounded_Wide_String
;
888 Pad
: Wide_Character := Wide_Space
;
889 Drop
: Truncation
:= Error
)
894 Right
: Bounded_Wide_String
) return Bounded_Wide_String
899 Item
: Bounded_Wide_String
;
900 Drop
: Truncation
:= Error
) return Bounded_Wide_String
901 renames Super_Replicate
;
903 end Generic_Bounded_Length
;
905 end Ada
.Strings
.Wide_Bounded
;