1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . S T R I N G S . S U P E R B O U N D E D --
9 -- Copyright (C) 2003-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with Ada
.Strings
.Maps
; use Ada
.Strings
.Maps
;
33 with Ada
.Strings
.Search
;
35 package body Ada
.Strings
.Superbounded
is
43 Right
: Super_String
) return Super_String
46 return Result
: Super_String
(Left
.Max_Length
) do
48 Llen
: constant Natural := Left
.Current_Length
;
49 Rlen
: constant Natural := Right
.Current_Length
;
50 Nlen
: constant Natural := Llen
+ Rlen
;
52 if Nlen
> Left
.Max_Length
then
53 raise Ada
.Strings
.Length_Error
;
56 Result
.Current_Length
:= Nlen
;
57 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
58 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
.Data
(1 .. Rlen
);
65 Right
: String) return Super_String
68 return Result
: Super_String
(Left
.Max_Length
) do
70 Llen
: constant Natural := Left
.Current_Length
;
71 Nlen
: constant Natural := Llen
+ Right
'Length;
73 if Nlen
> Left
.Max_Length
then
74 raise Ada
.Strings
.Length_Error
;
77 Result
.Current_Length
:= Nlen
;
78 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
79 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
;
86 Right
: Super_String
) return Super_String
90 return Result
: Super_String
(Right
.Max_Length
) do
92 Llen
: constant Natural := Left
'Length;
93 Rlen
: constant Natural := Right
.Current_Length
;
94 Nlen
: constant Natural := Llen
+ Rlen
;
96 if Nlen
> Right
.Max_Length
then
97 raise Ada
.Strings
.Length_Error
;
100 Result
.Current_Length
:= Nlen
;
101 Result
.Data
(1 .. Llen
) := Left
;
102 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
.Data
(1 .. Rlen
);
108 (Left
: Super_String
;
109 Right
: Character) return Super_String
112 return Result
: Super_String
(Left
.Max_Length
) do
114 Llen
: constant Natural := Left
.Current_Length
;
116 if Llen
= Left
.Max_Length
then
117 raise Ada
.Strings
.Length_Error
;
120 Result
.Current_Length
:= Llen
+ 1;
121 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
122 Result
.Data
(Result
.Current_Length
) := Right
;
129 Right
: Super_String
) return Super_String
132 return Result
: Super_String
(Right
.Max_Length
) do
134 Rlen
: constant Natural := Right
.Current_Length
;
136 if Rlen
= Right
.Max_Length
then
137 raise Ada
.Strings
.Length_Error
;
140 Result
.Current_Length
:= Rlen
+ 1;
141 Result
.Data
(1) := Left
;
142 Result
.Data
(2 .. Result
.Current_Length
) :=
143 Right
.Data
(1 .. Rlen
);
153 (Left
: Super_String
;
154 Right
: Super_String
) return Boolean
157 return Left
.Current_Length
= Right
.Current_Length
158 and then Left
.Data
(1 .. Left
.Current_Length
) =
159 Right
.Data
(1 .. Right
.Current_Length
);
163 (Left
: Super_String
;
164 Right
: String) return Boolean
167 return Left
.Current_Length
= Right
'Length
168 and then Left
.Data
(1 .. Left
.Current_Length
) = Right
;
173 Right
: Super_String
) return Boolean
176 return Left
'Length = Right
.Current_Length
177 and then Left
= Right
.Data
(1 .. Right
.Current_Length
);
185 (Left
: Super_String
;
186 Right
: Super_String
) return Boolean
189 return Left
.Data
(1 .. Left
.Current_Length
) >
190 Right
.Data
(1 .. Right
.Current_Length
);
194 (Left
: Super_String
;
195 Right
: String) return Boolean
198 return Left
.Data
(1 .. Left
.Current_Length
) > Right
;
203 Right
: Super_String
) return Boolean
206 return Left
> Right
.Data
(1 .. Right
.Current_Length
);
209 ----------------------
210 -- Greater_Or_Equal --
211 ----------------------
213 function Greater_Or_Equal
214 (Left
: Super_String
;
215 Right
: Super_String
) return Boolean
218 return Left
.Data
(1 .. Left
.Current_Length
) >=
219 Right
.Data
(1 .. Right
.Current_Length
);
220 end Greater_Or_Equal
;
222 function Greater_Or_Equal
223 (Left
: Super_String
;
224 Right
: String) return Boolean
227 return Left
.Data
(1 .. Left
.Current_Length
) >= Right
;
228 end Greater_Or_Equal
;
230 function Greater_Or_Equal
232 Right
: Super_String
) return Boolean
235 return Left
>= Right
.Data
(1 .. Right
.Current_Length
);
236 end Greater_Or_Equal
;
243 (Left
: Super_String
;
244 Right
: Super_String
) return Boolean
247 return Left
.Data
(1 .. Left
.Current_Length
) <
248 Right
.Data
(1 .. Right
.Current_Length
);
252 (Left
: Super_String
;
253 Right
: String) return Boolean
256 return Left
.Data
(1 .. Left
.Current_Length
) < Right
;
261 Right
: Super_String
) return Boolean
264 return Left
< Right
.Data
(1 .. Right
.Current_Length
);
271 function Less_Or_Equal
272 (Left
: Super_String
;
273 Right
: Super_String
) return Boolean
276 return Left
.Data
(1 .. Left
.Current_Length
) <=
277 Right
.Data
(1 .. Right
.Current_Length
);
280 function Less_Or_Equal
281 (Left
: Super_String
;
282 Right
: String) return Boolean
285 return Left
.Data
(1 .. Left
.Current_Length
) <= Right
;
288 function Less_Or_Equal
290 Right
: Super_String
) return Boolean
293 return Left
<= Right
.Data
(1 .. Right
.Current_Length
);
296 ----------------------
297 -- Set_Super_String --
298 ----------------------
300 procedure Set_Super_String
301 (Target
: out Super_String
;
303 Drop
: Truncation
:= Error
)
305 Slen
: constant Natural := Source
'Length;
306 Max_Length
: constant Positive := Target
.Max_Length
;
309 if Slen
<= Max_Length
then
310 Target
.Current_Length
:= Slen
;
311 Target
.Data
(1 .. Slen
) := Source
;
315 when Strings
.Right
=>
316 Target
.Current_Length
:= Max_Length
;
317 Target
.Data
(1 .. Max_Length
) :=
318 Source
(Source
'First .. Source
'First - 1 + Max_Length
);
321 Target
.Current_Length
:= Max_Length
;
322 Target
.Data
(1 .. Max_Length
) :=
323 Source
(Source
'Last - (Max_Length
- 1) .. Source
'Last);
325 when Strings
.Error
=>
326 raise Ada
.Strings
.Length_Error
;
329 end Set_Super_String
;
335 -- Case of Super_String and Super_String
337 function Super_Append
338 (Left
: Super_String
;
339 Right
: Super_String
;
340 Drop
: Truncation
:= Error
) return Super_String
342 Max_Length
: constant Positive := Left
.Max_Length
;
343 Result
: Super_String
(Max_Length
);
344 Llen
: constant Natural := Left
.Current_Length
;
345 Rlen
: constant Natural := Right
.Current_Length
;
346 Nlen
: constant Natural := Llen
+ Rlen
;
349 if Nlen
<= Max_Length
then
350 Result
.Current_Length
:= Nlen
;
351 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
352 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
.Data
(1 .. Rlen
);
355 Result
.Current_Length
:= Max_Length
;
358 when Strings
.Right
=>
359 if Llen
>= Max_Length
then -- only case is Llen = Max_Length
360 Result
.Data
:= Left
.Data
;
363 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
364 Result
.Data
(Llen
+ 1 .. Max_Length
) :=
365 Right
.Data
(1 .. Max_Length
- Llen
);
369 if Rlen
>= Max_Length
then -- only case is Rlen = Max_Length
370 Result
.Data
:= Right
.Data
;
373 Result
.Data
(1 .. Max_Length
- Rlen
) :=
374 Left
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
375 Result
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
376 Right
.Data
(1 .. Rlen
);
379 when Strings
.Error
=>
380 raise Ada
.Strings
.Length_Error
;
387 procedure Super_Append
388 (Source
: in out Super_String
;
389 New_Item
: Super_String
;
390 Drop
: Truncation
:= Error
)
392 Max_Length
: constant Positive := Source
.Max_Length
;
393 Llen
: constant Natural := Source
.Current_Length
;
394 Rlen
: constant Natural := New_Item
.Current_Length
;
395 Nlen
: constant Natural := Llen
+ Rlen
;
398 if Nlen
<= Max_Length
then
399 Source
.Current_Length
:= Nlen
;
400 Source
.Data
(Llen
+ 1 .. Nlen
) := New_Item
.Data
(1 .. Rlen
);
403 Source
.Current_Length
:= Max_Length
;
406 when Strings
.Right
=>
407 if Llen
< Max_Length
then
408 Source
.Data
(Llen
+ 1 .. Max_Length
) :=
409 New_Item
.Data
(1 .. Max_Length
- Llen
);
413 if Rlen
>= Max_Length
then -- only case is Rlen = Max_Length
414 Source
.Data
:= New_Item
.Data
;
417 Source
.Data
(1 .. Max_Length
- Rlen
) :=
418 Source
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
419 Source
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
420 New_Item
.Data
(1 .. Rlen
);
423 when Strings
.Error
=>
424 raise Ada
.Strings
.Length_Error
;
430 -- Case of Super_String and String
432 function Super_Append
433 (Left
: Super_String
;
435 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
437 Max_Length
: constant Positive := Left
.Max_Length
;
438 Result
: Super_String
(Max_Length
);
439 Llen
: constant Natural := Left
.Current_Length
;
440 Rlen
: constant Natural := Right
'Length;
441 Nlen
: constant Natural := Llen
+ Rlen
;
444 if Nlen
<= Max_Length
then
445 Result
.Current_Length
:= Nlen
;
446 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
447 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
;
450 Result
.Current_Length
:= Max_Length
;
453 when Strings
.Right
=>
454 if Llen
>= Max_Length
then -- only case is Llen = Max_Length
455 Result
.Data
:= Left
.Data
;
458 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
459 Result
.Data
(Llen
+ 1 .. Max_Length
) :=
460 Right
(Right
'First .. Right
'First - 1 +
466 if Rlen
>= Max_Length
then
467 Result
.Data
(1 .. Max_Length
) :=
468 Right
(Right
'Last - (Max_Length
- 1) .. Right
'Last);
471 Result
.Data
(1 .. Max_Length
- Rlen
) :=
472 Left
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
473 Result
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
477 when Strings
.Error
=>
478 raise Ada
.Strings
.Length_Error
;
485 procedure Super_Append
486 (Source
: in out Super_String
;
488 Drop
: Truncation
:= Error
)
490 Max_Length
: constant Positive := Source
.Max_Length
;
491 Llen
: constant Natural := Source
.Current_Length
;
492 Rlen
: constant Natural := New_Item
'Length;
493 Nlen
: constant Natural := Llen
+ Rlen
;
496 if Nlen
<= Max_Length
then
497 Source
.Current_Length
:= Nlen
;
498 Source
.Data
(Llen
+ 1 .. Nlen
) := New_Item
;
501 Source
.Current_Length
:= Max_Length
;
504 when Strings
.Right
=>
505 if Llen
< Max_Length
then
506 Source
.Data
(Llen
+ 1 .. Max_Length
) :=
507 New_Item
(New_Item
'First ..
508 New_Item
'First - 1 + Max_Length
- Llen
);
512 if Rlen
>= Max_Length
then
513 Source
.Data
(1 .. Max_Length
) :=
514 New_Item
(New_Item
'Last - (Max_Length
- 1) ..
518 Source
.Data
(1 .. Max_Length
- Rlen
) :=
519 Source
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
520 Source
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
524 when Strings
.Error
=>
525 raise Ada
.Strings
.Length_Error
;
531 -- Case of String and Super_String
533 function Super_Append
535 Right
: Super_String
;
536 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
538 Max_Length
: constant Positive := Right
.Max_Length
;
539 Result
: Super_String
(Max_Length
);
540 Llen
: constant Natural := Left
'Length;
541 Rlen
: constant Natural := Right
.Current_Length
;
542 Nlen
: constant Natural := Llen
+ Rlen
;
545 if Nlen
<= Max_Length
then
546 Result
.Current_Length
:= Nlen
;
547 Result
.Data
(1 .. Llen
) := Left
;
548 Result
.Data
(Llen
+ 1 .. Llen
+ Rlen
) := Right
.Data
(1 .. Rlen
);
551 Result
.Current_Length
:= Max_Length
;
554 when Strings
.Right
=>
555 if Llen
>= Max_Length
then
556 Result
.Data
(1 .. Max_Length
) :=
557 Left
(Left
'First .. Left
'First + (Max_Length
- 1));
560 Result
.Data
(1 .. Llen
) := Left
;
561 Result
.Data
(Llen
+ 1 .. Max_Length
) :=
562 Right
.Data
(1 .. Max_Length
- Llen
);
566 if Rlen
>= Max_Length
then
567 Result
.Data
(1 .. Max_Length
) :=
568 Right
.Data
(Rlen
- (Max_Length
- 1) .. Rlen
);
571 Result
.Data
(1 .. Max_Length
- Rlen
) :=
572 Left
(Left
'Last - (Max_Length
- Rlen
- 1) .. Left
'Last);
573 Result
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
574 Right
.Data
(1 .. Rlen
);
577 when Strings
.Error
=>
578 raise Ada
.Strings
.Length_Error
;
585 -- Case of Super_String and Character
587 function Super_Append
588 (Left
: Super_String
;
590 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
592 Max_Length
: constant Positive := Left
.Max_Length
;
593 Result
: Super_String
(Max_Length
);
594 Llen
: constant Natural := Left
.Current_Length
;
597 if Llen
< Max_Length
then
598 Result
.Current_Length
:= Llen
+ 1;
599 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
600 Result
.Data
(Llen
+ 1) := Right
;
605 when Strings
.Right
=>
609 Result
.Current_Length
:= Max_Length
;
610 Result
.Data
(1 .. Max_Length
- 1) :=
611 Left
.Data
(2 .. Max_Length
);
612 Result
.Data
(Max_Length
) := Right
;
615 when Strings
.Error
=>
616 raise Ada
.Strings
.Length_Error
;
621 procedure Super_Append
622 (Source
: in out Super_String
;
623 New_Item
: Character;
624 Drop
: Truncation
:= Error
)
626 Max_Length
: constant Positive := Source
.Max_Length
;
627 Llen
: constant Natural := Source
.Current_Length
;
630 if Llen
< Max_Length
then
631 Source
.Current_Length
:= Llen
+ 1;
632 Source
.Data
(Llen
+ 1) := New_Item
;
635 Source
.Current_Length
:= Max_Length
;
638 when Strings
.Right
=>
642 Source
.Data
(1 .. Max_Length
- 1) :=
643 Source
.Data
(2 .. Max_Length
);
644 Source
.Data
(Max_Length
) := New_Item
;
646 when Strings
.Error
=>
647 raise Ada
.Strings
.Length_Error
;
653 -- Case of Character and Super_String
655 function Super_Append
657 Right
: Super_String
;
658 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
660 Max_Length
: constant Positive := Right
.Max_Length
;
661 Result
: Super_String
(Max_Length
);
662 Rlen
: constant Natural := Right
.Current_Length
;
665 if Rlen
< Max_Length
then
666 Result
.Current_Length
:= Rlen
+ 1;
667 Result
.Data
(1) := Left
;
668 Result
.Data
(2 .. Rlen
+ 1) := Right
.Data
(1 .. Rlen
);
673 when Strings
.Right
=>
674 Result
.Current_Length
:= Max_Length
;
675 Result
.Data
(1) := Left
;
676 Result
.Data
(2 .. Max_Length
) :=
677 Right
.Data
(1 .. Max_Length
- 1);
683 when Strings
.Error
=>
684 raise Ada
.Strings
.Length_Error
;
694 (Source
: Super_String
;
696 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural
701 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Mapping
);
705 (Source
: Super_String
;
707 Mapping
: Maps
.Character_Mapping_Function
) return Natural
712 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Mapping
);
716 (Source
: Super_String
;
717 Set
: Maps
.Character_Set
) return Natural
720 return Search
.Count
(Source
.Data
(1 .. Source
.Current_Length
), Set
);
727 function Super_Delete
728 (Source
: Super_String
;
730 Through
: Natural) return Super_String
732 Result
: Super_String
(Source
.Max_Length
);
733 Slen
: constant Natural := Source
.Current_Length
;
734 Num_Delete
: constant Integer := Through
- From
+ 1;
737 if Num_Delete
<= 0 then
740 elsif From
> Slen
+ 1 then
741 raise Ada
.Strings
.Index_Error
;
743 elsif Through
>= Slen
then
744 Result
.Current_Length
:= From
- 1;
745 Result
.Data
(1 .. From
- 1) := Source
.Data
(1 .. From
- 1);
749 Result
.Current_Length
:= Slen
- Num_Delete
;
750 Result
.Data
(1 .. From
- 1) := Source
.Data
(1 .. From
- 1);
751 Result
.Data
(From
.. Result
.Current_Length
) :=
752 Source
.Data
(Through
+ 1 .. Slen
);
757 procedure Super_Delete
758 (Source
: in out Super_String
;
762 Slen
: constant Natural := Source
.Current_Length
;
763 Num_Delete
: constant Integer := Through
- From
+ 1;
766 if Num_Delete
<= 0 then
769 elsif From
> Slen
+ 1 then
770 raise Ada
.Strings
.Index_Error
;
772 elsif Through
>= Slen
then
773 Source
.Current_Length
:= From
- 1;
776 Source
.Current_Length
:= Slen
- Num_Delete
;
777 Source
.Data
(From
.. Source
.Current_Length
) :=
778 Source
.Data
(Through
+ 1 .. Slen
);
786 function Super_Element
787 (Source
: Super_String
;
788 Index
: Positive) return Character
791 if Index
<= Source
.Current_Length
then
792 return Source
.Data
(Index
);
794 raise Strings
.Index_Error
;
798 ----------------------
799 -- Super_Find_Token --
800 ----------------------
802 procedure Super_Find_Token
803 (Source
: Super_String
;
804 Set
: Maps
.Character_Set
;
806 Test
: Strings
.Membership
;
807 First
: out Positive;
812 (Source
.Data
(From
.. Source
.Current_Length
), Set
, Test
, First
, Last
);
813 end Super_Find_Token
;
815 procedure Super_Find_Token
816 (Source
: Super_String
;
817 Set
: Maps
.Character_Set
;
818 Test
: Strings
.Membership
;
819 First
: out Positive;
824 (Source
.Data
(1 .. Source
.Current_Length
), Set
, Test
, First
, Last
);
825 end Super_Find_Token
;
832 (Source
: Super_String
;
834 Pad
: Character := Space
;
835 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
837 Max_Length
: constant Positive := Source
.Max_Length
;
838 Result
: Super_String
(Max_Length
);
839 Slen
: constant Natural := Source
.Current_Length
;
840 Npad
: constant Integer := Count
- Slen
;
844 Result
.Current_Length
:= Count
;
845 Result
.Data
(1 .. Count
) := Source
.Data
(1 .. Count
);
847 elsif Count
<= Max_Length
then
848 Result
.Current_Length
:= Count
;
849 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
850 Result
.Data
(Slen
+ 1 .. Count
) := (others => Pad
);
853 Result
.Current_Length
:= Max_Length
;
856 when Strings
.Right
=>
857 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
858 Result
.Data
(Slen
+ 1 .. Max_Length
) := (others => Pad
);
861 if Npad
>= Max_Length
then
862 Result
.Data
:= (others => Pad
);
865 Result
.Data
(1 .. Max_Length
- Npad
) :=
866 Source
.Data
(Count
- Max_Length
+ 1 .. Slen
);
867 Result
.Data
(Max_Length
- Npad
+ 1 .. Max_Length
) :=
871 when Strings
.Error
=>
872 raise Ada
.Strings
.Length_Error
;
880 (Source
: in out Super_String
;
882 Pad
: Character := Space
;
883 Drop
: Truncation
:= Error
)
885 Max_Length
: constant Positive := Source
.Max_Length
;
886 Slen
: constant Natural := Source
.Current_Length
;
887 Npad
: constant Integer := Count
- Slen
;
888 Temp
: String (1 .. Max_Length
);
892 Source
.Current_Length
:= Count
;
894 elsif Count
<= Max_Length
then
895 Source
.Current_Length
:= Count
;
896 Source
.Data
(Slen
+ 1 .. Count
) := (others => Pad
);
899 Source
.Current_Length
:= Max_Length
;
902 when Strings
.Right
=>
903 Source
.Data
(Slen
+ 1 .. Max_Length
) := (others => Pad
);
906 if Npad
> Max_Length
then
907 Source
.Data
:= (others => Pad
);
911 Source
.Data
(1 .. Max_Length
- Npad
) :=
912 Temp
(Count
- Max_Length
+ 1 .. Slen
);
914 for J
in Max_Length
- Npad
+ 1 .. Max_Length
loop
915 Source
.Data
(J
) := Pad
;
919 when Strings
.Error
=>
920 raise Ada
.Strings
.Length_Error
;
930 (Source
: Super_String
;
932 Going
: Strings
.Direction
:= Strings
.Forward
;
933 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural
937 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Going
, Mapping
);
941 (Source
: Super_String
;
943 Going
: Direction
:= Forward
;
944 Mapping
: Maps
.Character_Mapping_Function
) return Natural
948 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Going
, Mapping
);
952 (Source
: Super_String
;
953 Set
: Maps
.Character_Set
;
954 Test
: Strings
.Membership
:= Strings
.Inside
;
955 Going
: Strings
.Direction
:= Strings
.Forward
) return Natural
959 (Source
.Data
(1 .. Source
.Current_Length
), Set
, Test
, Going
);
963 (Source
: Super_String
;
966 Going
: Direction
:= Forward
;
967 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural
971 (Source
.Data
(1 .. Source
.Current_Length
),
972 Pattern
, From
, Going
, Mapping
);
976 (Source
: Super_String
;
979 Going
: Direction
:= Forward
;
980 Mapping
: Maps
.Character_Mapping_Function
) return Natural
984 (Source
.Data
(1 .. Source
.Current_Length
),
985 Pattern
, From
, Going
, Mapping
);
989 (Source
: Super_String
;
990 Set
: Maps
.Character_Set
;
992 Test
: Membership
:= Inside
;
993 Going
: Direction
:= Forward
) return Natural
997 (Source
.Data
(1 .. Source
.Current_Length
), Set
, From
, Test
, Going
);
1000 ---------------------------
1001 -- Super_Index_Non_Blank --
1002 ---------------------------
1004 function Super_Index_Non_Blank
1005 (Source
: Super_String
;
1006 Going
: Strings
.Direction
:= Strings
.Forward
) return Natural
1010 Search
.Index_Non_Blank
1011 (Source
.Data
(1 .. Source
.Current_Length
), Going
);
1012 end Super_Index_Non_Blank
;
1014 function Super_Index_Non_Blank
1015 (Source
: Super_String
;
1017 Going
: Direction
:= Forward
) return Natural
1021 Search
.Index_Non_Blank
1022 (Source
.Data
(1 .. Source
.Current_Length
), From
, Going
);
1023 end Super_Index_Non_Blank
;
1029 function Super_Insert
1030 (Source
: Super_String
;
1033 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1035 Max_Length
: constant Positive := Source
.Max_Length
;
1036 Result
: Super_String
(Max_Length
);
1037 Slen
: constant Natural := Source
.Current_Length
;
1038 Nlen
: constant Natural := New_Item
'Length;
1039 Tlen
: constant Natural := Slen
+ Nlen
;
1040 Blen
: constant Natural := Before
- 1;
1041 Alen
: constant Integer := Slen
- Blen
;
1042 Droplen
: constant Integer := Tlen
- Max_Length
;
1044 -- Tlen is the length of the total string before possible truncation.
1045 -- Blen, Alen are the lengths of the before and after pieces of the
1050 raise Ada
.Strings
.Index_Error
;
1052 elsif Droplen
<= 0 then
1053 Result
.Current_Length
:= Tlen
;
1054 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1055 Result
.Data
(Before
.. Before
+ Nlen
- 1) := New_Item
;
1056 Result
.Data
(Before
+ Nlen
.. Tlen
) :=
1057 Source
.Data
(Before
.. Slen
);
1060 Result
.Current_Length
:= Max_Length
;
1063 when Strings
.Right
=>
1064 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1066 if Droplen
> Alen
then
1067 Result
.Data
(Before
.. Max_Length
) :=
1068 New_Item
(New_Item
'First
1069 .. New_Item
'First + Max_Length
- Before
);
1071 Result
.Data
(Before
.. Before
+ Nlen
- 1) := New_Item
;
1072 Result
.Data
(Before
+ Nlen
.. Max_Length
) :=
1073 Source
.Data
(Before
.. Slen
- Droplen
);
1076 when Strings
.Left
=>
1077 Result
.Data
(Max_Length
- (Alen
- 1) .. Max_Length
) :=
1078 Source
.Data
(Before
.. Slen
);
1080 if Droplen
>= Blen
then
1081 Result
.Data
(1 .. Max_Length
- Alen
) :=
1082 New_Item
(New_Item
'Last - (Max_Length
- Alen
) + 1
1086 (Blen
- Droplen
+ 1 .. Max_Length
- Alen
) :=
1088 Result
.Data
(1 .. Blen
- Droplen
) :=
1089 Source
.Data
(Droplen
+ 1 .. Blen
);
1092 when Strings
.Error
=>
1093 raise Ada
.Strings
.Length_Error
;
1100 procedure Super_Insert
1101 (Source
: in out Super_String
;
1104 Drop
: Strings
.Truncation
:= Strings
.Error
)
1107 -- We do a double copy here because this is one of the situations
1108 -- in which we move data to the right, and at least at the moment,
1109 -- GNAT is not handling such cases correctly ???
1111 Source
:= Super_Insert
(Source
, Before
, New_Item
, Drop
);
1118 function Super_Length
(Source
: Super_String
) return Natural is
1120 return Source
.Current_Length
;
1123 ---------------------
1124 -- Super_Overwrite --
1125 ---------------------
1127 function Super_Overwrite
1128 (Source
: Super_String
;
1129 Position
: Positive;
1131 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1133 Max_Length
: constant Positive := Source
.Max_Length
;
1134 Result
: Super_String
(Max_Length
);
1135 Endpos
: constant Natural := Position
+ New_Item
'Length - 1;
1136 Slen
: constant Natural := Source
.Current_Length
;
1140 if Position
> Slen
+ 1 then
1141 raise Ada
.Strings
.Index_Error
;
1143 elsif New_Item
'Length = 0 then
1146 elsif Endpos
<= Slen
then
1147 Result
.Current_Length
:= Source
.Current_Length
;
1148 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
1149 Result
.Data
(Position
.. Endpos
) := New_Item
;
1152 elsif Endpos
<= Max_Length
then
1153 Result
.Current_Length
:= Endpos
;
1154 Result
.Data
(1 .. Position
- 1) := Source
.Data
(1 .. Position
- 1);
1155 Result
.Data
(Position
.. Endpos
) := New_Item
;
1159 Result
.Current_Length
:= Max_Length
;
1160 Droplen
:= Endpos
- Max_Length
;
1163 when Strings
.Right
=>
1164 Result
.Data
(1 .. Position
- 1) :=
1165 Source
.Data
(1 .. Position
- 1);
1167 Result
.Data
(Position
.. Max_Length
) :=
1168 New_Item
(New_Item
'First .. New_Item
'Last - Droplen
);
1171 when Strings
.Left
=>
1172 if New_Item
'Length >= Max_Length
then
1173 Result
.Data
(1 .. Max_Length
) :=
1174 New_Item
(New_Item
'Last - Max_Length
+ 1 ..
1179 Result
.Data
(1 .. Max_Length
- New_Item
'Length) :=
1180 Source
.Data
(Droplen
+ 1 .. Position
- 1);
1182 (Max_Length
- New_Item
'Length + 1 .. Max_Length
) :=
1187 when Strings
.Error
=>
1188 raise Ada
.Strings
.Length_Error
;
1191 end Super_Overwrite
;
1193 procedure Super_Overwrite
1194 (Source
: in out Super_String
;
1195 Position
: Positive;
1197 Drop
: Strings
.Truncation
:= Strings
.Error
)
1199 Max_Length
: constant Positive := Source
.Max_Length
;
1200 Endpos
: constant Positive := Position
+ New_Item
'Length - 1;
1201 Slen
: constant Natural := Source
.Current_Length
;
1205 if Position
> Slen
+ 1 then
1206 raise Ada
.Strings
.Index_Error
;
1208 elsif Endpos
<= Slen
then
1209 Source
.Data
(Position
.. Endpos
) := New_Item
;
1211 elsif Endpos
<= Max_Length
then
1212 Source
.Data
(Position
.. Endpos
) := New_Item
;
1213 Source
.Current_Length
:= Endpos
;
1216 Source
.Current_Length
:= Max_Length
;
1217 Droplen
:= Endpos
- Max_Length
;
1220 when Strings
.Right
=>
1221 Source
.Data
(Position
.. Max_Length
) :=
1222 New_Item
(New_Item
'First .. New_Item
'Last - Droplen
);
1224 when Strings
.Left
=>
1225 if New_Item
'Length > Max_Length
then
1226 Source
.Data
(1 .. Max_Length
) :=
1227 New_Item
(New_Item
'Last - Max_Length
+ 1 ..
1231 Source
.Data
(1 .. Max_Length
- New_Item
'Length) :=
1232 Source
.Data
(Droplen
+ 1 .. Position
- 1);
1235 (Max_Length
- New_Item
'Length + 1 .. Max_Length
) :=
1239 when Strings
.Error
=>
1240 raise Ada
.Strings
.Length_Error
;
1243 end Super_Overwrite
;
1245 ---------------------------
1246 -- Super_Replace_Element --
1247 ---------------------------
1249 procedure Super_Replace_Element
1250 (Source
: in out Super_String
;
1255 if Index
<= Source
.Current_Length
then
1256 Source
.Data
(Index
) := By
;
1258 raise Ada
.Strings
.Index_Error
;
1260 end Super_Replace_Element
;
1262 -------------------------
1263 -- Super_Replace_Slice --
1264 -------------------------
1266 function Super_Replace_Slice
1267 (Source
: Super_String
;
1271 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1273 Max_Length
: constant Positive := Source
.Max_Length
;
1274 Slen
: constant Natural := Source
.Current_Length
;
1277 if Low
> Slen
+ 1 then
1278 raise Strings
.Index_Error
;
1280 elsif High
< Low
then
1281 return Super_Insert
(Source
, Low
, By
, Drop
);
1285 Blen
: constant Natural := Natural'Max (0, Low
- 1);
1286 Alen
: constant Natural := Natural'Max (0, Slen
- High
);
1287 Tlen
: constant Natural := Blen
+ By
'Length + Alen
;
1288 Droplen
: constant Integer := Tlen
- Max_Length
;
1289 Result
: Super_String
(Max_Length
);
1291 -- Tlen is the total length of the result string before any
1292 -- truncation. Blen and Alen are the lengths of the pieces
1293 -- of the original string that end up in the result string
1294 -- before and after the replaced slice.
1297 if Droplen
<= 0 then
1298 Result
.Current_Length
:= Tlen
;
1299 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1300 Result
.Data
(Low
.. Low
+ By
'Length - 1) := By
;
1301 Result
.Data
(Low
+ By
'Length .. Tlen
) :=
1302 Source
.Data
(High
+ 1 .. Slen
);
1305 Result
.Current_Length
:= Max_Length
;
1308 when Strings
.Right
=>
1309 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1311 if Droplen
> Alen
then
1312 Result
.Data
(Low
.. Max_Length
) :=
1313 By
(By
'First .. By
'First + Max_Length
- Low
);
1315 Result
.Data
(Low
.. Low
+ By
'Length - 1) := By
;
1316 Result
.Data
(Low
+ By
'Length .. Max_Length
) :=
1317 Source
.Data
(High
+ 1 .. Slen
- Droplen
);
1320 when Strings
.Left
=>
1321 Result
.Data
(Max_Length
- (Alen
- 1) .. Max_Length
) :=
1322 Source
.Data
(High
+ 1 .. Slen
);
1324 if Droplen
>= Blen
then
1325 Result
.Data
(1 .. Max_Length
- Alen
) :=
1326 By
(By
'Last - (Max_Length
- Alen
) + 1 .. By
'Last);
1329 (Blen
- Droplen
+ 1 .. Max_Length
- Alen
) := By
;
1330 Result
.Data
(1 .. Blen
- Droplen
) :=
1331 Source
.Data
(Droplen
+ 1 .. Blen
);
1334 when Strings
.Error
=>
1335 raise Ada
.Strings
.Length_Error
;
1342 end Super_Replace_Slice
;
1344 procedure Super_Replace_Slice
1345 (Source
: in out Super_String
;
1349 Drop
: Strings
.Truncation
:= Strings
.Error
)
1352 -- We do a double copy here because this is one of the situations
1353 -- in which we move data to the right, and at least at the moment,
1354 -- GNAT is not handling such cases correctly ???
1356 Source
:= Super_Replace_Slice
(Source
, Low
, High
, By
, Drop
);
1357 end Super_Replace_Slice
;
1359 ---------------------
1360 -- Super_Replicate --
1361 ---------------------
1363 function Super_Replicate
1366 Drop
: Truncation
:= Error
;
1367 Max_Length
: Positive) return Super_String
1369 Result
: Super_String
(Max_Length
);
1372 if Count
<= Max_Length
then
1373 Result
.Current_Length
:= Count
;
1375 elsif Drop
= Strings
.Error
then
1376 raise Ada
.Strings
.Length_Error
;
1379 Result
.Current_Length
:= Max_Length
;
1382 Result
.Data
(1 .. Result
.Current_Length
) := (others => Item
);
1384 end Super_Replicate
;
1386 function Super_Replicate
1389 Drop
: Truncation
:= Error
;
1390 Max_Length
: Positive) return Super_String
1392 Length
: constant Integer := Count
* Item
'Length;
1393 Result
: Super_String
(Max_Length
);
1397 if Length
<= Max_Length
then
1398 Result
.Current_Length
:= Length
;
1403 for J
in 1 .. Count
loop
1404 Result
.Data
(Indx
.. Indx
+ Item
'Length - 1) := Item
;
1405 Indx
:= Indx
+ Item
'Length;
1410 Result
.Current_Length
:= Max_Length
;
1413 when Strings
.Right
=>
1416 while Indx
+ Item
'Length <= Max_Length
+ 1 loop
1417 Result
.Data
(Indx
.. Indx
+ Item
'Length - 1) := Item
;
1418 Indx
:= Indx
+ Item
'Length;
1421 Result
.Data
(Indx
.. Max_Length
) :=
1422 Item
(Item
'First .. Item
'First + Max_Length
- Indx
);
1424 when Strings
.Left
=>
1427 while Indx
- Item
'Length >= 1 loop
1428 Result
.Data
(Indx
- (Item
'Length - 1) .. Indx
) := Item
;
1429 Indx
:= Indx
- Item
'Length;
1432 Result
.Data
(1 .. Indx
) :=
1433 Item
(Item
'Last - Indx
+ 1 .. Item
'Last);
1435 when Strings
.Error
=>
1436 raise Ada
.Strings
.Length_Error
;
1441 end Super_Replicate
;
1443 function Super_Replicate
1445 Item
: Super_String
;
1446 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1452 Item
.Data
(1 .. Item
.Current_Length
),
1455 end Super_Replicate
;
1461 function Super_Slice
1462 (Source
: Super_String
;
1464 High
: Natural) return String
1467 -- Note: test of High > Length is in accordance with AI95-00128
1469 return R
: String (Low
.. High
) do
1470 if Low
> Source
.Current_Length
+ 1
1471 or else High
> Source
.Current_Length
1476 -- Note: in this case, superflat bounds are not a problem, we just
1477 -- get the null string in accordance with normal Ada slice rules.
1479 R
:= Source
.Data
(Low
.. High
);
1483 function Super_Slice
1484 (Source
: Super_String
;
1486 High
: Natural) return Super_String
1489 return Result
: Super_String
(Source
.Max_Length
) do
1490 if Low
> Source
.Current_Length
+ 1
1491 or else High
> Source
.Current_Length
1496 -- Note: the Max operation here deals with the superflat case
1498 Result
.Current_Length
:= Integer'Max (0, High
- Low
+ 1);
1499 Result
.Data
(1 .. Result
.Current_Length
) := Source
.Data
(Low
.. High
);
1503 procedure Super_Slice
1504 (Source
: Super_String
;
1505 Target
: out Super_String
;
1510 if Low
> Source
.Current_Length
+ 1
1511 or else High
> Source
.Current_Length
1516 -- Note: the Max operation here deals with the superflat case
1518 Target
.Current_Length
:= Integer'Max (0, High
- Low
+ 1);
1519 Target
.Data
(1 .. Target
.Current_Length
) := Source
.Data
(Low
.. High
);
1527 (Source
: Super_String
;
1529 Pad
: Character := Space
;
1530 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1532 Max_Length
: constant Positive := Source
.Max_Length
;
1533 Result
: Super_String
(Max_Length
);
1534 Slen
: constant Natural := Source
.Current_Length
;
1535 Npad
: constant Integer := Count
- Slen
;
1539 Result
.Current_Length
:= Count
;
1540 Result
.Data
(1 .. Count
) :=
1541 Source
.Data
(Slen
- (Count
- 1) .. Slen
);
1543 elsif Count
<= Max_Length
then
1544 Result
.Current_Length
:= Count
;
1545 Result
.Data
(1 .. Npad
) := (others => Pad
);
1546 Result
.Data
(Npad
+ 1 .. Count
) := Source
.Data
(1 .. Slen
);
1549 Result
.Current_Length
:= Max_Length
;
1552 when Strings
.Right
=>
1553 if Npad
>= Max_Length
then
1554 Result
.Data
:= (others => Pad
);
1557 Result
.Data
(1 .. Npad
) := (others => Pad
);
1558 Result
.Data
(Npad
+ 1 .. Max_Length
) :=
1559 Source
.Data
(1 .. Max_Length
- Npad
);
1562 when Strings
.Left
=>
1563 Result
.Data
(1 .. Max_Length
- Slen
) := (others => Pad
);
1564 Result
.Data
(Max_Length
- Slen
+ 1 .. Max_Length
) :=
1565 Source
.Data
(1 .. Slen
);
1567 when Strings
.Error
=>
1568 raise Ada
.Strings
.Length_Error
;
1575 procedure Super_Tail
1576 (Source
: in out Super_String
;
1578 Pad
: Character := Space
;
1579 Drop
: Truncation
:= Error
)
1581 Max_Length
: constant Positive := Source
.Max_Length
;
1582 Slen
: constant Natural := Source
.Current_Length
;
1583 Npad
: constant Integer := Count
- Slen
;
1585 Temp
: constant String (1 .. Max_Length
) := Source
.Data
;
1589 Source
.Current_Length
:= Count
;
1590 Source
.Data
(1 .. Count
) :=
1591 Temp
(Slen
- (Count
- 1) .. Slen
);
1593 elsif Count
<= Max_Length
then
1594 Source
.Current_Length
:= Count
;
1595 Source
.Data
(1 .. Npad
) := (others => Pad
);
1596 Source
.Data
(Npad
+ 1 .. Count
) := Temp
(1 .. Slen
);
1599 Source
.Current_Length
:= Max_Length
;
1602 when Strings
.Right
=>
1603 if Npad
>= Max_Length
then
1604 Source
.Data
:= (others => Pad
);
1607 Source
.Data
(1 .. Npad
) := (others => Pad
);
1608 Source
.Data
(Npad
+ 1 .. Max_Length
) :=
1609 Temp
(1 .. Max_Length
- Npad
);
1612 when Strings
.Left
=>
1613 for J
in 1 .. Max_Length
- Slen
loop
1614 Source
.Data
(J
) := Pad
;
1617 Source
.Data
(Max_Length
- Slen
+ 1 .. Max_Length
) :=
1620 when Strings
.Error
=>
1621 raise Ada
.Strings
.Length_Error
;
1626 ---------------------
1627 -- Super_To_String --
1628 ---------------------
1630 function Super_To_String
(Source
: Super_String
) return String is
1632 return R
: String (1 .. Source
.Current_Length
) do
1633 R
:= Source
.Data
(1 .. Source
.Current_Length
);
1635 end Super_To_String
;
1637 ---------------------
1638 -- Super_Translate --
1639 ---------------------
1641 function Super_Translate
1642 (Source
: Super_String
;
1643 Mapping
: Maps
.Character_Mapping
) return Super_String
1645 Result
: Super_String
(Source
.Max_Length
);
1648 Result
.Current_Length
:= Source
.Current_Length
;
1650 for J
in 1 .. Source
.Current_Length
loop
1651 Result
.Data
(J
) := Value
(Mapping
, Source
.Data
(J
));
1655 end Super_Translate
;
1657 procedure Super_Translate
1658 (Source
: in out Super_String
;
1659 Mapping
: Maps
.Character_Mapping
)
1662 for J
in 1 .. Source
.Current_Length
loop
1663 Source
.Data
(J
) := Value
(Mapping
, Source
.Data
(J
));
1665 end Super_Translate
;
1667 function Super_Translate
1668 (Source
: Super_String
;
1669 Mapping
: Maps
.Character_Mapping_Function
) return Super_String
1671 Result
: Super_String
(Source
.Max_Length
);
1674 Result
.Current_Length
:= Source
.Current_Length
;
1676 for J
in 1 .. Source
.Current_Length
loop
1677 Result
.Data
(J
) := Mapping
.all (Source
.Data
(J
));
1681 end Super_Translate
;
1683 procedure Super_Translate
1684 (Source
: in out Super_String
;
1685 Mapping
: Maps
.Character_Mapping_Function
)
1688 for J
in 1 .. Source
.Current_Length
loop
1689 Source
.Data
(J
) := Mapping
.all (Source
.Data
(J
));
1691 end Super_Translate
;
1698 (Source
: Super_String
;
1699 Side
: Trim_End
) return Super_String
1701 Result
: Super_String
(Source
.Max_Length
);
1702 Last
: Natural := Source
.Current_Length
;
1703 First
: Positive := 1;
1706 if Side
= Left
or else Side
= Both
then
1707 while First
<= Last
and then Source
.Data
(First
) = ' ' loop
1712 if Side
= Right
or else Side
= Both
then
1713 while Last
>= First
and then Source
.Data
(Last
) = ' ' loop
1718 Result
.Current_Length
:= Last
- First
+ 1;
1719 Result
.Data
(1 .. Result
.Current_Length
) := Source
.Data
(First
.. Last
);
1723 procedure Super_Trim
1724 (Source
: in out Super_String
;
1727 Max_Length
: constant Positive := Source
.Max_Length
;
1728 Last
: Natural := Source
.Current_Length
;
1729 First
: Positive := 1;
1730 Temp
: String (1 .. Max_Length
);
1733 Temp
(1 .. Last
) := Source
.Data
(1 .. Last
);
1735 if Side
= Left
or else Side
= Both
then
1736 while First
<= Last
and then Temp
(First
) = ' ' loop
1741 if Side
= Right
or else Side
= Both
then
1742 while Last
>= First
and then Temp
(Last
) = ' ' loop
1747 Source
.Data
:= (others => ASCII
.NUL
);
1748 Source
.Current_Length
:= Last
- First
+ 1;
1749 Source
.Data
(1 .. Source
.Current_Length
) := Temp
(First
.. Last
);
1753 (Source
: Super_String
;
1754 Left
: Maps
.Character_Set
;
1755 Right
: Maps
.Character_Set
) return Super_String
1757 Result
: Super_String
(Source
.Max_Length
);
1760 for First
in 1 .. Source
.Current_Length
loop
1761 if not Is_In
(Source
.Data
(First
), Left
) then
1762 for Last
in reverse First
.. Source
.Current_Length
loop
1763 if not Is_In
(Source
.Data
(Last
), Right
) then
1764 Result
.Current_Length
:= Last
- First
+ 1;
1765 Result
.Data
(1 .. Result
.Current_Length
) :=
1766 Source
.Data
(First
.. Last
);
1773 Result
.Current_Length
:= 0;
1777 procedure Super_Trim
1778 (Source
: in out Super_String
;
1779 Left
: Maps
.Character_Set
;
1780 Right
: Maps
.Character_Set
)
1783 for First
in 1 .. Source
.Current_Length
loop
1784 if not Is_In
(Source
.Data
(First
), Left
) then
1785 for Last
in reverse First
.. Source
.Current_Length
loop
1786 if not Is_In
(Source
.Data
(Last
), Right
) then
1788 Source
.Current_Length
:= Last
;
1791 Source
.Current_Length
:= Last
- First
+ 1;
1792 Source
.Data
(1 .. Source
.Current_Length
) :=
1793 Source
.Data
(First
.. Last
);
1795 for J
in Source
.Current_Length
+ 1 ..
1798 Source
.Data
(J
) := ASCII
.NUL
;
1806 Source
.Current_Length
:= 0;
1811 Source
.Current_Length
:= 0;
1821 Max_Length
: Positive) return Super_String
1823 Result
: Super_String
(Max_Length
);
1826 if Left
> Max_Length
then
1827 raise Ada
.Strings
.Length_Error
;
1830 Result
.Current_Length
:= Left
;
1832 for J
in 1 .. Left
loop
1833 Result
.Data
(J
) := Right
;
1843 Max_Length
: Positive) return Super_String
1845 Result
: Super_String
(Max_Length
);
1846 Pos
: Positive := 1;
1847 Rlen
: constant Natural := Right
'Length;
1848 Nlen
: constant Natural := Left
* Rlen
;
1851 if Nlen
> Max_Length
then
1852 raise Ada
.Strings
.Length_Error
;
1855 Result
.Current_Length
:= Nlen
;
1858 for J
in 1 .. Left
loop
1859 Result
.Data
(Pos
.. Pos
+ Rlen
- 1) := Right
;
1870 Right
: Super_String
) return Super_String
1872 Result
: Super_String
(Right
.Max_Length
);
1873 Pos
: Positive := 1;
1874 Rlen
: constant Natural := Right
.Current_Length
;
1875 Nlen
: constant Natural := Left
* Rlen
;
1878 if Nlen
> Right
.Max_Length
then
1879 raise Ada
.Strings
.Length_Error
;
1882 Result
.Current_Length
:= Nlen
;
1885 for J
in 1 .. Left
loop
1886 Result
.Data
(Pos
.. Pos
+ Rlen
- 1) :=
1887 Right
.Data
(1 .. Rlen
);
1896 ---------------------
1897 -- To_Super_String --
1898 ---------------------
1900 function To_Super_String
1902 Max_Length
: Natural;
1903 Drop
: Truncation
:= Error
) return Super_String
1905 Result
: Super_String
(Max_Length
);
1906 Slen
: constant Natural := Source
'Length;
1909 if Slen
<= Max_Length
then
1910 Result
.Current_Length
:= Slen
;
1911 Result
.Data
(1 .. Slen
) := Source
;
1915 when Strings
.Right
=>
1916 Result
.Current_Length
:= Max_Length
;
1917 Result
.Data
(1 .. Max_Length
) :=
1918 Source
(Source
'First .. Source
'First - 1 + Max_Length
);
1920 when Strings
.Left
=>
1921 Result
.Current_Length
:= Max_Length
;
1922 Result
.Data
(1 .. Max_Length
) :=
1923 Source
(Source
'Last - (Max_Length
- 1) .. Source
'Last);
1925 when Strings
.Error
=>
1926 raise Ada
.Strings
.Length_Error
;
1931 end To_Super_String
;
1933 end Ada
.Strings
.Superbounded
;