1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . S T R I N G S . W I D E _ S U P E R B O U N D E D --
9 -- Copyright (C) 2003-2012, 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
.Wide_Maps
; use Ada
.Strings
.Wide_Maps
;
33 with Ada
.Strings
.Wide_Search
;
35 package body Ada
.Strings
.Wide_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
;
53 if Nlen
> Left
.Max_Length
then
54 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
);
66 Right
: Wide_String) return Super_String
69 return Result
: Super_String
(Left
.Max_Length
) do
71 Llen
: constant Natural := Left
.Current_Length
;
72 Nlen
: constant Natural := Llen
+ Right
'Length;
75 if Nlen
> Left
.Max_Length
then
76 raise Ada
.Strings
.Length_Error
;
78 Result
.Current_Length
:= Nlen
;
79 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
80 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
;
88 Right
: Super_String
) return Super_String
91 return Result
: Super_String
(Right
.Max_Length
) do
93 Llen
: constant Natural := Left
'Length;
94 Rlen
: constant Natural := Right
.Current_Length
;
95 Nlen
: constant Natural := Llen
+ Rlen
;
98 if Nlen
> Right
.Max_Length
then
99 raise Ada
.Strings
.Length_Error
;
101 Result
.Current_Length
:= Nlen
;
102 Result
.Data
(1 .. Llen
) := Left
;
103 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
.Data
(1 .. Rlen
);
110 (Left
: Super_String
;
111 Right
: Wide_Character) return Super_String
114 return Result
: Super_String
(Left
.Max_Length
) do
116 Llen
: constant Natural := Left
.Current_Length
;
119 if Llen
= Left
.Max_Length
then
120 raise Ada
.Strings
.Length_Error
;
122 Result
.Current_Length
:= Llen
+ 1;
123 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
124 Result
.Data
(Result
.Current_Length
) := Right
;
131 (Left
: Wide_Character;
132 Right
: Super_String
) return Super_String
135 return Result
: Super_String
(Right
.Max_Length
) do
137 Rlen
: constant Natural := Right
.Current_Length
;
140 if Rlen
= Right
.Max_Length
then
141 raise Ada
.Strings
.Length_Error
;
143 Result
.Current_Length
:= Rlen
+ 1;
144 Result
.Data
(1) := Left
;
145 Result
.Data
(2 .. Result
.Current_Length
) :=
146 Right
.Data
(1 .. Rlen
);
157 (Left
: Super_String
;
158 Right
: Super_String
) return Boolean
161 return Left
.Current_Length
= Right
.Current_Length
162 and then Left
.Data
(1 .. Left
.Current_Length
) =
163 Right
.Data
(1 .. Right
.Current_Length
);
167 (Left
: Super_String
;
168 Right
: Wide_String) return Boolean
171 return Left
.Current_Length
= Right
'Length
172 and then Left
.Data
(1 .. Left
.Current_Length
) = Right
;
177 Right
: Super_String
) return Boolean
180 return Left
'Length = Right
.Current_Length
181 and then Left
= Right
.Data
(1 .. Right
.Current_Length
);
189 (Left
: Super_String
;
190 Right
: Super_String
) return Boolean
193 return Left
.Data
(1 .. Left
.Current_Length
) >
194 Right
.Data
(1 .. Right
.Current_Length
);
198 (Left
: Super_String
;
199 Right
: Wide_String) return Boolean
202 return Left
.Data
(1 .. Left
.Current_Length
) > Right
;
207 Right
: Super_String
) return Boolean
210 return Left
> Right
.Data
(1 .. Right
.Current_Length
);
213 ----------------------
214 -- Greater_Or_Equal --
215 ----------------------
217 function Greater_Or_Equal
218 (Left
: Super_String
;
219 Right
: Super_String
) return Boolean
222 return Left
.Data
(1 .. Left
.Current_Length
) >=
223 Right
.Data
(1 .. Right
.Current_Length
);
224 end Greater_Or_Equal
;
226 function Greater_Or_Equal
227 (Left
: Super_String
;
228 Right
: Wide_String) return Boolean
231 return Left
.Data
(1 .. Left
.Current_Length
) >= Right
;
232 end Greater_Or_Equal
;
234 function Greater_Or_Equal
236 Right
: Super_String
) return Boolean
239 return Left
>= Right
.Data
(1 .. Right
.Current_Length
);
240 end Greater_Or_Equal
;
247 (Left
: Super_String
;
248 Right
: Super_String
) return Boolean
251 return Left
.Data
(1 .. Left
.Current_Length
) <
252 Right
.Data
(1 .. Right
.Current_Length
);
256 (Left
: Super_String
;
257 Right
: Wide_String) return Boolean
260 return Left
.Data
(1 .. Left
.Current_Length
) < Right
;
265 Right
: Super_String
) return Boolean
268 return Left
< Right
.Data
(1 .. Right
.Current_Length
);
275 function Less_Or_Equal
276 (Left
: Super_String
;
277 Right
: Super_String
) return Boolean
280 return Left
.Data
(1 .. Left
.Current_Length
) <=
281 Right
.Data
(1 .. Right
.Current_Length
);
284 function Less_Or_Equal
285 (Left
: Super_String
;
286 Right
: Wide_String) return Boolean
289 return Left
.Data
(1 .. Left
.Current_Length
) <= Right
;
292 function Less_Or_Equal
294 Right
: Super_String
) return Boolean
297 return Left
<= Right
.Data
(1 .. Right
.Current_Length
);
300 ----------------------
301 -- Set_Super_String --
302 ----------------------
304 procedure Set_Super_String
305 (Target
: out Super_String
;
306 Source
: Wide_String;
307 Drop
: Truncation
:= Error
)
309 Slen
: constant Natural := Source
'Length;
310 Max_Length
: constant Positive := Target
.Max_Length
;
313 if Slen
<= Max_Length
then
314 Target
.Current_Length
:= Slen
;
315 Target
.Data
(1 .. Slen
) := Source
;
319 when Strings
.Right
=>
320 Target
.Current_Length
:= Max_Length
;
321 Target
.Data
(1 .. Max_Length
) :=
322 Source
(Source
'First .. Source
'First - 1 + Max_Length
);
325 Target
.Current_Length
:= Max_Length
;
326 Target
.Data
(1 .. Max_Length
) :=
327 Source
(Source
'Last - (Max_Length
- 1) .. Source
'Last);
329 when Strings
.Error
=>
330 raise Ada
.Strings
.Length_Error
;
333 end Set_Super_String
;
339 -- Case of Super_String and Super_String
341 function Super_Append
342 (Left
: Super_String
;
343 Right
: Super_String
;
344 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
346 Max_Length
: constant Positive := Left
.Max_Length
;
347 Result
: Super_String
(Max_Length
);
348 Llen
: constant Natural := Left
.Current_Length
;
349 Rlen
: constant Natural := Right
.Current_Length
;
350 Nlen
: constant Natural := Llen
+ Rlen
;
353 if Nlen
<= Max_Length
then
354 Result
.Current_Length
:= Nlen
;
355 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
356 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
.Data
(1 .. Rlen
);
359 Result
.Current_Length
:= Max_Length
;
362 when Strings
.Right
=>
363 if Llen
>= Max_Length
then -- only case is Llen = Max_Length
364 Result
.Data
:= Left
.Data
;
367 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
368 Result
.Data
(Llen
+ 1 .. Max_Length
) :=
369 Right
.Data
(1 .. Max_Length
- Llen
);
373 if Rlen
>= Max_Length
then -- only case is Rlen = Max_Length
374 Result
.Data
:= Right
.Data
;
377 Result
.Data
(1 .. Max_Length
- Rlen
) :=
378 Left
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
379 Result
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
380 Right
.Data
(1 .. Rlen
);
383 when Strings
.Error
=>
384 raise Ada
.Strings
.Length_Error
;
391 procedure Super_Append
392 (Source
: in out Super_String
;
393 New_Item
: Super_String
;
394 Drop
: Truncation
:= Error
)
396 Max_Length
: constant Positive := Source
.Max_Length
;
397 Llen
: constant Natural := Source
.Current_Length
;
398 Rlen
: constant Natural := New_Item
.Current_Length
;
399 Nlen
: constant Natural := Llen
+ Rlen
;
402 if Nlen
<= Max_Length
then
403 Source
.Current_Length
:= Nlen
;
404 Source
.Data
(Llen
+ 1 .. Nlen
) := New_Item
.Data
(1 .. Rlen
);
407 Source
.Current_Length
:= Max_Length
;
410 when Strings
.Right
=>
411 if Llen
< Max_Length
then
412 Source
.Data
(Llen
+ 1 .. Max_Length
) :=
413 New_Item
.Data
(1 .. Max_Length
- Llen
);
417 if Rlen
>= Max_Length
then -- only case is Rlen = Max_Length
418 Source
.Data
:= New_Item
.Data
;
421 Source
.Data
(1 .. Max_Length
- Rlen
) :=
422 Source
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
423 Source
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
424 New_Item
.Data
(1 .. Rlen
);
427 when Strings
.Error
=>
428 raise Ada
.Strings
.Length_Error
;
434 -- Case of Super_String and Wide_String
436 function Super_Append
437 (Left
: Super_String
;
439 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
441 Max_Length
: constant Positive := Left
.Max_Length
;
442 Result
: Super_String
(Max_Length
);
443 Llen
: constant Natural := Left
.Current_Length
;
444 Rlen
: constant Natural := Right
'Length;
445 Nlen
: constant Natural := Llen
+ Rlen
;
448 if Nlen
<= Max_Length
then
449 Result
.Current_Length
:= Nlen
;
450 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
451 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
;
454 Result
.Current_Length
:= Max_Length
;
457 when Strings
.Right
=>
458 if Llen
>= Max_Length
then -- only case is Llen = Max_Length
459 Result
.Data
:= Left
.Data
;
462 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
463 Result
.Data
(Llen
+ 1 .. Max_Length
) :=
464 Right
(Right
'First .. Right
'First - 1 +
470 if Rlen
>= Max_Length
then
471 Result
.Data
(1 .. Max_Length
) :=
472 Right
(Right
'Last - (Max_Length
- 1) .. Right
'Last);
475 Result
.Data
(1 .. Max_Length
- Rlen
) :=
476 Left
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
477 Result
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
481 when Strings
.Error
=>
482 raise Ada
.Strings
.Length_Error
;
489 procedure Super_Append
490 (Source
: in out Super_String
;
491 New_Item
: Wide_String;
492 Drop
: Truncation
:= Error
)
494 Max_Length
: constant Positive := Source
.Max_Length
;
495 Llen
: constant Natural := Source
.Current_Length
;
496 Rlen
: constant Natural := New_Item
'Length;
497 Nlen
: constant Natural := Llen
+ Rlen
;
500 if Nlen
<= Max_Length
then
501 Source
.Current_Length
:= Nlen
;
502 Source
.Data
(Llen
+ 1 .. Nlen
) := New_Item
;
505 Source
.Current_Length
:= Max_Length
;
508 when Strings
.Right
=>
509 if Llen
< Max_Length
then
510 Source
.Data
(Llen
+ 1 .. Max_Length
) :=
511 New_Item
(New_Item
'First ..
512 New_Item
'First - 1 + Max_Length
- Llen
);
516 if Rlen
>= Max_Length
then
517 Source
.Data
(1 .. Max_Length
) :=
518 New_Item
(New_Item
'Last - (Max_Length
- 1) ..
522 Source
.Data
(1 .. Max_Length
- Rlen
) :=
523 Source
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
524 Source
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
528 when Strings
.Error
=>
529 raise Ada
.Strings
.Length_Error
;
535 -- Case of Wide_String and Super_String
537 function Super_Append
539 Right
: Super_String
;
540 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
542 Max_Length
: constant Positive := Right
.Max_Length
;
543 Result
: Super_String
(Max_Length
);
544 Llen
: constant Natural := Left
'Length;
545 Rlen
: constant Natural := Right
.Current_Length
;
546 Nlen
: constant Natural := Llen
+ Rlen
;
549 if Nlen
<= Max_Length
then
550 Result
.Current_Length
:= Nlen
;
551 Result
.Data
(1 .. Llen
) := Left
;
552 Result
.Data
(Llen
+ 1 .. Llen
+ Rlen
) := Right
.Data
(1 .. Rlen
);
555 Result
.Current_Length
:= Max_Length
;
558 when Strings
.Right
=>
559 if Llen
>= Max_Length
then
560 Result
.Data
(1 .. Max_Length
) :=
561 Left
(Left
'First .. Left
'First + (Max_Length
- 1));
564 Result
.Data
(1 .. Llen
) := Left
;
565 Result
.Data
(Llen
+ 1 .. Max_Length
) :=
566 Right
.Data
(1 .. Max_Length
- Llen
);
570 if Rlen
>= Max_Length
then
571 Result
.Data
(1 .. Max_Length
) :=
572 Right
.Data
(Rlen
- (Max_Length
- 1) .. Rlen
);
575 Result
.Data
(1 .. Max_Length
- Rlen
) :=
576 Left
(Left
'Last - (Max_Length
- Rlen
- 1) .. Left
'Last);
577 Result
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
578 Right
.Data
(1 .. Rlen
);
581 when Strings
.Error
=>
582 raise Ada
.Strings
.Length_Error
;
589 -- Case of Super_String and Wide_Character
591 function Super_Append
592 (Left
: Super_String
;
593 Right
: Wide_Character;
594 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
596 Max_Length
: constant Positive := Left
.Max_Length
;
597 Result
: Super_String
(Max_Length
);
598 Llen
: constant Natural := Left
.Current_Length
;
601 if Llen
< Max_Length
then
602 Result
.Current_Length
:= Llen
+ 1;
603 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
604 Result
.Data
(Llen
+ 1) := Right
;
609 when Strings
.Right
=>
613 Result
.Current_Length
:= Max_Length
;
614 Result
.Data
(1 .. Max_Length
- 1) :=
615 Left
.Data
(2 .. Max_Length
);
616 Result
.Data
(Max_Length
) := Right
;
619 when Strings
.Error
=>
620 raise Ada
.Strings
.Length_Error
;
625 procedure Super_Append
626 (Source
: in out Super_String
;
627 New_Item
: Wide_Character;
628 Drop
: Truncation
:= Error
)
630 Max_Length
: constant Positive := Source
.Max_Length
;
631 Llen
: constant Natural := Source
.Current_Length
;
634 if Llen
< Max_Length
then
635 Source
.Current_Length
:= Llen
+ 1;
636 Source
.Data
(Llen
+ 1) := New_Item
;
639 Source
.Current_Length
:= Max_Length
;
642 when Strings
.Right
=>
646 Source
.Data
(1 .. Max_Length
- 1) :=
647 Source
.Data
(2 .. Max_Length
);
648 Source
.Data
(Max_Length
) := New_Item
;
650 when Strings
.Error
=>
651 raise Ada
.Strings
.Length_Error
;
657 -- Case of Wide_Character and Super_String
659 function Super_Append
660 (Left
: Wide_Character;
661 Right
: Super_String
;
662 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
664 Max_Length
: constant Positive := Right
.Max_Length
;
665 Result
: Super_String
(Max_Length
);
666 Rlen
: constant Natural := Right
.Current_Length
;
669 if Rlen
< Max_Length
then
670 Result
.Current_Length
:= Rlen
+ 1;
671 Result
.Data
(1) := Left
;
672 Result
.Data
(2 .. Rlen
+ 1) := Right
.Data
(1 .. Rlen
);
677 when Strings
.Right
=>
678 Result
.Current_Length
:= Max_Length
;
679 Result
.Data
(1) := Left
;
680 Result
.Data
(2 .. Max_Length
) :=
681 Right
.Data
(1 .. Max_Length
- 1);
687 when Strings
.Error
=>
688 raise Ada
.Strings
.Length_Error
;
698 (Source
: Super_String
;
699 Pattern
: Wide_String;
700 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
706 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Mapping
);
710 (Source
: Super_String
;
711 Pattern
: Wide_String;
712 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
717 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Mapping
);
721 (Source
: Super_String
;
722 Set
: Wide_Maps
.Wide_Character_Set
) return Natural
725 return Wide_Search
.Count
(Source
.Data
(1 .. Source
.Current_Length
), Set
);
732 function Super_Delete
733 (Source
: Super_String
;
735 Through
: Natural) return Super_String
737 Result
: Super_String
(Source
.Max_Length
);
738 Slen
: constant Natural := Source
.Current_Length
;
739 Num_Delete
: constant Integer := Through
- From
+ 1;
742 if Num_Delete
<= 0 then
745 elsif From
> Slen
+ 1 then
746 raise Ada
.Strings
.Index_Error
;
748 elsif Through
>= Slen
then
749 Result
.Current_Length
:= From
- 1;
750 Result
.Data
(1 .. From
- 1) := Source
.Data
(1 .. From
- 1);
754 Result
.Current_Length
:= Slen
- Num_Delete
;
755 Result
.Data
(1 .. From
- 1) := Source
.Data
(1 .. From
- 1);
756 Result
.Data
(From
.. Result
.Current_Length
) :=
757 Source
.Data
(Through
+ 1 .. Slen
);
762 procedure Super_Delete
763 (Source
: in out Super_String
;
767 Slen
: constant Natural := Source
.Current_Length
;
768 Num_Delete
: constant Integer := Through
- From
+ 1;
771 if Num_Delete
<= 0 then
774 elsif From
> Slen
+ 1 then
775 raise Ada
.Strings
.Index_Error
;
777 elsif Through
>= Slen
then
778 Source
.Current_Length
:= From
- 1;
781 Source
.Current_Length
:= Slen
- Num_Delete
;
782 Source
.Data
(From
.. Source
.Current_Length
) :=
783 Source
.Data
(Through
+ 1 .. Slen
);
791 function Super_Element
792 (Source
: Super_String
;
793 Index
: Positive) return Wide_Character
796 if Index
<= Source
.Current_Length
then
797 return Source
.Data
(Index
);
799 raise Strings
.Index_Error
;
803 ----------------------
804 -- Super_Find_Token --
805 ----------------------
807 procedure Super_Find_Token
808 (Source
: Super_String
;
809 Set
: Wide_Maps
.Wide_Character_Set
;
811 Test
: Strings
.Membership
;
812 First
: out Positive;
816 Wide_Search
.Find_Token
817 (Source
.Data
(From
.. Source
.Current_Length
), Set
, Test
, First
, Last
);
818 end Super_Find_Token
;
820 procedure Super_Find_Token
821 (Source
: Super_String
;
822 Set
: Wide_Maps
.Wide_Character_Set
;
823 Test
: Strings
.Membership
;
824 First
: out Positive;
828 Wide_Search
.Find_Token
829 (Source
.Data
(1 .. Source
.Current_Length
), Set
, Test
, First
, Last
);
830 end Super_Find_Token
;
837 (Source
: Super_String
;
839 Pad
: Wide_Character := Wide_Space
;
840 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
842 Max_Length
: constant Positive := Source
.Max_Length
;
843 Result
: Super_String
(Max_Length
);
844 Slen
: constant Natural := Source
.Current_Length
;
845 Npad
: constant Integer := Count
- Slen
;
849 Result
.Current_Length
:= Count
;
850 Result
.Data
(1 .. Count
) := Source
.Data
(1 .. Count
);
852 elsif Count
<= Max_Length
then
853 Result
.Current_Length
:= Count
;
854 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
855 Result
.Data
(Slen
+ 1 .. Count
) := (others => Pad
);
858 Result
.Current_Length
:= Max_Length
;
861 when Strings
.Right
=>
862 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
863 Result
.Data
(Slen
+ 1 .. Max_Length
) := (others => Pad
);
866 if Npad
>= Max_Length
then
867 Result
.Data
:= (others => Pad
);
870 Result
.Data
(1 .. Max_Length
- Npad
) :=
871 Source
.Data
(Count
- Max_Length
+ 1 .. Slen
);
872 Result
.Data
(Max_Length
- Npad
+ 1 .. Max_Length
) :=
876 when Strings
.Error
=>
877 raise Ada
.Strings
.Length_Error
;
885 (Source
: in out Super_String
;
887 Pad
: Wide_Character := Wide_Space
;
888 Drop
: Truncation
:= Error
)
890 Max_Length
: constant Positive := Source
.Max_Length
;
891 Slen
: constant Natural := Source
.Current_Length
;
892 Npad
: constant Integer := Count
- Slen
;
893 Temp
: Wide_String (1 .. Max_Length
);
897 Source
.Current_Length
:= Count
;
899 elsif Count
<= Max_Length
then
900 Source
.Current_Length
:= Count
;
901 Source
.Data
(Slen
+ 1 .. Count
) := (others => Pad
);
904 Source
.Current_Length
:= Max_Length
;
907 when Strings
.Right
=>
908 Source
.Data
(Slen
+ 1 .. Max_Length
) := (others => Pad
);
911 if Npad
> Max_Length
then
912 Source
.Data
:= (others => Pad
);
916 Source
.Data
(1 .. Max_Length
- Npad
) :=
917 Temp
(Count
- Max_Length
+ 1 .. Slen
);
919 for J
in Max_Length
- Npad
+ 1 .. Max_Length
loop
920 Source
.Data
(J
) := Pad
;
924 when Strings
.Error
=>
925 raise Ada
.Strings
.Length_Error
;
935 (Source
: Super_String
;
936 Pattern
: Wide_String;
937 Going
: Strings
.Direction
:= Strings
.Forward
;
938 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
942 return Wide_Search
.Index
943 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Going
, Mapping
);
947 (Source
: Super_String
;
948 Pattern
: Wide_String;
949 Going
: Direction
:= Forward
;
950 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
953 return Wide_Search
.Index
954 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Going
, Mapping
);
958 (Source
: Super_String
;
959 Set
: Wide_Maps
.Wide_Character_Set
;
960 Test
: Strings
.Membership
:= Strings
.Inside
;
961 Going
: Strings
.Direction
:= Strings
.Forward
) return Natural
964 return Wide_Search
.Index
965 (Source
.Data
(1 .. Source
.Current_Length
), Set
, Test
, Going
);
969 (Source
: Super_String
;
970 Pattern
: Wide_String;
972 Going
: Direction
:= Forward
;
973 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
977 return Wide_Search
.Index
978 (Source
.Data
(1 .. Source
.Current_Length
),
979 Pattern
, From
, Going
, Mapping
);
983 (Source
: Super_String
;
984 Pattern
: Wide_String;
986 Going
: Direction
:= Forward
;
987 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural
990 return Wide_Search
.Index
991 (Source
.Data
(1 .. Source
.Current_Length
),
992 Pattern
, From
, Going
, Mapping
);
996 (Source
: Super_String
;
997 Set
: Wide_Maps
.Wide_Character_Set
;
999 Test
: Membership
:= Inside
;
1000 Going
: Direction
:= Forward
) return Natural
1003 return Wide_Search
.Index
1004 (Source
.Data
(1 .. Source
.Current_Length
), Set
, From
, Test
, Going
);
1007 ---------------------------
1008 -- Super_Index_Non_Blank --
1009 ---------------------------
1011 function Super_Index_Non_Blank
1012 (Source
: Super_String
;
1013 Going
: Strings
.Direction
:= Strings
.Forward
) return Natural
1017 Wide_Search
.Index_Non_Blank
1018 (Source
.Data
(1 .. Source
.Current_Length
), Going
);
1019 end Super_Index_Non_Blank
;
1021 function Super_Index_Non_Blank
1022 (Source
: Super_String
;
1024 Going
: Direction
:= Forward
) return Natural
1028 Wide_Search
.Index_Non_Blank
1029 (Source
.Data
(1 .. Source
.Current_Length
), From
, Going
);
1030 end Super_Index_Non_Blank
;
1036 function Super_Insert
1037 (Source
: Super_String
;
1039 New_Item
: Wide_String;
1040 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1042 Max_Length
: constant Positive := Source
.Max_Length
;
1043 Result
: Super_String
(Max_Length
);
1044 Slen
: constant Natural := Source
.Current_Length
;
1045 Nlen
: constant Natural := New_Item
'Length;
1046 Tlen
: constant Natural := Slen
+ Nlen
;
1047 Blen
: constant Natural := Before
- 1;
1048 Alen
: constant Integer := Slen
- Blen
;
1049 Droplen
: constant Integer := Tlen
- Max_Length
;
1051 -- Tlen is the length of the total string before possible truncation.
1052 -- Blen, Alen are the lengths of the before and after pieces of the
1057 raise Ada
.Strings
.Index_Error
;
1059 elsif Droplen
<= 0 then
1060 Result
.Current_Length
:= Tlen
;
1061 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1062 Result
.Data
(Before
.. Before
+ Nlen
- 1) := New_Item
;
1063 Result
.Data
(Before
+ Nlen
.. Tlen
) :=
1064 Source
.Data
(Before
.. Slen
);
1067 Result
.Current_Length
:= Max_Length
;
1070 when Strings
.Right
=>
1071 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1073 if Droplen
> Alen
then
1074 Result
.Data
(Before
.. Max_Length
) :=
1075 New_Item
(New_Item
'First
1076 .. New_Item
'First + Max_Length
- Before
);
1078 Result
.Data
(Before
.. Before
+ Nlen
- 1) := New_Item
;
1079 Result
.Data
(Before
+ Nlen
.. Max_Length
) :=
1080 Source
.Data
(Before
.. Slen
- Droplen
);
1083 when Strings
.Left
=>
1084 Result
.Data
(Max_Length
- (Alen
- 1) .. Max_Length
) :=
1085 Source
.Data
(Before
.. Slen
);
1087 if Droplen
>= Blen
then
1088 Result
.Data
(1 .. Max_Length
- Alen
) :=
1089 New_Item
(New_Item
'Last - (Max_Length
- Alen
) + 1
1093 (Blen
- Droplen
+ 1 .. Max_Length
- Alen
) :=
1095 Result
.Data
(1 .. Blen
- Droplen
) :=
1096 Source
.Data
(Droplen
+ 1 .. Blen
);
1099 when Strings
.Error
=>
1100 raise Ada
.Strings
.Length_Error
;
1107 procedure Super_Insert
1108 (Source
: in out Super_String
;
1110 New_Item
: Wide_String;
1111 Drop
: Strings
.Truncation
:= Strings
.Error
)
1114 -- We do a double copy here because this is one of the situations
1115 -- in which we move data to the right, and at least at the moment,
1116 -- GNAT is not handling such cases correctly ???
1118 Source
:= Super_Insert
(Source
, Before
, New_Item
, Drop
);
1125 function Super_Length
(Source
: Super_String
) return Natural is
1127 return Source
.Current_Length
;
1130 ---------------------
1131 -- Super_Overwrite --
1132 ---------------------
1134 function Super_Overwrite
1135 (Source
: Super_String
;
1136 Position
: Positive;
1137 New_Item
: Wide_String;
1138 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1140 Max_Length
: constant Positive := Source
.Max_Length
;
1141 Result
: Super_String
(Max_Length
);
1142 Endpos
: constant Natural := Position
+ New_Item
'Length - 1;
1143 Slen
: constant Natural := Source
.Current_Length
;
1147 if Position
> Slen
+ 1 then
1148 raise Ada
.Strings
.Index_Error
;
1150 elsif New_Item
'Length = 0 then
1153 elsif Endpos
<= Slen
then
1154 Result
.Current_Length
:= Source
.Current_Length
;
1155 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
1156 Result
.Data
(Position
.. Endpos
) := New_Item
;
1159 elsif Endpos
<= Max_Length
then
1160 Result
.Current_Length
:= Endpos
;
1161 Result
.Data
(1 .. Position
- 1) := Source
.Data
(1 .. Position
- 1);
1162 Result
.Data
(Position
.. Endpos
) := New_Item
;
1166 Result
.Current_Length
:= Max_Length
;
1167 Droplen
:= Endpos
- Max_Length
;
1170 when Strings
.Right
=>
1171 Result
.Data
(1 .. Position
- 1) :=
1172 Source
.Data
(1 .. Position
- 1);
1174 Result
.Data
(Position
.. Max_Length
) :=
1175 New_Item
(New_Item
'First .. New_Item
'Last - Droplen
);
1178 when Strings
.Left
=>
1179 if New_Item
'Length >= Max_Length
then
1180 Result
.Data
(1 .. Max_Length
) :=
1181 New_Item
(New_Item
'Last - Max_Length
+ 1 ..
1186 Result
.Data
(1 .. Max_Length
- New_Item
'Length) :=
1187 Source
.Data
(Droplen
+ 1 .. Position
- 1);
1189 (Max_Length
- New_Item
'Length + 1 .. Max_Length
) :=
1194 when Strings
.Error
=>
1195 raise Ada
.Strings
.Length_Error
;
1198 end Super_Overwrite
;
1200 procedure Super_Overwrite
1201 (Source
: in out Super_String
;
1202 Position
: Positive;
1203 New_Item
: Wide_String;
1204 Drop
: Strings
.Truncation
:= Strings
.Error
)
1206 Max_Length
: constant Positive := Source
.Max_Length
;
1207 Endpos
: constant Positive := Position
+ New_Item
'Length - 1;
1208 Slen
: constant Natural := Source
.Current_Length
;
1212 if Position
> Slen
+ 1 then
1213 raise Ada
.Strings
.Index_Error
;
1215 elsif Endpos
<= Slen
then
1216 Source
.Data
(Position
.. Endpos
) := New_Item
;
1218 elsif Endpos
<= Max_Length
then
1219 Source
.Data
(Position
.. Endpos
) := New_Item
;
1220 Source
.Current_Length
:= Endpos
;
1223 Source
.Current_Length
:= Max_Length
;
1224 Droplen
:= Endpos
- Max_Length
;
1227 when Strings
.Right
=>
1228 Source
.Data
(Position
.. Max_Length
) :=
1229 New_Item
(New_Item
'First .. New_Item
'Last - Droplen
);
1231 when Strings
.Left
=>
1232 if New_Item
'Length > Max_Length
then
1233 Source
.Data
(1 .. Max_Length
) :=
1234 New_Item
(New_Item
'Last - Max_Length
+ 1 ..
1238 Source
.Data
(1 .. Max_Length
- New_Item
'Length) :=
1239 Source
.Data
(Droplen
+ 1 .. Position
- 1);
1242 (Max_Length
- New_Item
'Length + 1 .. Max_Length
) :=
1246 when Strings
.Error
=>
1247 raise Ada
.Strings
.Length_Error
;
1250 end Super_Overwrite
;
1252 ---------------------------
1253 -- Super_Replace_Element --
1254 ---------------------------
1256 procedure Super_Replace_Element
1257 (Source
: in out Super_String
;
1259 By
: Wide_Character)
1262 if Index
<= Source
.Current_Length
then
1263 Source
.Data
(Index
) := By
;
1265 raise Ada
.Strings
.Index_Error
;
1267 end Super_Replace_Element
;
1269 -------------------------
1270 -- Super_Replace_Slice --
1271 -------------------------
1273 function Super_Replace_Slice
1274 (Source
: Super_String
;
1278 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1280 Max_Length
: constant Positive := Source
.Max_Length
;
1281 Slen
: constant Natural := Source
.Current_Length
;
1284 if Low
> Slen
+ 1 then
1285 raise Strings
.Index_Error
;
1287 elsif High
< Low
then
1288 return Super_Insert
(Source
, Low
, By
, Drop
);
1292 Blen
: constant Natural := Natural'Max (0, Low
- 1);
1293 Alen
: constant Natural := Natural'Max (0, Slen
- High
);
1294 Tlen
: constant Natural := Blen
+ By
'Length + Alen
;
1295 Droplen
: constant Integer := Tlen
- Max_Length
;
1296 Result
: Super_String
(Max_Length
);
1298 -- Tlen is the total length of the result string before any
1299 -- truncation. Blen and Alen are the lengths of the pieces
1300 -- of the original string that end up in the result string
1301 -- before and after the replaced slice.
1304 if Droplen
<= 0 then
1305 Result
.Current_Length
:= Tlen
;
1306 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1307 Result
.Data
(Low
.. Low
+ By
'Length - 1) := By
;
1308 Result
.Data
(Low
+ By
'Length .. Tlen
) :=
1309 Source
.Data
(High
+ 1 .. Slen
);
1312 Result
.Current_Length
:= Max_Length
;
1315 when Strings
.Right
=>
1316 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1318 if Droplen
> Alen
then
1319 Result
.Data
(Low
.. Max_Length
) :=
1320 By
(By
'First .. By
'First + Max_Length
- Low
);
1322 Result
.Data
(Low
.. Low
+ By
'Length - 1) := By
;
1323 Result
.Data
(Low
+ By
'Length .. Max_Length
) :=
1324 Source
.Data
(High
+ 1 .. Slen
- Droplen
);
1327 when Strings
.Left
=>
1328 Result
.Data
(Max_Length
- (Alen
- 1) .. Max_Length
) :=
1329 Source
.Data
(High
+ 1 .. Slen
);
1331 if Droplen
>= Blen
then
1332 Result
.Data
(1 .. Max_Length
- Alen
) :=
1333 By
(By
'Last - (Max_Length
- Alen
) + 1 .. By
'Last);
1336 (Blen
- Droplen
+ 1 .. Max_Length
- Alen
) := By
;
1337 Result
.Data
(1 .. Blen
- Droplen
) :=
1338 Source
.Data
(Droplen
+ 1 .. Blen
);
1341 when Strings
.Error
=>
1342 raise Ada
.Strings
.Length_Error
;
1349 end Super_Replace_Slice
;
1351 procedure Super_Replace_Slice
1352 (Source
: in out Super_String
;
1356 Drop
: Strings
.Truncation
:= Strings
.Error
)
1359 -- We do a double copy here because this is one of the situations
1360 -- in which we move data to the right, and at least at the moment,
1361 -- GNAT is not handling such cases correctly ???
1363 Source
:= Super_Replace_Slice
(Source
, Low
, High
, By
, Drop
);
1364 end Super_Replace_Slice
;
1366 ---------------------
1367 -- Super_Replicate --
1368 ---------------------
1370 function Super_Replicate
1372 Item
: Wide_Character;
1373 Drop
: Truncation
:= Error
;
1374 Max_Length
: Positive) return Super_String
1376 Result
: Super_String
(Max_Length
);
1379 if Count
<= Max_Length
then
1380 Result
.Current_Length
:= Count
;
1382 elsif Drop
= Strings
.Error
then
1383 raise Ada
.Strings
.Length_Error
;
1386 Result
.Current_Length
:= Max_Length
;
1389 Result
.Data
(1 .. Result
.Current_Length
) := (others => Item
);
1391 end Super_Replicate
;
1393 function Super_Replicate
1396 Drop
: Truncation
:= Error
;
1397 Max_Length
: Positive) return Super_String
1399 Length
: constant Integer := Count
* Item
'Length;
1400 Result
: Super_String
(Max_Length
);
1404 if Length
<= Max_Length
then
1405 Result
.Current_Length
:= Length
;
1410 for J
in 1 .. Count
loop
1411 Result
.Data
(Indx
.. Indx
+ Item
'Length - 1) := Item
;
1412 Indx
:= Indx
+ Item
'Length;
1417 Result
.Current_Length
:= Max_Length
;
1420 when Strings
.Right
=>
1423 while Indx
+ Item
'Length <= Max_Length
+ 1 loop
1424 Result
.Data
(Indx
.. Indx
+ Item
'Length - 1) := Item
;
1425 Indx
:= Indx
+ Item
'Length;
1428 Result
.Data
(Indx
.. Max_Length
) :=
1429 Item
(Item
'First .. Item
'First + Max_Length
- Indx
);
1431 when Strings
.Left
=>
1434 while Indx
- Item
'Length >= 1 loop
1435 Result
.Data
(Indx
- (Item
'Length - 1) .. Indx
) := Item
;
1436 Indx
:= Indx
- Item
'Length;
1439 Result
.Data
(1 .. Indx
) :=
1440 Item
(Item
'Last - Indx
+ 1 .. Item
'Last);
1442 when Strings
.Error
=>
1443 raise Ada
.Strings
.Length_Error
;
1448 end Super_Replicate
;
1450 function Super_Replicate
1452 Item
: Super_String
;
1453 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1459 Item
.Data
(1 .. Item
.Current_Length
),
1462 end Super_Replicate
;
1468 function Super_Slice
1469 (Source
: Super_String
;
1471 High
: Natural) return Wide_String
1474 -- Note: test of High > Length is in accordance with AI95-00128
1476 return R
: Wide_String (Low
.. High
) do
1477 if Low
> Source
.Current_Length
+ 1
1478 or else High
> Source
.Current_Length
1483 R
:= Source
.Data
(Low
.. High
);
1487 function Super_Slice
1488 (Source
: Super_String
;
1490 High
: Natural) return Super_String
1493 return Result
: Super_String
(Source
.Max_Length
) do
1494 if Low
> Source
.Current_Length
+ 1
1495 or else High
> Source
.Current_Length
1500 Result
.Current_Length
:= High
- Low
+ 1;
1501 Result
.Data
(1 .. Result
.Current_Length
) := Source
.Data
(Low
.. High
);
1505 procedure Super_Slice
1506 (Source
: Super_String
;
1507 Target
: out Super_String
;
1512 if Low
> Source
.Current_Length
+ 1
1513 or else High
> Source
.Current_Length
1517 Target
.Current_Length
:= High
- Low
+ 1;
1518 Target
.Data
(1 .. Target
.Current_Length
) := Source
.Data
(Low
.. High
);
1527 (Source
: Super_String
;
1529 Pad
: Wide_Character := Wide_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
: Wide_Character := Wide_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 Wide_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 Wide_String is
1632 return R
: Wide_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
: Wide_Maps
.Wide_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
: Wide_Maps
.Wide_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
: Wide_Maps
.Wide_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
: Wide_Maps
.Wide_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
: Wide_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 => Wide_NUL
);
1748 Source
.Current_Length
:= Last
- First
+ 1;
1749 Source
.Data
(1 .. Source
.Current_Length
) := Temp
(First
.. Last
);
1753 (Source
: Super_String
;
1754 Left
: Wide_Maps
.Wide_Character_Set
;
1755 Right
: Wide_Maps
.Wide_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
: Wide_Maps
.Wide_Character_Set
;
1780 Right
: Wide_Maps
.Wide_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
) := Wide_NUL
;
1806 Source
.Current_Length
:= 0;
1811 Source
.Current_Length
:= 0;
1820 Right
: Wide_Character;
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
;
1842 Right
: Wide_String;
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
.Index_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
1901 (Source
: Wide_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
.Wide_Superbounded
;