1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . S T R I N G S . W I D E _ 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_Wide_Maps
; use Ada
.Strings
.Wide_Wide_Maps
;
33 with Ada
.Strings
.Wide_Wide_Search
;
35 package body Ada
.Strings
.Wide_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_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
;
87 (Left
: Wide_Wide_String
;
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_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_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_Wide_String
) return Boolean
171 return Left
.Current_Length
= Right
'Length
172 and then Left
.Data
(1 .. Left
.Current_Length
) = Right
;
176 (Left
: Wide_Wide_String
;
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_Wide_String
) return Boolean
202 return Left
.Data
(1 .. Left
.Current_Length
) > Right
;
206 (Left
: Wide_Wide_String
;
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_Wide_String
) return Boolean
231 return Left
.Data
(1 .. Left
.Current_Length
) >= Right
;
232 end Greater_Or_Equal
;
234 function Greater_Or_Equal
235 (Left
: Wide_Wide_String
;
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_Wide_String
) return Boolean
260 return Left
.Data
(1 .. Left
.Current_Length
) < Right
;
264 (Left
: Wide_Wide_String
;
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_Wide_String
) return Boolean
289 return Left
.Data
(1 .. Left
.Current_Length
) <= Right
;
292 function Less_Or_Equal
293 (Left
: Wide_Wide_String
;
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_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_Wide_String
436 function Super_Append
437 (Left
: Super_String
;
438 Right
: Wide_Wide_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_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_Wide_String and Super_String
537 function Super_Append
538 (Left
: Wide_Wide_String
;
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_Wide_Character
591 function Super_Append
592 (Left
: Super_String
;
593 Right
: Wide_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_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_Wide_Character and Super_String
659 function Super_Append
660 (Left
: Wide_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_Wide_String
;
700 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
701 Wide_Wide_Maps
.Identity
) return Natural
705 Wide_Wide_Search
.Count
706 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Mapping
);
710 (Source
: Super_String
;
711 Pattern
: Wide_Wide_String
;
712 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
717 Wide_Wide_Search
.Count
718 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Mapping
);
722 (Source
: Super_String
;
723 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
) return Natural
726 return Wide_Wide_Search
.Count
727 (Source
.Data
(1 .. Source
.Current_Length
), Set
);
734 function Super_Delete
735 (Source
: Super_String
;
737 Through
: Natural) return Super_String
739 Result
: Super_String
(Source
.Max_Length
);
740 Slen
: constant Natural := Source
.Current_Length
;
741 Num_Delete
: constant Integer := Through
- From
+ 1;
744 if Num_Delete
<= 0 then
747 elsif From
> Slen
+ 1 then
748 raise Ada
.Strings
.Index_Error
;
750 elsif Through
>= Slen
then
751 Result
.Current_Length
:= From
- 1;
752 Result
.Data
(1 .. From
- 1) := Source
.Data
(1 .. From
- 1);
756 Result
.Current_Length
:= Slen
- Num_Delete
;
757 Result
.Data
(1 .. From
- 1) := Source
.Data
(1 .. From
- 1);
758 Result
.Data
(From
.. Result
.Current_Length
) :=
759 Source
.Data
(Through
+ 1 .. Slen
);
764 procedure Super_Delete
765 (Source
: in out Super_String
;
769 Slen
: constant Natural := Source
.Current_Length
;
770 Num_Delete
: constant Integer := Through
- From
+ 1;
773 if Num_Delete
<= 0 then
776 elsif From
> Slen
+ 1 then
777 raise Ada
.Strings
.Index_Error
;
779 elsif Through
>= Slen
then
780 Source
.Current_Length
:= From
- 1;
783 Source
.Current_Length
:= Slen
- Num_Delete
;
784 Source
.Data
(From
.. Source
.Current_Length
) :=
785 Source
.Data
(Through
+ 1 .. Slen
);
793 function Super_Element
794 (Source
: Super_String
;
795 Index
: Positive) return Wide_Wide_Character
798 if Index
<= Source
.Current_Length
then
799 return Source
.Data
(Index
);
801 raise Strings
.Index_Error
;
805 ----------------------
806 -- Super_Find_Token --
807 ----------------------
809 procedure Super_Find_Token
810 (Source
: Super_String
;
811 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
813 Test
: Strings
.Membership
;
814 First
: out Positive;
818 Wide_Wide_Search
.Find_Token
819 (Source
.Data
(From
.. Source
.Current_Length
), Set
, Test
, First
, Last
);
820 end Super_Find_Token
;
822 procedure Super_Find_Token
823 (Source
: Super_String
;
824 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
825 Test
: Strings
.Membership
;
826 First
: out Positive;
830 Wide_Wide_Search
.Find_Token
831 (Source
.Data
(1 .. Source
.Current_Length
), Set
, Test
, First
, Last
);
832 end Super_Find_Token
;
839 (Source
: Super_String
;
841 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
842 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
844 Max_Length
: constant Positive := Source
.Max_Length
;
845 Result
: Super_String
(Max_Length
);
846 Slen
: constant Natural := Source
.Current_Length
;
847 Npad
: constant Integer := Count
- Slen
;
851 Result
.Current_Length
:= Count
;
852 Result
.Data
(1 .. Count
) := Source
.Data
(1 .. Count
);
854 elsif Count
<= Max_Length
then
855 Result
.Current_Length
:= Count
;
856 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
857 Result
.Data
(Slen
+ 1 .. Count
) := (others => Pad
);
860 Result
.Current_Length
:= Max_Length
;
863 when Strings
.Right
=>
864 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
865 Result
.Data
(Slen
+ 1 .. Max_Length
) := (others => Pad
);
868 if Npad
>= Max_Length
then
869 Result
.Data
:= (others => Pad
);
872 Result
.Data
(1 .. Max_Length
- Npad
) :=
873 Source
.Data
(Count
- Max_Length
+ 1 .. Slen
);
874 Result
.Data
(Max_Length
- Npad
+ 1 .. Max_Length
) :=
878 when Strings
.Error
=>
879 raise Ada
.Strings
.Length_Error
;
887 (Source
: in out Super_String
;
889 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
890 Drop
: Truncation
:= Error
)
892 Max_Length
: constant Positive := Source
.Max_Length
;
893 Slen
: constant Natural := Source
.Current_Length
;
894 Npad
: constant Integer := Count
- Slen
;
895 Temp
: Wide_Wide_String
(1 .. Max_Length
);
899 Source
.Current_Length
:= Count
;
901 elsif Count
<= Max_Length
then
902 Source
.Current_Length
:= Count
;
903 Source
.Data
(Slen
+ 1 .. Count
) := (others => Pad
);
906 Source
.Current_Length
:= Max_Length
;
909 when Strings
.Right
=>
910 Source
.Data
(Slen
+ 1 .. Max_Length
) := (others => Pad
);
913 if Npad
> Max_Length
then
914 Source
.Data
:= (others => Pad
);
918 Source
.Data
(1 .. Max_Length
- Npad
) :=
919 Temp
(Count
- Max_Length
+ 1 .. Slen
);
921 for J
in Max_Length
- Npad
+ 1 .. Max_Length
loop
922 Source
.Data
(J
) := Pad
;
926 when Strings
.Error
=>
927 raise Ada
.Strings
.Length_Error
;
937 (Source
: Super_String
;
938 Pattern
: Wide_Wide_String
;
939 Going
: Strings
.Direction
:= Strings
.Forward
;
940 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
941 Wide_Wide_Maps
.Identity
) return Natural
944 return Wide_Wide_Search
.Index
945 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Going
, Mapping
);
949 (Source
: Super_String
;
950 Pattern
: Wide_Wide_String
;
951 Going
: Direction
:= Forward
;
952 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
956 return Wide_Wide_Search
.Index
957 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Going
, Mapping
);
961 (Source
: Super_String
;
962 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
963 Test
: Strings
.Membership
:= Strings
.Inside
;
964 Going
: Strings
.Direction
:= Strings
.Forward
) return Natural
967 return Wide_Wide_Search
.Index
968 (Source
.Data
(1 .. Source
.Current_Length
), Set
, Test
, Going
);
972 (Source
: Super_String
;
973 Pattern
: Wide_Wide_String
;
975 Going
: Direction
:= Forward
;
976 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
977 Wide_Wide_Maps
.Identity
) return Natural
980 return Wide_Wide_Search
.Index
981 (Source
.Data
(1 .. Source
.Current_Length
),
982 Pattern
, From
, Going
, Mapping
);
986 (Source
: Super_String
;
987 Pattern
: Wide_Wide_String
;
989 Going
: Direction
:= Forward
;
990 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
994 return Wide_Wide_Search
.Index
995 (Source
.Data
(1 .. Source
.Current_Length
),
996 Pattern
, From
, Going
, Mapping
);
1000 (Source
: Super_String
;
1001 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
1003 Test
: Membership
:= Inside
;
1004 Going
: Direction
:= Forward
) return Natural
1007 return Wide_Wide_Search
.Index
1008 (Source
.Data
(1 .. Source
.Current_Length
), Set
, From
, Test
, Going
);
1011 ---------------------------
1012 -- Super_Index_Non_Blank --
1013 ---------------------------
1015 function Super_Index_Non_Blank
1016 (Source
: Super_String
;
1017 Going
: Strings
.Direction
:= Strings
.Forward
) return Natural
1021 Wide_Wide_Search
.Index_Non_Blank
1022 (Source
.Data
(1 .. Source
.Current_Length
), Going
);
1023 end Super_Index_Non_Blank
;
1025 function Super_Index_Non_Blank
1026 (Source
: Super_String
;
1028 Going
: Direction
:= Forward
) return Natural
1032 Wide_Wide_Search
.Index_Non_Blank
1033 (Source
.Data
(1 .. Source
.Current_Length
), From
, Going
);
1034 end Super_Index_Non_Blank
;
1040 function Super_Insert
1041 (Source
: Super_String
;
1043 New_Item
: Wide_Wide_String
;
1044 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1046 Max_Length
: constant Positive := Source
.Max_Length
;
1047 Result
: Super_String
(Max_Length
);
1048 Slen
: constant Natural := Source
.Current_Length
;
1049 Nlen
: constant Natural := New_Item
'Length;
1050 Tlen
: constant Natural := Slen
+ Nlen
;
1051 Blen
: constant Natural := Before
- 1;
1052 Alen
: constant Integer := Slen
- Blen
;
1053 Droplen
: constant Integer := Tlen
- Max_Length
;
1055 -- Tlen is the length of the total string before possible truncation.
1056 -- Blen, Alen are the lengths of the before and after pieces of the
1061 raise Ada
.Strings
.Index_Error
;
1063 elsif Droplen
<= 0 then
1064 Result
.Current_Length
:= Tlen
;
1065 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1066 Result
.Data
(Before
.. Before
+ Nlen
- 1) := New_Item
;
1067 Result
.Data
(Before
+ Nlen
.. Tlen
) :=
1068 Source
.Data
(Before
.. Slen
);
1071 Result
.Current_Length
:= Max_Length
;
1074 when Strings
.Right
=>
1075 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1077 if Droplen
> Alen
then
1078 Result
.Data
(Before
.. Max_Length
) :=
1079 New_Item
(New_Item
'First
1080 .. New_Item
'First + Max_Length
- Before
);
1082 Result
.Data
(Before
.. Before
+ Nlen
- 1) := New_Item
;
1083 Result
.Data
(Before
+ Nlen
.. Max_Length
) :=
1084 Source
.Data
(Before
.. Slen
- Droplen
);
1087 when Strings
.Left
=>
1088 Result
.Data
(Max_Length
- (Alen
- 1) .. Max_Length
) :=
1089 Source
.Data
(Before
.. Slen
);
1091 if Droplen
>= Blen
then
1092 Result
.Data
(1 .. Max_Length
- Alen
) :=
1093 New_Item
(New_Item
'Last - (Max_Length
- Alen
) + 1
1097 (Blen
- Droplen
+ 1 .. Max_Length
- Alen
) :=
1099 Result
.Data
(1 .. Blen
- Droplen
) :=
1100 Source
.Data
(Droplen
+ 1 .. Blen
);
1103 when Strings
.Error
=>
1104 raise Ada
.Strings
.Length_Error
;
1111 procedure Super_Insert
1112 (Source
: in out Super_String
;
1114 New_Item
: Wide_Wide_String
;
1115 Drop
: Strings
.Truncation
:= Strings
.Error
)
1118 -- We do a double copy here because this is one of the situations
1119 -- in which we move data to the right, and at least at the moment,
1120 -- GNAT is not handling such cases correctly ???
1122 Source
:= Super_Insert
(Source
, Before
, New_Item
, Drop
);
1129 function Super_Length
(Source
: Super_String
) return Natural is
1131 return Source
.Current_Length
;
1134 ---------------------
1135 -- Super_Overwrite --
1136 ---------------------
1138 function Super_Overwrite
1139 (Source
: Super_String
;
1140 Position
: Positive;
1141 New_Item
: Wide_Wide_String
;
1142 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1144 Max_Length
: constant Positive := Source
.Max_Length
;
1145 Result
: Super_String
(Max_Length
);
1146 Endpos
: constant Natural := Position
+ New_Item
'Length - 1;
1147 Slen
: constant Natural := Source
.Current_Length
;
1151 if Position
> Slen
+ 1 then
1152 raise Ada
.Strings
.Index_Error
;
1154 elsif New_Item
'Length = 0 then
1157 elsif Endpos
<= Slen
then
1158 Result
.Current_Length
:= Source
.Current_Length
;
1159 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
1160 Result
.Data
(Position
.. Endpos
) := New_Item
;
1163 elsif Endpos
<= Max_Length
then
1164 Result
.Current_Length
:= Endpos
;
1165 Result
.Data
(1 .. Position
- 1) := Source
.Data
(1 .. Position
- 1);
1166 Result
.Data
(Position
.. Endpos
) := New_Item
;
1170 Result
.Current_Length
:= Max_Length
;
1171 Droplen
:= Endpos
- Max_Length
;
1174 when Strings
.Right
=>
1175 Result
.Data
(1 .. Position
- 1) :=
1176 Source
.Data
(1 .. Position
- 1);
1178 Result
.Data
(Position
.. Max_Length
) :=
1179 New_Item
(New_Item
'First .. New_Item
'Last - Droplen
);
1182 when Strings
.Left
=>
1183 if New_Item
'Length >= Max_Length
then
1184 Result
.Data
(1 .. Max_Length
) :=
1185 New_Item
(New_Item
'Last - Max_Length
+ 1 ..
1190 Result
.Data
(1 .. Max_Length
- New_Item
'Length) :=
1191 Source
.Data
(Droplen
+ 1 .. Position
- 1);
1193 (Max_Length
- New_Item
'Length + 1 .. Max_Length
) :=
1198 when Strings
.Error
=>
1199 raise Ada
.Strings
.Length_Error
;
1202 end Super_Overwrite
;
1204 procedure Super_Overwrite
1205 (Source
: in out Super_String
;
1206 Position
: Positive;
1207 New_Item
: Wide_Wide_String
;
1208 Drop
: Strings
.Truncation
:= Strings
.Error
)
1210 Max_Length
: constant Positive := Source
.Max_Length
;
1211 Endpos
: constant Positive := Position
+ New_Item
'Length - 1;
1212 Slen
: constant Natural := Source
.Current_Length
;
1216 if Position
> Slen
+ 1 then
1217 raise Ada
.Strings
.Index_Error
;
1219 elsif Endpos
<= Slen
then
1220 Source
.Data
(Position
.. Endpos
) := New_Item
;
1222 elsif Endpos
<= Max_Length
then
1223 Source
.Data
(Position
.. Endpos
) := New_Item
;
1224 Source
.Current_Length
:= Endpos
;
1227 Source
.Current_Length
:= Max_Length
;
1228 Droplen
:= Endpos
- Max_Length
;
1231 when Strings
.Right
=>
1232 Source
.Data
(Position
.. Max_Length
) :=
1233 New_Item
(New_Item
'First .. New_Item
'Last - Droplen
);
1235 when Strings
.Left
=>
1236 if New_Item
'Length > Max_Length
then
1237 Source
.Data
(1 .. Max_Length
) :=
1238 New_Item
(New_Item
'Last - Max_Length
+ 1 ..
1242 Source
.Data
(1 .. Max_Length
- New_Item
'Length) :=
1243 Source
.Data
(Droplen
+ 1 .. Position
- 1);
1246 (Max_Length
- New_Item
'Length + 1 .. Max_Length
) :=
1250 when Strings
.Error
=>
1251 raise Ada
.Strings
.Length_Error
;
1254 end Super_Overwrite
;
1256 ---------------------------
1257 -- Super_Replace_Element --
1258 ---------------------------
1260 procedure Super_Replace_Element
1261 (Source
: in out Super_String
;
1263 By
: Wide_Wide_Character
)
1266 if Index
<= Source
.Current_Length
then
1267 Source
.Data
(Index
) := By
;
1269 raise Ada
.Strings
.Index_Error
;
1271 end Super_Replace_Element
;
1273 -------------------------
1274 -- Super_Replace_Slice --
1275 -------------------------
1277 function Super_Replace_Slice
1278 (Source
: Super_String
;
1281 By
: Wide_Wide_String
;
1282 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1284 Max_Length
: constant Positive := Source
.Max_Length
;
1285 Slen
: constant Natural := Source
.Current_Length
;
1288 if Low
> Slen
+ 1 then
1289 raise Strings
.Index_Error
;
1291 elsif High
< Low
then
1292 return Super_Insert
(Source
, Low
, By
, Drop
);
1296 Blen
: constant Natural := Natural'Max (0, Low
- 1);
1297 Alen
: constant Natural := Natural'Max (0, Slen
- High
);
1298 Tlen
: constant Natural := Blen
+ By
'Length + Alen
;
1299 Droplen
: constant Integer := Tlen
- Max_Length
;
1300 Result
: Super_String
(Max_Length
);
1302 -- Tlen is the total length of the result string before any
1303 -- truncation. Blen and Alen are the lengths of the pieces
1304 -- of the original string that end up in the result string
1305 -- before and after the replaced slice.
1308 if Droplen
<= 0 then
1309 Result
.Current_Length
:= Tlen
;
1310 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1311 Result
.Data
(Low
.. Low
+ By
'Length - 1) := By
;
1312 Result
.Data
(Low
+ By
'Length .. Tlen
) :=
1313 Source
.Data
(High
+ 1 .. Slen
);
1316 Result
.Current_Length
:= Max_Length
;
1319 when Strings
.Right
=>
1320 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1322 if Droplen
> Alen
then
1323 Result
.Data
(Low
.. Max_Length
) :=
1324 By
(By
'First .. By
'First + Max_Length
- Low
);
1326 Result
.Data
(Low
.. Low
+ By
'Length - 1) := By
;
1327 Result
.Data
(Low
+ By
'Length .. Max_Length
) :=
1328 Source
.Data
(High
+ 1 .. Slen
- Droplen
);
1331 when Strings
.Left
=>
1332 Result
.Data
(Max_Length
- (Alen
- 1) .. Max_Length
) :=
1333 Source
.Data
(High
+ 1 .. Slen
);
1335 if Droplen
>= Blen
then
1336 Result
.Data
(1 .. Max_Length
- Alen
) :=
1337 By
(By
'Last - (Max_Length
- Alen
) + 1 .. By
'Last);
1340 (Blen
- Droplen
+ 1 .. Max_Length
- Alen
) := By
;
1341 Result
.Data
(1 .. Blen
- Droplen
) :=
1342 Source
.Data
(Droplen
+ 1 .. Blen
);
1345 when Strings
.Error
=>
1346 raise Ada
.Strings
.Length_Error
;
1353 end Super_Replace_Slice
;
1355 procedure Super_Replace_Slice
1356 (Source
: in out Super_String
;
1359 By
: Wide_Wide_String
;
1360 Drop
: Strings
.Truncation
:= Strings
.Error
)
1363 -- We do a double copy here because this is one of the situations
1364 -- in which we move data to the right, and at least at the moment,
1365 -- GNAT is not handling such cases correctly ???
1367 Source
:= Super_Replace_Slice
(Source
, Low
, High
, By
, Drop
);
1368 end Super_Replace_Slice
;
1370 ---------------------
1371 -- Super_Replicate --
1372 ---------------------
1374 function Super_Replicate
1376 Item
: Wide_Wide_Character
;
1377 Drop
: Truncation
:= Error
;
1378 Max_Length
: Positive) return Super_String
1380 Result
: Super_String
(Max_Length
);
1383 if Count
<= Max_Length
then
1384 Result
.Current_Length
:= Count
;
1386 elsif Drop
= Strings
.Error
then
1387 raise Ada
.Strings
.Length_Error
;
1390 Result
.Current_Length
:= Max_Length
;
1393 Result
.Data
(1 .. Result
.Current_Length
) := (others => Item
);
1395 end Super_Replicate
;
1397 function Super_Replicate
1399 Item
: Wide_Wide_String
;
1400 Drop
: Truncation
:= Error
;
1401 Max_Length
: Positive) return Super_String
1403 Length
: constant Integer := Count
* Item
'Length;
1404 Result
: Super_String
(Max_Length
);
1408 if Length
<= Max_Length
then
1409 Result
.Current_Length
:= Length
;
1414 for J
in 1 .. Count
loop
1415 Result
.Data
(Indx
.. Indx
+ Item
'Length - 1) := Item
;
1416 Indx
:= Indx
+ Item
'Length;
1421 Result
.Current_Length
:= Max_Length
;
1424 when Strings
.Right
=>
1427 while Indx
+ Item
'Length <= Max_Length
+ 1 loop
1428 Result
.Data
(Indx
.. Indx
+ Item
'Length - 1) := Item
;
1429 Indx
:= Indx
+ Item
'Length;
1432 Result
.Data
(Indx
.. Max_Length
) :=
1433 Item
(Item
'First .. Item
'First + Max_Length
- Indx
);
1435 when Strings
.Left
=>
1438 while Indx
- Item
'Length >= 1 loop
1439 Result
.Data
(Indx
- (Item
'Length - 1) .. Indx
) := Item
;
1440 Indx
:= Indx
- Item
'Length;
1443 Result
.Data
(1 .. Indx
) :=
1444 Item
(Item
'Last - Indx
+ 1 .. Item
'Last);
1446 when Strings
.Error
=>
1447 raise Ada
.Strings
.Length_Error
;
1452 end Super_Replicate
;
1454 function Super_Replicate
1456 Item
: Super_String
;
1457 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1463 Item
.Data
(1 .. Item
.Current_Length
),
1466 end Super_Replicate
;
1472 function Super_Slice
1473 (Source
: Super_String
;
1475 High
: Natural) return Wide_Wide_String
1478 -- Note: test of High > Length is in accordance with AI95-00128
1480 return R
: Wide_Wide_String
(Low
.. High
) do
1481 if Low
> Source
.Current_Length
+ 1
1482 or else High
> Source
.Current_Length
1487 R
:= Source
.Data
(Low
.. High
);
1491 function Super_Slice
1492 (Source
: Super_String
;
1494 High
: Natural) return Super_String
1497 return Result
: Super_String
(Source
.Max_Length
) do
1498 if Low
> Source
.Current_Length
+ 1
1499 or else High
> Source
.Current_Length
1503 Result
.Current_Length
:= High
- Low
+ 1;
1504 Result
.Data
(1 .. Result
.Current_Length
) :=
1505 Source
.Data
(Low
.. High
);
1510 procedure Super_Slice
1511 (Source
: Super_String
;
1512 Target
: out Super_String
;
1517 if Low
> Source
.Current_Length
+ 1
1518 or else High
> Source
.Current_Length
1522 Target
.Current_Length
:= High
- Low
+ 1;
1523 Target
.Data
(1 .. Target
.Current_Length
) := Source
.Data
(Low
.. High
);
1532 (Source
: Super_String
;
1534 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
1535 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1537 Max_Length
: constant Positive := Source
.Max_Length
;
1538 Result
: Super_String
(Max_Length
);
1539 Slen
: constant Natural := Source
.Current_Length
;
1540 Npad
: constant Integer := Count
- Slen
;
1544 Result
.Current_Length
:= Count
;
1545 Result
.Data
(1 .. Count
) :=
1546 Source
.Data
(Slen
- (Count
- 1) .. Slen
);
1548 elsif Count
<= Max_Length
then
1549 Result
.Current_Length
:= Count
;
1550 Result
.Data
(1 .. Npad
) := (others => Pad
);
1551 Result
.Data
(Npad
+ 1 .. Count
) := Source
.Data
(1 .. Slen
);
1554 Result
.Current_Length
:= Max_Length
;
1557 when Strings
.Right
=>
1558 if Npad
>= Max_Length
then
1559 Result
.Data
:= (others => Pad
);
1562 Result
.Data
(1 .. Npad
) := (others => Pad
);
1563 Result
.Data
(Npad
+ 1 .. Max_Length
) :=
1564 Source
.Data
(1 .. Max_Length
- Npad
);
1567 when Strings
.Left
=>
1568 Result
.Data
(1 .. Max_Length
- Slen
) := (others => Pad
);
1569 Result
.Data
(Max_Length
- Slen
+ 1 .. Max_Length
) :=
1570 Source
.Data
(1 .. Slen
);
1572 when Strings
.Error
=>
1573 raise Ada
.Strings
.Length_Error
;
1580 procedure Super_Tail
1581 (Source
: in out Super_String
;
1583 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
1584 Drop
: Truncation
:= Error
)
1586 Max_Length
: constant Positive := Source
.Max_Length
;
1587 Slen
: constant Natural := Source
.Current_Length
;
1588 Npad
: constant Integer := Count
- Slen
;
1590 Temp
: constant Wide_Wide_String
(1 .. Max_Length
) := Source
.Data
;
1594 Source
.Current_Length
:= Count
;
1595 Source
.Data
(1 .. Count
) :=
1596 Temp
(Slen
- (Count
- 1) .. Slen
);
1598 elsif Count
<= Max_Length
then
1599 Source
.Current_Length
:= Count
;
1600 Source
.Data
(1 .. Npad
) := (others => Pad
);
1601 Source
.Data
(Npad
+ 1 .. Count
) := Temp
(1 .. Slen
);
1604 Source
.Current_Length
:= Max_Length
;
1607 when Strings
.Right
=>
1608 if Npad
>= Max_Length
then
1609 Source
.Data
:= (others => Pad
);
1612 Source
.Data
(1 .. Npad
) := (others => Pad
);
1613 Source
.Data
(Npad
+ 1 .. Max_Length
) :=
1614 Temp
(1 .. Max_Length
- Npad
);
1617 when Strings
.Left
=>
1618 for J
in 1 .. Max_Length
- Slen
loop
1619 Source
.Data
(J
) := Pad
;
1622 Source
.Data
(Max_Length
- Slen
+ 1 .. Max_Length
) :=
1625 when Strings
.Error
=>
1626 raise Ada
.Strings
.Length_Error
;
1631 ---------------------
1632 -- Super_To_String --
1633 ---------------------
1635 function Super_To_String
1636 (Source
: Super_String
) return Wide_Wide_String
1639 return R
: Wide_Wide_String
(1 .. Source
.Current_Length
) do
1640 R
:= Source
.Data
(1 .. Source
.Current_Length
);
1642 end Super_To_String
;
1644 ---------------------
1645 -- Super_Translate --
1646 ---------------------
1648 function Super_Translate
1649 (Source
: Super_String
;
1650 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
)
1653 Result
: Super_String
(Source
.Max_Length
);
1656 Result
.Current_Length
:= Source
.Current_Length
;
1658 for J
in 1 .. Source
.Current_Length
loop
1659 Result
.Data
(J
) := Value
(Mapping
, Source
.Data
(J
));
1663 end Super_Translate
;
1665 procedure Super_Translate
1666 (Source
: in out Super_String
;
1667 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
)
1670 for J
in 1 .. Source
.Current_Length
loop
1671 Source
.Data
(J
) := Value
(Mapping
, Source
.Data
(J
));
1673 end Super_Translate
;
1675 function Super_Translate
1676 (Source
: Super_String
;
1677 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
1680 Result
: Super_String
(Source
.Max_Length
);
1683 Result
.Current_Length
:= Source
.Current_Length
;
1685 for J
in 1 .. Source
.Current_Length
loop
1686 Result
.Data
(J
) := Mapping
.all (Source
.Data
(J
));
1690 end Super_Translate
;
1692 procedure Super_Translate
1693 (Source
: in out Super_String
;
1694 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
1697 for J
in 1 .. Source
.Current_Length
loop
1698 Source
.Data
(J
) := Mapping
.all (Source
.Data
(J
));
1700 end Super_Translate
;
1707 (Source
: Super_String
;
1708 Side
: Trim_End
) return Super_String
1710 Result
: Super_String
(Source
.Max_Length
);
1711 Last
: Natural := Source
.Current_Length
;
1712 First
: Positive := 1;
1715 if Side
= Left
or else Side
= Both
then
1716 while First
<= Last
and then Source
.Data
(First
) = ' ' loop
1721 if Side
= Right
or else Side
= Both
then
1722 while Last
>= First
and then Source
.Data
(Last
) = ' ' loop
1727 Result
.Current_Length
:= Last
- First
+ 1;
1728 Result
.Data
(1 .. Result
.Current_Length
) := Source
.Data
(First
.. Last
);
1732 procedure Super_Trim
1733 (Source
: in out Super_String
;
1736 Max_Length
: constant Positive := Source
.Max_Length
;
1737 Last
: Natural := Source
.Current_Length
;
1738 First
: Positive := 1;
1739 Temp
: Wide_Wide_String
(1 .. Max_Length
);
1742 Temp
(1 .. Last
) := Source
.Data
(1 .. Last
);
1744 if Side
= Left
or else Side
= Both
then
1745 while First
<= Last
and then Temp
(First
) = ' ' loop
1750 if Side
= Right
or else Side
= Both
then
1751 while Last
>= First
and then Temp
(Last
) = ' ' loop
1756 Source
.Data
:= (others => Wide_Wide_NUL
);
1757 Source
.Current_Length
:= Last
- First
+ 1;
1758 Source
.Data
(1 .. Source
.Current_Length
) := Temp
(First
.. Last
);
1762 (Source
: Super_String
;
1763 Left
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
1764 Right
: Wide_Wide_Maps
.Wide_Wide_Character_Set
) return Super_String
1766 Result
: Super_String
(Source
.Max_Length
);
1769 for First
in 1 .. Source
.Current_Length
loop
1770 if not Is_In
(Source
.Data
(First
), Left
) then
1771 for Last
in reverse First
.. Source
.Current_Length
loop
1772 if not Is_In
(Source
.Data
(Last
), Right
) then
1773 Result
.Current_Length
:= Last
- First
+ 1;
1774 Result
.Data
(1 .. Result
.Current_Length
) :=
1775 Source
.Data
(First
.. Last
);
1782 Result
.Current_Length
:= 0;
1786 procedure Super_Trim
1787 (Source
: in out Super_String
;
1788 Left
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
1789 Right
: Wide_Wide_Maps
.Wide_Wide_Character_Set
)
1792 for First
in 1 .. Source
.Current_Length
loop
1793 if not Is_In
(Source
.Data
(First
), Left
) then
1794 for Last
in reverse First
.. Source
.Current_Length
loop
1795 if not Is_In
(Source
.Data
(Last
), Right
) then
1797 Source
.Current_Length
:= Last
;
1800 Source
.Current_Length
:= Last
- First
+ 1;
1801 Source
.Data
(1 .. Source
.Current_Length
) :=
1802 Source
.Data
(First
.. Last
);
1804 for J
in Source
.Current_Length
+ 1 ..
1807 Source
.Data
(J
) := Wide_Wide_NUL
;
1815 Source
.Current_Length
:= 0;
1820 Source
.Current_Length
:= 0;
1829 Right
: Wide_Wide_Character
;
1830 Max_Length
: Positive) return Super_String
1832 Result
: Super_String
(Max_Length
);
1835 if Left
> Max_Length
then
1836 raise Ada
.Strings
.Length_Error
;
1839 Result
.Current_Length
:= Left
;
1841 for J
in 1 .. Left
loop
1842 Result
.Data
(J
) := Right
;
1851 Right
: Wide_Wide_String
;
1852 Max_Length
: Positive) return Super_String
1854 Result
: Super_String
(Max_Length
);
1855 Pos
: Positive := 1;
1856 Rlen
: constant Natural := Right
'Length;
1857 Nlen
: constant Natural := Left
* Rlen
;
1860 if Nlen
> Max_Length
then
1861 raise Ada
.Strings
.Index_Error
;
1864 Result
.Current_Length
:= Nlen
;
1867 for J
in 1 .. Left
loop
1868 Result
.Data
(Pos
.. Pos
+ Rlen
- 1) := Right
;
1879 Right
: Super_String
) return Super_String
1881 Result
: Super_String
(Right
.Max_Length
);
1882 Pos
: Positive := 1;
1883 Rlen
: constant Natural := Right
.Current_Length
;
1884 Nlen
: constant Natural := Left
* Rlen
;
1887 if Nlen
> Right
.Max_Length
then
1888 raise Ada
.Strings
.Length_Error
;
1891 Result
.Current_Length
:= Nlen
;
1894 for J
in 1 .. Left
loop
1895 Result
.Data
(Pos
.. Pos
+ Rlen
- 1) :=
1896 Right
.Data
(1 .. Rlen
);
1905 ---------------------
1906 -- To_Super_String --
1907 ---------------------
1909 function To_Super_String
1910 (Source
: Wide_Wide_String
;
1911 Max_Length
: Natural;
1912 Drop
: Truncation
:= Error
) return Super_String
1914 Result
: Super_String
(Max_Length
);
1915 Slen
: constant Natural := Source
'Length;
1918 if Slen
<= Max_Length
then
1919 Result
.Current_Length
:= Slen
;
1920 Result
.Data
(1 .. Slen
) := Source
;
1924 when Strings
.Right
=>
1925 Result
.Current_Length
:= Max_Length
;
1926 Result
.Data
(1 .. Max_Length
) :=
1927 Source
(Source
'First .. Source
'First - 1 + Max_Length
);
1929 when Strings
.Left
=>
1930 Result
.Current_Length
:= Max_Length
;
1931 Result
.Data
(1 .. Max_Length
) :=
1932 Source
(Source
'Last - (Max_Length
- 1) .. Source
'Last);
1934 when Strings
.Error
=>
1935 raise Ada
.Strings
.Length_Error
;
1940 end To_Super_String
;
1942 end Ada
.Strings
.Wide_Wide_Superbounded
;