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-2009, 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
45 Result
: Super_String
(Left
.Max_Length
);
46 Llen
: constant Natural := Left
.Current_Length
;
47 Rlen
: constant Natural := Right
.Current_Length
;
48 Nlen
: constant Natural := Llen
+ Rlen
;
51 if Nlen
> Left
.Max_Length
then
52 raise Ada
.Strings
.Length_Error
;
54 Result
.Current_Length
:= Nlen
;
55 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
56 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
.Data
(1 .. Rlen
);
64 Right
: Wide_Wide_String
) return Super_String
66 Result
: Super_String
(Left
.Max_Length
);
67 Llen
: constant Natural := Left
.Current_Length
;
69 Nlen
: constant Natural := Llen
+ Right
'Length;
72 if Nlen
> Left
.Max_Length
then
73 raise Ada
.Strings
.Length_Error
;
75 Result
.Current_Length
:= Nlen
;
76 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
77 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
;
83 (Left
: Wide_Wide_String
;
84 Right
: Super_String
) return Super_String
86 Result
: Super_String
(Right
.Max_Length
);
87 Llen
: constant Natural := Left
'Length;
88 Rlen
: constant Natural := Right
.Current_Length
;
89 Nlen
: constant Natural := Llen
+ Rlen
;
92 if Nlen
> Right
.Max_Length
then
93 raise Ada
.Strings
.Length_Error
;
95 Result
.Current_Length
:= Nlen
;
96 Result
.Data
(1 .. Llen
) := Left
;
97 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
.Data
(1 .. Rlen
);
104 (Left
: Super_String
;
105 Right
: Wide_Wide_Character
) return Super_String
107 Result
: Super_String
(Left
.Max_Length
);
108 Llen
: constant Natural := Left
.Current_Length
;
111 if Llen
= Left
.Max_Length
then
112 raise Ada
.Strings
.Length_Error
;
114 Result
.Current_Length
:= Llen
+ 1;
115 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
116 Result
.Data
(Result
.Current_Length
) := Right
;
123 (Left
: Wide_Wide_Character
;
124 Right
: Super_String
) return Super_String
126 Result
: Super_String
(Right
.Max_Length
);
127 Rlen
: constant Natural := Right
.Current_Length
;
130 if Rlen
= Right
.Max_Length
then
131 raise Ada
.Strings
.Length_Error
;
133 Result
.Current_Length
:= Rlen
+ 1;
134 Result
.Data
(1) := Left
;
135 Result
.Data
(2 .. Result
.Current_Length
) := Right
.Data
(1 .. Rlen
);
146 (Left
: Super_String
;
147 Right
: Super_String
) return Boolean
150 return Left
.Current_Length
= Right
.Current_Length
151 and then Left
.Data
(1 .. Left
.Current_Length
) =
152 Right
.Data
(1 .. Right
.Current_Length
);
156 (Left
: Super_String
;
157 Right
: Wide_Wide_String
) return Boolean
160 return Left
.Current_Length
= Right
'Length
161 and then Left
.Data
(1 .. Left
.Current_Length
) = Right
;
165 (Left
: Wide_Wide_String
;
166 Right
: Super_String
) return Boolean
169 return Left
'Length = Right
.Current_Length
170 and then Left
= Right
.Data
(1 .. Right
.Current_Length
);
178 (Left
: Super_String
;
179 Right
: Super_String
) return Boolean
182 return Left
.Data
(1 .. Left
.Current_Length
) >
183 Right
.Data
(1 .. Right
.Current_Length
);
187 (Left
: Super_String
;
188 Right
: Wide_Wide_String
) return Boolean
191 return Left
.Data
(1 .. Left
.Current_Length
) > Right
;
195 (Left
: Wide_Wide_String
;
196 Right
: Super_String
) return Boolean
199 return Left
> Right
.Data
(1 .. Right
.Current_Length
);
202 ----------------------
203 -- Greater_Or_Equal --
204 ----------------------
206 function Greater_Or_Equal
207 (Left
: Super_String
;
208 Right
: Super_String
) return Boolean
211 return Left
.Data
(1 .. Left
.Current_Length
) >=
212 Right
.Data
(1 .. Right
.Current_Length
);
213 end Greater_Or_Equal
;
215 function Greater_Or_Equal
216 (Left
: Super_String
;
217 Right
: Wide_Wide_String
) return Boolean
220 return Left
.Data
(1 .. Left
.Current_Length
) >= Right
;
221 end Greater_Or_Equal
;
223 function Greater_Or_Equal
224 (Left
: Wide_Wide_String
;
225 Right
: Super_String
) return Boolean
228 return Left
>= Right
.Data
(1 .. Right
.Current_Length
);
229 end Greater_Or_Equal
;
236 (Left
: Super_String
;
237 Right
: Super_String
) return Boolean
240 return Left
.Data
(1 .. Left
.Current_Length
) <
241 Right
.Data
(1 .. Right
.Current_Length
);
245 (Left
: Super_String
;
246 Right
: Wide_Wide_String
) return Boolean
249 return Left
.Data
(1 .. Left
.Current_Length
) < Right
;
253 (Left
: Wide_Wide_String
;
254 Right
: Super_String
) return Boolean
257 return Left
< Right
.Data
(1 .. Right
.Current_Length
);
264 function Less_Or_Equal
265 (Left
: Super_String
;
266 Right
: Super_String
) return Boolean
269 return Left
.Data
(1 .. Left
.Current_Length
) <=
270 Right
.Data
(1 .. Right
.Current_Length
);
273 function Less_Or_Equal
274 (Left
: Super_String
;
275 Right
: Wide_Wide_String
) return Boolean
278 return Left
.Data
(1 .. Left
.Current_Length
) <= Right
;
281 function Less_Or_Equal
282 (Left
: Wide_Wide_String
;
283 Right
: Super_String
) return Boolean
286 return Left
<= Right
.Data
(1 .. Right
.Current_Length
);
289 ----------------------
290 -- Set_Super_String --
291 ----------------------
293 procedure Set_Super_String
294 (Target
: out Super_String
;
295 Source
: Wide_Wide_String
;
296 Drop
: Truncation
:= Error
)
298 Slen
: constant Natural := Source
'Length;
299 Max_Length
: constant Positive := Target
.Max_Length
;
302 if Slen
<= Max_Length
then
303 Target
.Current_Length
:= Slen
;
304 Target
.Data
(1 .. Slen
) := Source
;
308 when Strings
.Right
=>
309 Target
.Current_Length
:= Max_Length
;
310 Target
.Data
(1 .. Max_Length
) :=
311 Source
(Source
'First .. Source
'First - 1 + Max_Length
);
314 Target
.Current_Length
:= Max_Length
;
315 Target
.Data
(1 .. Max_Length
) :=
316 Source
(Source
'Last - (Max_Length
- 1) .. Source
'Last);
318 when Strings
.Error
=>
319 raise Ada
.Strings
.Length_Error
;
322 end Set_Super_String
;
328 -- Case of Super_String and Super_String
330 function Super_Append
331 (Left
: Super_String
;
332 Right
: Super_String
;
333 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
335 Max_Length
: constant Positive := Left
.Max_Length
;
336 Result
: Super_String
(Max_Length
);
337 Llen
: constant Natural := Left
.Current_Length
;
338 Rlen
: constant Natural := Right
.Current_Length
;
339 Nlen
: constant Natural := Llen
+ Rlen
;
342 if Nlen
<= Max_Length
then
343 Result
.Current_Length
:= Nlen
;
344 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
345 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
.Data
(1 .. Rlen
);
348 Result
.Current_Length
:= Max_Length
;
351 when Strings
.Right
=>
352 if Llen
>= Max_Length
then -- only case is Llen = Max_Length
353 Result
.Data
:= Left
.Data
;
356 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
357 Result
.Data
(Llen
+ 1 .. Max_Length
) :=
358 Right
.Data
(1 .. Max_Length
- Llen
);
362 if Rlen
>= Max_Length
then -- only case is Rlen = Max_Length
363 Result
.Data
:= Right
.Data
;
366 Result
.Data
(1 .. Max_Length
- Rlen
) :=
367 Left
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
368 Result
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
369 Right
.Data
(1 .. Rlen
);
372 when Strings
.Error
=>
373 raise Ada
.Strings
.Length_Error
;
380 procedure Super_Append
381 (Source
: in out Super_String
;
382 New_Item
: Super_String
;
383 Drop
: Truncation
:= Error
)
385 Max_Length
: constant Positive := Source
.Max_Length
;
386 Llen
: constant Natural := Source
.Current_Length
;
387 Rlen
: constant Natural := New_Item
.Current_Length
;
388 Nlen
: constant Natural := Llen
+ Rlen
;
391 if Nlen
<= Max_Length
then
392 Source
.Current_Length
:= Nlen
;
393 Source
.Data
(Llen
+ 1 .. Nlen
) := New_Item
.Data
(1 .. Rlen
);
396 Source
.Current_Length
:= Max_Length
;
399 when Strings
.Right
=>
400 if Llen
< Max_Length
then
401 Source
.Data
(Llen
+ 1 .. Max_Length
) :=
402 New_Item
.Data
(1 .. Max_Length
- Llen
);
406 if Rlen
>= Max_Length
then -- only case is Rlen = Max_Length
407 Source
.Data
:= New_Item
.Data
;
410 Source
.Data
(1 .. Max_Length
- Rlen
) :=
411 Source
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
412 Source
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
413 New_Item
.Data
(1 .. Rlen
);
416 when Strings
.Error
=>
417 raise Ada
.Strings
.Length_Error
;
423 -- Case of Super_String and Wide_Wide_String
425 function Super_Append
426 (Left
: Super_String
;
427 Right
: Wide_Wide_String
;
428 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
430 Max_Length
: constant Positive := Left
.Max_Length
;
431 Result
: Super_String
(Max_Length
);
432 Llen
: constant Natural := Left
.Current_Length
;
433 Rlen
: constant Natural := Right
'Length;
434 Nlen
: constant Natural := Llen
+ Rlen
;
437 if Nlen
<= Max_Length
then
438 Result
.Current_Length
:= Nlen
;
439 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
440 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
;
443 Result
.Current_Length
:= Max_Length
;
446 when Strings
.Right
=>
447 if Llen
>= Max_Length
then -- only case is Llen = Max_Length
448 Result
.Data
:= Left
.Data
;
451 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
452 Result
.Data
(Llen
+ 1 .. Max_Length
) :=
453 Right
(Right
'First .. Right
'First - 1 +
459 if Rlen
>= Max_Length
then
460 Result
.Data
(1 .. Max_Length
) :=
461 Right
(Right
'Last - (Max_Length
- 1) .. Right
'Last);
464 Result
.Data
(1 .. Max_Length
- Rlen
) :=
465 Left
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
466 Result
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
470 when Strings
.Error
=>
471 raise Ada
.Strings
.Length_Error
;
478 procedure Super_Append
479 (Source
: in out Super_String
;
480 New_Item
: Wide_Wide_String
;
481 Drop
: Truncation
:= Error
)
483 Max_Length
: constant Positive := Source
.Max_Length
;
484 Llen
: constant Natural := Source
.Current_Length
;
485 Rlen
: constant Natural := New_Item
'Length;
486 Nlen
: constant Natural := Llen
+ Rlen
;
489 if Nlen
<= Max_Length
then
490 Source
.Current_Length
:= Nlen
;
491 Source
.Data
(Llen
+ 1 .. Nlen
) := New_Item
;
494 Source
.Current_Length
:= Max_Length
;
497 when Strings
.Right
=>
498 if Llen
< Max_Length
then
499 Source
.Data
(Llen
+ 1 .. Max_Length
) :=
500 New_Item
(New_Item
'First ..
501 New_Item
'First - 1 + Max_Length
- Llen
);
505 if Rlen
>= Max_Length
then
506 Source
.Data
(1 .. Max_Length
) :=
507 New_Item
(New_Item
'Last - (Max_Length
- 1) ..
511 Source
.Data
(1 .. Max_Length
- Rlen
) :=
512 Source
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
513 Source
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
517 when Strings
.Error
=>
518 raise Ada
.Strings
.Length_Error
;
524 -- Case of Wide_Wide_String and Super_String
526 function Super_Append
527 (Left
: Wide_Wide_String
;
528 Right
: Super_String
;
529 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
531 Max_Length
: constant Positive := Right
.Max_Length
;
532 Result
: Super_String
(Max_Length
);
533 Llen
: constant Natural := Left
'Length;
534 Rlen
: constant Natural := Right
.Current_Length
;
535 Nlen
: constant Natural := Llen
+ Rlen
;
538 if Nlen
<= Max_Length
then
539 Result
.Current_Length
:= Nlen
;
540 Result
.Data
(1 .. Llen
) := Left
;
541 Result
.Data
(Llen
+ 1 .. Llen
+ Rlen
) := Right
.Data
(1 .. Rlen
);
544 Result
.Current_Length
:= Max_Length
;
547 when Strings
.Right
=>
548 if Llen
>= Max_Length
then
549 Result
.Data
(1 .. Max_Length
) :=
550 Left
(Left
'First .. Left
'First + (Max_Length
- 1));
553 Result
.Data
(1 .. Llen
) := Left
;
554 Result
.Data
(Llen
+ 1 .. Max_Length
) :=
555 Right
.Data
(1 .. Max_Length
- Llen
);
559 if Rlen
>= Max_Length
then
560 Result
.Data
(1 .. Max_Length
) :=
561 Right
.Data
(Rlen
- (Max_Length
- 1) .. Rlen
);
564 Result
.Data
(1 .. Max_Length
- Rlen
) :=
565 Left
(Left
'Last - (Max_Length
- Rlen
- 1) .. Left
'Last);
566 Result
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
567 Right
.Data
(1 .. Rlen
);
570 when Strings
.Error
=>
571 raise Ada
.Strings
.Length_Error
;
578 -- Case of Super_String and Wide_Wide_Character
580 function Super_Append
581 (Left
: Super_String
;
582 Right
: Wide_Wide_Character
;
583 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
585 Max_Length
: constant Positive := Left
.Max_Length
;
586 Result
: Super_String
(Max_Length
);
587 Llen
: constant Natural := Left
.Current_Length
;
590 if Llen
< Max_Length
then
591 Result
.Current_Length
:= Llen
+ 1;
592 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
593 Result
.Data
(Llen
+ 1) := Right
;
598 when Strings
.Right
=>
602 Result
.Current_Length
:= Max_Length
;
603 Result
.Data
(1 .. Max_Length
- 1) :=
604 Left
.Data
(2 .. Max_Length
);
605 Result
.Data
(Max_Length
) := Right
;
608 when Strings
.Error
=>
609 raise Ada
.Strings
.Length_Error
;
614 procedure Super_Append
615 (Source
: in out Super_String
;
616 New_Item
: Wide_Wide_Character
;
617 Drop
: Truncation
:= Error
)
619 Max_Length
: constant Positive := Source
.Max_Length
;
620 Llen
: constant Natural := Source
.Current_Length
;
623 if Llen
< Max_Length
then
624 Source
.Current_Length
:= Llen
+ 1;
625 Source
.Data
(Llen
+ 1) := New_Item
;
628 Source
.Current_Length
:= Max_Length
;
631 when Strings
.Right
=>
635 Source
.Data
(1 .. Max_Length
- 1) :=
636 Source
.Data
(2 .. Max_Length
);
637 Source
.Data
(Max_Length
) := New_Item
;
639 when Strings
.Error
=>
640 raise Ada
.Strings
.Length_Error
;
646 -- Case of Wide_Wide_Character and Super_String
648 function Super_Append
649 (Left
: Wide_Wide_Character
;
650 Right
: Super_String
;
651 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
653 Max_Length
: constant Positive := Right
.Max_Length
;
654 Result
: Super_String
(Max_Length
);
655 Rlen
: constant Natural := Right
.Current_Length
;
658 if Rlen
< Max_Length
then
659 Result
.Current_Length
:= Rlen
+ 1;
660 Result
.Data
(1) := Left
;
661 Result
.Data
(2 .. Rlen
+ 1) := Right
.Data
(1 .. Rlen
);
666 when Strings
.Right
=>
667 Result
.Current_Length
:= Max_Length
;
668 Result
.Data
(1) := Left
;
669 Result
.Data
(2 .. Max_Length
) :=
670 Right
.Data
(1 .. Max_Length
- 1);
676 when Strings
.Error
=>
677 raise Ada
.Strings
.Length_Error
;
687 (Source
: Super_String
;
688 Pattern
: Wide_Wide_String
;
689 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
690 Wide_Wide_Maps
.Identity
)
695 Wide_Wide_Search
.Count
696 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Mapping
);
700 (Source
: Super_String
;
701 Pattern
: Wide_Wide_String
;
702 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
707 Wide_Wide_Search
.Count
708 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Mapping
);
712 (Source
: Super_String
;
713 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
) return Natural
716 return Wide_Wide_Search
.Count
717 (Source
.Data
(1 .. Source
.Current_Length
), Set
);
724 function Super_Delete
725 (Source
: Super_String
;
727 Through
: Natural) return Super_String
729 Result
: Super_String
(Source
.Max_Length
);
730 Slen
: constant Natural := Source
.Current_Length
;
731 Num_Delete
: constant Integer := Through
- From
+ 1;
734 if Num_Delete
<= 0 then
737 elsif From
> Slen
+ 1 then
738 raise Ada
.Strings
.Index_Error
;
740 elsif Through
>= Slen
then
741 Result
.Current_Length
:= From
- 1;
742 Result
.Data
(1 .. From
- 1) := Source
.Data
(1 .. From
- 1);
746 Result
.Current_Length
:= Slen
- Num_Delete
;
747 Result
.Data
(1 .. From
- 1) := Source
.Data
(1 .. From
- 1);
748 Result
.Data
(From
.. Result
.Current_Length
) :=
749 Source
.Data
(Through
+ 1 .. Slen
);
754 procedure Super_Delete
755 (Source
: in out Super_String
;
759 Slen
: constant Natural := Source
.Current_Length
;
760 Num_Delete
: constant Integer := Through
- From
+ 1;
763 if Num_Delete
<= 0 then
766 elsif From
> Slen
+ 1 then
767 raise Ada
.Strings
.Index_Error
;
769 elsif Through
>= Slen
then
770 Source
.Current_Length
:= From
- 1;
773 Source
.Current_Length
:= Slen
- Num_Delete
;
774 Source
.Data
(From
.. Source
.Current_Length
) :=
775 Source
.Data
(Through
+ 1 .. Slen
);
783 function Super_Element
784 (Source
: Super_String
;
785 Index
: Positive) return Wide_Wide_Character
788 if Index
<= Source
.Current_Length
then
789 return Source
.Data
(Index
);
791 raise Strings
.Index_Error
;
795 ----------------------
796 -- Super_Find_Token --
797 ----------------------
799 procedure Super_Find_Token
800 (Source
: Super_String
;
801 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
802 Test
: Strings
.Membership
;
803 First
: out Positive;
807 Wide_Wide_Search
.Find_Token
808 (Source
.Data
(1 .. Source
.Current_Length
), Set
, Test
, First
, Last
);
809 end Super_Find_Token
;
816 (Source
: Super_String
;
818 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
819 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
821 Max_Length
: constant Positive := Source
.Max_Length
;
822 Result
: Super_String
(Max_Length
);
823 Slen
: constant Natural := Source
.Current_Length
;
824 Npad
: constant Integer := Count
- Slen
;
828 Result
.Current_Length
:= Count
;
829 Result
.Data
(1 .. Count
) := Source
.Data
(1 .. Count
);
831 elsif Count
<= Max_Length
then
832 Result
.Current_Length
:= Count
;
833 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
834 Result
.Data
(Slen
+ 1 .. Count
) := (others => Pad
);
837 Result
.Current_Length
:= Max_Length
;
840 when Strings
.Right
=>
841 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
842 Result
.Data
(Slen
+ 1 .. Max_Length
) := (others => Pad
);
845 if Npad
>= Max_Length
then
846 Result
.Data
:= (others => Pad
);
849 Result
.Data
(1 .. Max_Length
- Npad
) :=
850 Source
.Data
(Count
- Max_Length
+ 1 .. Slen
);
851 Result
.Data
(Max_Length
- Npad
+ 1 .. Max_Length
) :=
855 when Strings
.Error
=>
856 raise Ada
.Strings
.Length_Error
;
864 (Source
: in out Super_String
;
866 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
867 Drop
: Truncation
:= Error
)
869 Max_Length
: constant Positive := Source
.Max_Length
;
870 Slen
: constant Natural := Source
.Current_Length
;
871 Npad
: constant Integer := Count
- Slen
;
872 Temp
: Wide_Wide_String
(1 .. Max_Length
);
876 Source
.Current_Length
:= Count
;
878 elsif Count
<= Max_Length
then
879 Source
.Current_Length
:= Count
;
880 Source
.Data
(Slen
+ 1 .. Count
) := (others => Pad
);
883 Source
.Current_Length
:= Max_Length
;
886 when Strings
.Right
=>
887 Source
.Data
(Slen
+ 1 .. Max_Length
) := (others => Pad
);
890 if Npad
> Max_Length
then
891 Source
.Data
:= (others => Pad
);
895 Source
.Data
(1 .. Max_Length
- Npad
) :=
896 Temp
(Count
- Max_Length
+ 1 .. Slen
);
898 for J
in Max_Length
- Npad
+ 1 .. Max_Length
loop
899 Source
.Data
(J
) := Pad
;
903 when Strings
.Error
=>
904 raise Ada
.Strings
.Length_Error
;
914 (Source
: Super_String
;
915 Pattern
: Wide_Wide_String
;
916 Going
: Strings
.Direction
:= Strings
.Forward
;
917 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
918 Wide_Wide_Maps
.Identity
)
922 return Wide_Wide_Search
.Index
923 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Going
, Mapping
);
927 (Source
: Super_String
;
928 Pattern
: Wide_Wide_String
;
929 Going
: Direction
:= Forward
;
930 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
934 return Wide_Wide_Search
.Index
935 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Going
, Mapping
);
939 (Source
: Super_String
;
940 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
941 Test
: Strings
.Membership
:= Strings
.Inside
;
942 Going
: Strings
.Direction
:= Strings
.Forward
) return Natural
945 return Wide_Wide_Search
.Index
946 (Source
.Data
(1 .. Source
.Current_Length
), Set
, Test
, Going
);
950 (Source
: Super_String
;
951 Pattern
: Wide_Wide_String
;
953 Going
: Direction
:= Forward
;
954 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
955 Wide_Wide_Maps
.Identity
)
959 return Wide_Wide_Search
.Index
960 (Source
.Data
(1 .. Source
.Current_Length
),
961 Pattern
, From
, Going
, Mapping
);
965 (Source
: Super_String
;
966 Pattern
: Wide_Wide_String
;
968 Going
: Direction
:= Forward
;
969 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
973 return Wide_Wide_Search
.Index
974 (Source
.Data
(1 .. Source
.Current_Length
),
975 Pattern
, From
, Going
, Mapping
);
979 (Source
: Super_String
;
980 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
982 Test
: Membership
:= Inside
;
983 Going
: Direction
:= Forward
) return Natural
986 return Wide_Wide_Search
.Index
987 (Source
.Data
(1 .. Source
.Current_Length
), Set
, From
, Test
, Going
);
990 ---------------------------
991 -- Super_Index_Non_Blank --
992 ---------------------------
994 function Super_Index_Non_Blank
995 (Source
: Super_String
;
996 Going
: Strings
.Direction
:= Strings
.Forward
) return Natural
1000 Wide_Wide_Search
.Index_Non_Blank
1001 (Source
.Data
(1 .. Source
.Current_Length
), Going
);
1002 end Super_Index_Non_Blank
;
1004 function Super_Index_Non_Blank
1005 (Source
: Super_String
;
1007 Going
: Direction
:= Forward
) return Natural
1011 Wide_Wide_Search
.Index_Non_Blank
1012 (Source
.Data
(1 .. Source
.Current_Length
), From
, Going
);
1013 end Super_Index_Non_Blank
;
1019 function Super_Insert
1020 (Source
: Super_String
;
1022 New_Item
: Wide_Wide_String
;
1023 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1025 Max_Length
: constant Positive := Source
.Max_Length
;
1026 Result
: Super_String
(Max_Length
);
1027 Slen
: constant Natural := Source
.Current_Length
;
1028 Nlen
: constant Natural := New_Item
'Length;
1029 Tlen
: constant Natural := Slen
+ Nlen
;
1030 Blen
: constant Natural := Before
- 1;
1031 Alen
: constant Integer := Slen
- Blen
;
1032 Droplen
: constant Integer := Tlen
- Max_Length
;
1034 -- Tlen is the length of the total string before possible truncation.
1035 -- Blen, Alen are the lengths of the before and after pieces of the
1040 raise Ada
.Strings
.Index_Error
;
1042 elsif Droplen
<= 0 then
1043 Result
.Current_Length
:= Tlen
;
1044 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1045 Result
.Data
(Before
.. Before
+ Nlen
- 1) := New_Item
;
1046 Result
.Data
(Before
+ Nlen
.. Tlen
) :=
1047 Source
.Data
(Before
.. Slen
);
1050 Result
.Current_Length
:= Max_Length
;
1053 when Strings
.Right
=>
1054 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1056 if Droplen
> Alen
then
1057 Result
.Data
(Before
.. Max_Length
) :=
1058 New_Item
(New_Item
'First
1059 .. New_Item
'First + Max_Length
- Before
);
1061 Result
.Data
(Before
.. Before
+ Nlen
- 1) := New_Item
;
1062 Result
.Data
(Before
+ Nlen
.. Max_Length
) :=
1063 Source
.Data
(Before
.. Slen
- Droplen
);
1066 when Strings
.Left
=>
1067 Result
.Data
(Max_Length
- (Alen
- 1) .. Max_Length
) :=
1068 Source
.Data
(Before
.. Slen
);
1070 if Droplen
>= Blen
then
1071 Result
.Data
(1 .. Max_Length
- Alen
) :=
1072 New_Item
(New_Item
'Last - (Max_Length
- Alen
) + 1
1076 (Blen
- Droplen
+ 1 .. Max_Length
- Alen
) :=
1078 Result
.Data
(1 .. Blen
- Droplen
) :=
1079 Source
.Data
(Droplen
+ 1 .. Blen
);
1082 when Strings
.Error
=>
1083 raise Ada
.Strings
.Length_Error
;
1090 procedure Super_Insert
1091 (Source
: in out Super_String
;
1093 New_Item
: Wide_Wide_String
;
1094 Drop
: Strings
.Truncation
:= Strings
.Error
)
1097 -- We do a double copy here because this is one of the situations
1098 -- in which we move data to the right, and at least at the moment,
1099 -- GNAT is not handling such cases correctly ???
1101 Source
:= Super_Insert
(Source
, Before
, New_Item
, Drop
);
1108 function Super_Length
(Source
: Super_String
) return Natural is
1110 return Source
.Current_Length
;
1113 ---------------------
1114 -- Super_Overwrite --
1115 ---------------------
1117 function Super_Overwrite
1118 (Source
: Super_String
;
1119 Position
: Positive;
1120 New_Item
: Wide_Wide_String
;
1121 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1123 Max_Length
: constant Positive := Source
.Max_Length
;
1124 Result
: Super_String
(Max_Length
);
1125 Endpos
: constant Natural := Position
+ New_Item
'Length - 1;
1126 Slen
: constant Natural := Source
.Current_Length
;
1130 if Position
> Slen
+ 1 then
1131 raise Ada
.Strings
.Index_Error
;
1133 elsif New_Item
'Length = 0 then
1136 elsif Endpos
<= Slen
then
1137 Result
.Current_Length
:= Source
.Current_Length
;
1138 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
1139 Result
.Data
(Position
.. Endpos
) := New_Item
;
1142 elsif Endpos
<= Max_Length
then
1143 Result
.Current_Length
:= Endpos
;
1144 Result
.Data
(1 .. Position
- 1) := Source
.Data
(1 .. Position
- 1);
1145 Result
.Data
(Position
.. Endpos
) := New_Item
;
1149 Result
.Current_Length
:= Max_Length
;
1150 Droplen
:= Endpos
- Max_Length
;
1153 when Strings
.Right
=>
1154 Result
.Data
(1 .. Position
- 1) :=
1155 Source
.Data
(1 .. Position
- 1);
1157 Result
.Data
(Position
.. Max_Length
) :=
1158 New_Item
(New_Item
'First .. New_Item
'Last - Droplen
);
1161 when Strings
.Left
=>
1162 if New_Item
'Length >= Max_Length
then
1163 Result
.Data
(1 .. Max_Length
) :=
1164 New_Item
(New_Item
'Last - Max_Length
+ 1 ..
1169 Result
.Data
(1 .. Max_Length
- New_Item
'Length) :=
1170 Source
.Data
(Droplen
+ 1 .. Position
- 1);
1172 (Max_Length
- New_Item
'Length + 1 .. Max_Length
) :=
1177 when Strings
.Error
=>
1178 raise Ada
.Strings
.Length_Error
;
1181 end Super_Overwrite
;
1183 procedure Super_Overwrite
1184 (Source
: in out Super_String
;
1185 Position
: Positive;
1186 New_Item
: Wide_Wide_String
;
1187 Drop
: Strings
.Truncation
:= Strings
.Error
)
1189 Max_Length
: constant Positive := Source
.Max_Length
;
1190 Endpos
: constant Positive := Position
+ New_Item
'Length - 1;
1191 Slen
: constant Natural := Source
.Current_Length
;
1195 if Position
> Slen
+ 1 then
1196 raise Ada
.Strings
.Index_Error
;
1198 elsif Endpos
<= Slen
then
1199 Source
.Data
(Position
.. Endpos
) := New_Item
;
1201 elsif Endpos
<= Max_Length
then
1202 Source
.Data
(Position
.. Endpos
) := New_Item
;
1203 Source
.Current_Length
:= Endpos
;
1206 Source
.Current_Length
:= Max_Length
;
1207 Droplen
:= Endpos
- Max_Length
;
1210 when Strings
.Right
=>
1211 Source
.Data
(Position
.. Max_Length
) :=
1212 New_Item
(New_Item
'First .. New_Item
'Last - Droplen
);
1214 when Strings
.Left
=>
1215 if New_Item
'Length > Max_Length
then
1216 Source
.Data
(1 .. Max_Length
) :=
1217 New_Item
(New_Item
'Last - Max_Length
+ 1 ..
1221 Source
.Data
(1 .. Max_Length
- New_Item
'Length) :=
1222 Source
.Data
(Droplen
+ 1 .. Position
- 1);
1225 (Max_Length
- New_Item
'Length + 1 .. Max_Length
) :=
1229 when Strings
.Error
=>
1230 raise Ada
.Strings
.Length_Error
;
1233 end Super_Overwrite
;
1235 ---------------------------
1236 -- Super_Replace_Element --
1237 ---------------------------
1239 procedure Super_Replace_Element
1240 (Source
: in out Super_String
;
1242 By
: Wide_Wide_Character
)
1245 if Index
<= Source
.Current_Length
then
1246 Source
.Data
(Index
) := By
;
1248 raise Ada
.Strings
.Index_Error
;
1250 end Super_Replace_Element
;
1252 -------------------------
1253 -- Super_Replace_Slice --
1254 -------------------------
1256 function Super_Replace_Slice
1257 (Source
: Super_String
;
1260 By
: Wide_Wide_String
;
1261 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1263 Max_Length
: constant Positive := Source
.Max_Length
;
1264 Slen
: constant Natural := Source
.Current_Length
;
1267 if Low
> Slen
+ 1 then
1268 raise Strings
.Index_Error
;
1270 elsif High
< Low
then
1271 return Super_Insert
(Source
, Low
, By
, Drop
);
1275 Blen
: constant Natural := Natural'Max (0, Low
- 1);
1276 Alen
: constant Natural := Natural'Max (0, Slen
- High
);
1277 Tlen
: constant Natural := Blen
+ By
'Length + Alen
;
1278 Droplen
: constant Integer := Tlen
- Max_Length
;
1279 Result
: Super_String
(Max_Length
);
1281 -- Tlen is the total length of the result string before any
1282 -- truncation. Blen and Alen are the lengths of the pieces
1283 -- of the original string that end up in the result string
1284 -- before and after the replaced slice.
1287 if Droplen
<= 0 then
1288 Result
.Current_Length
:= Tlen
;
1289 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1290 Result
.Data
(Low
.. Low
+ By
'Length - 1) := By
;
1291 Result
.Data
(Low
+ By
'Length .. Tlen
) :=
1292 Source
.Data
(High
+ 1 .. Slen
);
1295 Result
.Current_Length
:= Max_Length
;
1298 when Strings
.Right
=>
1299 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1301 if Droplen
> Alen
then
1302 Result
.Data
(Low
.. Max_Length
) :=
1303 By
(By
'First .. By
'First + Max_Length
- Low
);
1305 Result
.Data
(Low
.. Low
+ By
'Length - 1) := By
;
1306 Result
.Data
(Low
+ By
'Length .. Max_Length
) :=
1307 Source
.Data
(High
+ 1 .. Slen
- Droplen
);
1310 when Strings
.Left
=>
1311 Result
.Data
(Max_Length
- (Alen
- 1) .. Max_Length
) :=
1312 Source
.Data
(High
+ 1 .. Slen
);
1314 if Droplen
>= Blen
then
1315 Result
.Data
(1 .. Max_Length
- Alen
) :=
1316 By
(By
'Last - (Max_Length
- Alen
) + 1 .. By
'Last);
1319 (Blen
- Droplen
+ 1 .. Max_Length
- Alen
) := By
;
1320 Result
.Data
(1 .. Blen
- Droplen
) :=
1321 Source
.Data
(Droplen
+ 1 .. Blen
);
1324 when Strings
.Error
=>
1325 raise Ada
.Strings
.Length_Error
;
1332 end Super_Replace_Slice
;
1334 procedure Super_Replace_Slice
1335 (Source
: in out Super_String
;
1338 By
: Wide_Wide_String
;
1339 Drop
: Strings
.Truncation
:= Strings
.Error
)
1342 -- We do a double copy here because this is one of the situations
1343 -- in which we move data to the right, and at least at the moment,
1344 -- GNAT is not handling such cases correctly ???
1346 Source
:= Super_Replace_Slice
(Source
, Low
, High
, By
, Drop
);
1347 end Super_Replace_Slice
;
1349 ---------------------
1350 -- Super_Replicate --
1351 ---------------------
1353 function Super_Replicate
1355 Item
: Wide_Wide_Character
;
1356 Drop
: Truncation
:= Error
;
1357 Max_Length
: Positive) return Super_String
1359 Result
: Super_String
(Max_Length
);
1362 if Count
<= Max_Length
then
1363 Result
.Current_Length
:= Count
;
1365 elsif Drop
= Strings
.Error
then
1366 raise Ada
.Strings
.Length_Error
;
1369 Result
.Current_Length
:= Max_Length
;
1372 Result
.Data
(1 .. Result
.Current_Length
) := (others => Item
);
1374 end Super_Replicate
;
1376 function Super_Replicate
1378 Item
: Wide_Wide_String
;
1379 Drop
: Truncation
:= Error
;
1380 Max_Length
: Positive) return Super_String
1382 Length
: constant Integer := Count
* Item
'Length;
1383 Result
: Super_String
(Max_Length
);
1387 if Length
<= Max_Length
then
1388 Result
.Current_Length
:= Length
;
1393 for J
in 1 .. Count
loop
1394 Result
.Data
(Indx
.. Indx
+ Item
'Length - 1) := Item
;
1395 Indx
:= Indx
+ Item
'Length;
1400 Result
.Current_Length
:= Max_Length
;
1403 when Strings
.Right
=>
1406 while Indx
+ Item
'Length <= Max_Length
+ 1 loop
1407 Result
.Data
(Indx
.. Indx
+ Item
'Length - 1) := Item
;
1408 Indx
:= Indx
+ Item
'Length;
1411 Result
.Data
(Indx
.. Max_Length
) :=
1412 Item
(Item
'First .. Item
'First + Max_Length
- Indx
);
1414 when Strings
.Left
=>
1417 while Indx
- Item
'Length >= 1 loop
1418 Result
.Data
(Indx
- (Item
'Length - 1) .. Indx
) := Item
;
1419 Indx
:= Indx
- Item
'Length;
1422 Result
.Data
(1 .. Indx
) :=
1423 Item
(Item
'Last - Indx
+ 1 .. Item
'Last);
1425 when Strings
.Error
=>
1426 raise Ada
.Strings
.Length_Error
;
1431 end Super_Replicate
;
1433 function Super_Replicate
1435 Item
: Super_String
;
1436 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1442 Item
.Data
(1 .. Item
.Current_Length
),
1445 end Super_Replicate
;
1451 function Super_Slice
1452 (Source
: Super_String
;
1454 High
: Natural) return Wide_Wide_String
1457 -- Note: test of High > Length is in accordance with AI95-00128
1459 if Low
> Source
.Current_Length
+ 1
1460 or else High
> Source
.Current_Length
1464 return Source
.Data
(Low
.. High
);
1468 function Super_Slice
1469 (Source
: Super_String
;
1471 High
: Natural) return Super_String
1473 Result
: Super_String
(Source
.Max_Length
);
1476 if Low
> Source
.Current_Length
+ 1
1477 or else High
> Source
.Current_Length
1481 Result
.Current_Length
:= High
- Low
+ 1;
1482 Result
.Data
(1 .. Result
.Current_Length
) := Source
.Data
(Low
.. High
);
1488 procedure Super_Slice
1489 (Source
: Super_String
;
1490 Target
: out Super_String
;
1495 if Low
> Source
.Current_Length
+ 1
1496 or else High
> Source
.Current_Length
1500 Target
.Current_Length
:= High
- Low
+ 1;
1501 Target
.Data
(1 .. Target
.Current_Length
) := Source
.Data
(Low
.. High
);
1510 (Source
: Super_String
;
1512 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
1513 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1515 Max_Length
: constant Positive := Source
.Max_Length
;
1516 Result
: Super_String
(Max_Length
);
1517 Slen
: constant Natural := Source
.Current_Length
;
1518 Npad
: constant Integer := Count
- Slen
;
1522 Result
.Current_Length
:= Count
;
1523 Result
.Data
(1 .. Count
) :=
1524 Source
.Data
(Slen
- (Count
- 1) .. Slen
);
1526 elsif Count
<= Max_Length
then
1527 Result
.Current_Length
:= Count
;
1528 Result
.Data
(1 .. Npad
) := (others => Pad
);
1529 Result
.Data
(Npad
+ 1 .. Count
) := Source
.Data
(1 .. Slen
);
1532 Result
.Current_Length
:= Max_Length
;
1535 when Strings
.Right
=>
1536 if Npad
>= Max_Length
then
1537 Result
.Data
:= (others => Pad
);
1540 Result
.Data
(1 .. Npad
) := (others => Pad
);
1541 Result
.Data
(Npad
+ 1 .. Max_Length
) :=
1542 Source
.Data
(1 .. Max_Length
- Npad
);
1545 when Strings
.Left
=>
1546 Result
.Data
(1 .. Max_Length
- Slen
) := (others => Pad
);
1547 Result
.Data
(Max_Length
- Slen
+ 1 .. Max_Length
) :=
1548 Source
.Data
(1 .. Slen
);
1550 when Strings
.Error
=>
1551 raise Ada
.Strings
.Length_Error
;
1558 procedure Super_Tail
1559 (Source
: in out Super_String
;
1561 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
1562 Drop
: Truncation
:= Error
)
1564 Max_Length
: constant Positive := Source
.Max_Length
;
1565 Slen
: constant Natural := Source
.Current_Length
;
1566 Npad
: constant Integer := Count
- Slen
;
1568 Temp
: constant Wide_Wide_String
(1 .. Max_Length
) := Source
.Data
;
1572 Source
.Current_Length
:= Count
;
1573 Source
.Data
(1 .. Count
) :=
1574 Temp
(Slen
- (Count
- 1) .. Slen
);
1576 elsif Count
<= Max_Length
then
1577 Source
.Current_Length
:= Count
;
1578 Source
.Data
(1 .. Npad
) := (others => Pad
);
1579 Source
.Data
(Npad
+ 1 .. Count
) := Temp
(1 .. Slen
);
1582 Source
.Current_Length
:= Max_Length
;
1585 when Strings
.Right
=>
1586 if Npad
>= Max_Length
then
1587 Source
.Data
:= (others => Pad
);
1590 Source
.Data
(1 .. Npad
) := (others => Pad
);
1591 Source
.Data
(Npad
+ 1 .. Max_Length
) :=
1592 Temp
(1 .. Max_Length
- Npad
);
1595 when Strings
.Left
=>
1596 for J
in 1 .. Max_Length
- Slen
loop
1597 Source
.Data
(J
) := Pad
;
1600 Source
.Data
(Max_Length
- Slen
+ 1 .. Max_Length
) :=
1603 when Strings
.Error
=>
1604 raise Ada
.Strings
.Length_Error
;
1609 ---------------------
1610 -- Super_To_String --
1611 ---------------------
1613 function Super_To_String
1614 (Source
: Super_String
) return Wide_Wide_String
1617 return Source
.Data
(1 .. Source
.Current_Length
);
1618 end Super_To_String
;
1620 ---------------------
1621 -- Super_Translate --
1622 ---------------------
1624 function Super_Translate
1625 (Source
: Super_String
;
1626 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
)
1629 Result
: Super_String
(Source
.Max_Length
);
1632 Result
.Current_Length
:= Source
.Current_Length
;
1634 for J
in 1 .. Source
.Current_Length
loop
1635 Result
.Data
(J
) := Value
(Mapping
, Source
.Data
(J
));
1639 end Super_Translate
;
1641 procedure Super_Translate
1642 (Source
: in out Super_String
;
1643 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
)
1646 for J
in 1 .. Source
.Current_Length
loop
1647 Source
.Data
(J
) := Value
(Mapping
, Source
.Data
(J
));
1649 end Super_Translate
;
1651 function Super_Translate
1652 (Source
: Super_String
;
1653 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
1656 Result
: Super_String
(Source
.Max_Length
);
1659 Result
.Current_Length
:= Source
.Current_Length
;
1661 for J
in 1 .. Source
.Current_Length
loop
1662 Result
.Data
(J
) := Mapping
.all (Source
.Data
(J
));
1666 end Super_Translate
;
1668 procedure Super_Translate
1669 (Source
: in out Super_String
;
1670 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
1673 for J
in 1 .. Source
.Current_Length
loop
1674 Source
.Data
(J
) := Mapping
.all (Source
.Data
(J
));
1676 end Super_Translate
;
1683 (Source
: Super_String
;
1684 Side
: Trim_End
) return Super_String
1686 Result
: Super_String
(Source
.Max_Length
);
1687 Last
: Natural := Source
.Current_Length
;
1688 First
: Positive := 1;
1691 if Side
= Left
or else Side
= Both
then
1692 while First
<= Last
and then Source
.Data
(First
) = ' ' loop
1697 if Side
= Right
or else Side
= Both
then
1698 while Last
>= First
and then Source
.Data
(Last
) = ' ' loop
1703 Result
.Current_Length
:= Last
- First
+ 1;
1704 Result
.Data
(1 .. Result
.Current_Length
) := Source
.Data
(First
.. Last
);
1708 procedure Super_Trim
1709 (Source
: in out Super_String
;
1712 Max_Length
: constant Positive := Source
.Max_Length
;
1713 Last
: Natural := Source
.Current_Length
;
1714 First
: Positive := 1;
1715 Temp
: Wide_Wide_String
(1 .. Max_Length
);
1718 Temp
(1 .. Last
) := Source
.Data
(1 .. Last
);
1720 if Side
= Left
or else Side
= Both
then
1721 while First
<= Last
and then Temp
(First
) = ' ' loop
1726 if Side
= Right
or else Side
= Both
then
1727 while Last
>= First
and then Temp
(Last
) = ' ' loop
1732 Source
.Data
:= (others => Wide_Wide_NUL
);
1733 Source
.Current_Length
:= Last
- First
+ 1;
1734 Source
.Data
(1 .. Source
.Current_Length
) := Temp
(First
.. Last
);
1738 (Source
: Super_String
;
1739 Left
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
1740 Right
: Wide_Wide_Maps
.Wide_Wide_Character_Set
) return Super_String
1742 Result
: Super_String
(Source
.Max_Length
);
1745 for First
in 1 .. Source
.Current_Length
loop
1746 if not Is_In
(Source
.Data
(First
), Left
) then
1747 for Last
in reverse First
.. Source
.Current_Length
loop
1748 if not Is_In
(Source
.Data
(Last
), Right
) then
1749 Result
.Current_Length
:= Last
- First
+ 1;
1750 Result
.Data
(1 .. Result
.Current_Length
) :=
1751 Source
.Data
(First
.. Last
);
1758 Result
.Current_Length
:= 0;
1762 procedure Super_Trim
1763 (Source
: in out Super_String
;
1764 Left
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
1765 Right
: Wide_Wide_Maps
.Wide_Wide_Character_Set
)
1768 for First
in 1 .. Source
.Current_Length
loop
1769 if not Is_In
(Source
.Data
(First
), Left
) then
1770 for Last
in reverse First
.. Source
.Current_Length
loop
1771 if not Is_In
(Source
.Data
(Last
), Right
) then
1773 Source
.Current_Length
:= Last
;
1776 Source
.Current_Length
:= Last
- First
+ 1;
1777 Source
.Data
(1 .. Source
.Current_Length
) :=
1778 Source
.Data
(First
.. Last
);
1780 for J
in Source
.Current_Length
+ 1 ..
1783 Source
.Data
(J
) := Wide_Wide_NUL
;
1791 Source
.Current_Length
:= 0;
1796 Source
.Current_Length
:= 0;
1805 Right
: Wide_Wide_Character
;
1806 Max_Length
: Positive) return Super_String
1808 Result
: Super_String
(Max_Length
);
1811 if Left
> Max_Length
then
1812 raise Ada
.Strings
.Length_Error
;
1815 Result
.Current_Length
:= Left
;
1817 for J
in 1 .. Left
loop
1818 Result
.Data
(J
) := Right
;
1827 Right
: Wide_Wide_String
;
1828 Max_Length
: Positive) return Super_String
1830 Result
: Super_String
(Max_Length
);
1831 Pos
: Positive := 1;
1832 Rlen
: constant Natural := Right
'Length;
1833 Nlen
: constant Natural := Left
* Rlen
;
1836 if Nlen
> Max_Length
then
1837 raise Ada
.Strings
.Index_Error
;
1840 Result
.Current_Length
:= Nlen
;
1843 for J
in 1 .. Left
loop
1844 Result
.Data
(Pos
.. Pos
+ Rlen
- 1) := Right
;
1855 Right
: Super_String
) return Super_String
1857 Result
: Super_String
(Right
.Max_Length
);
1858 Pos
: Positive := 1;
1859 Rlen
: constant Natural := Right
.Current_Length
;
1860 Nlen
: constant Natural := Left
* Rlen
;
1863 if Nlen
> Right
.Max_Length
then
1864 raise Ada
.Strings
.Length_Error
;
1867 Result
.Current_Length
:= Nlen
;
1870 for J
in 1 .. Left
loop
1871 Result
.Data
(Pos
.. Pos
+ Rlen
- 1) :=
1872 Right
.Data
(1 .. Rlen
);
1881 ---------------------
1882 -- To_Super_String --
1883 ---------------------
1885 function To_Super_String
1886 (Source
: Wide_Wide_String
;
1887 Max_Length
: Natural;
1888 Drop
: Truncation
:= Error
) return Super_String
1890 Result
: Super_String
(Max_Length
);
1891 Slen
: constant Natural := Source
'Length;
1894 if Slen
<= Max_Length
then
1895 Result
.Current_Length
:= Slen
;
1896 Result
.Data
(1 .. Slen
) := Source
;
1900 when Strings
.Right
=>
1901 Result
.Current_Length
:= Max_Length
;
1902 Result
.Data
(1 .. Max_Length
) :=
1903 Source
(Source
'First .. Source
'First - 1 + Max_Length
);
1905 when Strings
.Left
=>
1906 Result
.Current_Length
:= Max_Length
;
1907 Result
.Data
(1 .. Max_Length
) :=
1908 Source
(Source
'Last - (Max_Length
- 1) .. Source
'Last);
1910 when Strings
.Error
=>
1911 raise Ada
.Strings
.Length_Error
;
1916 end To_Super_String
;
1918 end Ada
.Strings
.Wide_Wide_Superbounded
;