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-2010, 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
;
803 Test
: Strings
.Membership
;
804 First
: out Positive;
808 Wide_Wide_Search
.Find_Token
809 (Source
.Data
(From
.. Source
.Current_Length
), Set
, Test
, First
, Last
);
810 end Super_Find_Token
;
812 procedure Super_Find_Token
813 (Source
: Super_String
;
814 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
815 Test
: Strings
.Membership
;
816 First
: out Positive;
820 Wide_Wide_Search
.Find_Token
821 (Source
.Data
(1 .. Source
.Current_Length
), Set
, Test
, First
, Last
);
822 end Super_Find_Token
;
829 (Source
: Super_String
;
831 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
832 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
834 Max_Length
: constant Positive := Source
.Max_Length
;
835 Result
: Super_String
(Max_Length
);
836 Slen
: constant Natural := Source
.Current_Length
;
837 Npad
: constant Integer := Count
- Slen
;
841 Result
.Current_Length
:= Count
;
842 Result
.Data
(1 .. Count
) := Source
.Data
(1 .. Count
);
844 elsif Count
<= Max_Length
then
845 Result
.Current_Length
:= Count
;
846 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
847 Result
.Data
(Slen
+ 1 .. Count
) := (others => Pad
);
850 Result
.Current_Length
:= Max_Length
;
853 when Strings
.Right
=>
854 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
855 Result
.Data
(Slen
+ 1 .. Max_Length
) := (others => Pad
);
858 if Npad
>= Max_Length
then
859 Result
.Data
:= (others => Pad
);
862 Result
.Data
(1 .. Max_Length
- Npad
) :=
863 Source
.Data
(Count
- Max_Length
+ 1 .. Slen
);
864 Result
.Data
(Max_Length
- Npad
+ 1 .. Max_Length
) :=
868 when Strings
.Error
=>
869 raise Ada
.Strings
.Length_Error
;
877 (Source
: in out Super_String
;
879 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
880 Drop
: Truncation
:= Error
)
882 Max_Length
: constant Positive := Source
.Max_Length
;
883 Slen
: constant Natural := Source
.Current_Length
;
884 Npad
: constant Integer := Count
- Slen
;
885 Temp
: Wide_Wide_String
(1 .. Max_Length
);
889 Source
.Current_Length
:= Count
;
891 elsif Count
<= Max_Length
then
892 Source
.Current_Length
:= Count
;
893 Source
.Data
(Slen
+ 1 .. Count
) := (others => Pad
);
896 Source
.Current_Length
:= Max_Length
;
899 when Strings
.Right
=>
900 Source
.Data
(Slen
+ 1 .. Max_Length
) := (others => Pad
);
903 if Npad
> Max_Length
then
904 Source
.Data
:= (others => Pad
);
908 Source
.Data
(1 .. Max_Length
- Npad
) :=
909 Temp
(Count
- Max_Length
+ 1 .. Slen
);
911 for J
in Max_Length
- Npad
+ 1 .. Max_Length
loop
912 Source
.Data
(J
) := Pad
;
916 when Strings
.Error
=>
917 raise Ada
.Strings
.Length_Error
;
927 (Source
: Super_String
;
928 Pattern
: Wide_Wide_String
;
929 Going
: Strings
.Direction
:= Strings
.Forward
;
930 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
931 Wide_Wide_Maps
.Identity
)
935 return Wide_Wide_Search
.Index
936 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Going
, Mapping
);
940 (Source
: Super_String
;
941 Pattern
: Wide_Wide_String
;
942 Going
: Direction
:= Forward
;
943 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
947 return Wide_Wide_Search
.Index
948 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Going
, Mapping
);
952 (Source
: Super_String
;
953 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
954 Test
: Strings
.Membership
:= Strings
.Inside
;
955 Going
: Strings
.Direction
:= Strings
.Forward
) return Natural
958 return Wide_Wide_Search
.Index
959 (Source
.Data
(1 .. Source
.Current_Length
), Set
, Test
, Going
);
963 (Source
: Super_String
;
964 Pattern
: Wide_Wide_String
;
966 Going
: Direction
:= Forward
;
967 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
968 Wide_Wide_Maps
.Identity
)
972 return Wide_Wide_Search
.Index
973 (Source
.Data
(1 .. Source
.Current_Length
),
974 Pattern
, From
, Going
, Mapping
);
978 (Source
: Super_String
;
979 Pattern
: Wide_Wide_String
;
981 Going
: Direction
:= Forward
;
982 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
986 return Wide_Wide_Search
.Index
987 (Source
.Data
(1 .. Source
.Current_Length
),
988 Pattern
, From
, Going
, Mapping
);
992 (Source
: Super_String
;
993 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
995 Test
: Membership
:= Inside
;
996 Going
: Direction
:= Forward
) return Natural
999 return Wide_Wide_Search
.Index
1000 (Source
.Data
(1 .. Source
.Current_Length
), Set
, From
, Test
, Going
);
1003 ---------------------------
1004 -- Super_Index_Non_Blank --
1005 ---------------------------
1007 function Super_Index_Non_Blank
1008 (Source
: Super_String
;
1009 Going
: Strings
.Direction
:= Strings
.Forward
) return Natural
1013 Wide_Wide_Search
.Index_Non_Blank
1014 (Source
.Data
(1 .. Source
.Current_Length
), Going
);
1015 end Super_Index_Non_Blank
;
1017 function Super_Index_Non_Blank
1018 (Source
: Super_String
;
1020 Going
: Direction
:= Forward
) return Natural
1024 Wide_Wide_Search
.Index_Non_Blank
1025 (Source
.Data
(1 .. Source
.Current_Length
), From
, Going
);
1026 end Super_Index_Non_Blank
;
1032 function Super_Insert
1033 (Source
: Super_String
;
1035 New_Item
: Wide_Wide_String
;
1036 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1038 Max_Length
: constant Positive := Source
.Max_Length
;
1039 Result
: Super_String
(Max_Length
);
1040 Slen
: constant Natural := Source
.Current_Length
;
1041 Nlen
: constant Natural := New_Item
'Length;
1042 Tlen
: constant Natural := Slen
+ Nlen
;
1043 Blen
: constant Natural := Before
- 1;
1044 Alen
: constant Integer := Slen
- Blen
;
1045 Droplen
: constant Integer := Tlen
- Max_Length
;
1047 -- Tlen is the length of the total string before possible truncation.
1048 -- Blen, Alen are the lengths of the before and after pieces of the
1053 raise Ada
.Strings
.Index_Error
;
1055 elsif Droplen
<= 0 then
1056 Result
.Current_Length
:= Tlen
;
1057 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1058 Result
.Data
(Before
.. Before
+ Nlen
- 1) := New_Item
;
1059 Result
.Data
(Before
+ Nlen
.. Tlen
) :=
1060 Source
.Data
(Before
.. Slen
);
1063 Result
.Current_Length
:= Max_Length
;
1066 when Strings
.Right
=>
1067 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1069 if Droplen
> Alen
then
1070 Result
.Data
(Before
.. Max_Length
) :=
1071 New_Item
(New_Item
'First
1072 .. New_Item
'First + Max_Length
- Before
);
1074 Result
.Data
(Before
.. Before
+ Nlen
- 1) := New_Item
;
1075 Result
.Data
(Before
+ Nlen
.. Max_Length
) :=
1076 Source
.Data
(Before
.. Slen
- Droplen
);
1079 when Strings
.Left
=>
1080 Result
.Data
(Max_Length
- (Alen
- 1) .. Max_Length
) :=
1081 Source
.Data
(Before
.. Slen
);
1083 if Droplen
>= Blen
then
1084 Result
.Data
(1 .. Max_Length
- Alen
) :=
1085 New_Item
(New_Item
'Last - (Max_Length
- Alen
) + 1
1089 (Blen
- Droplen
+ 1 .. Max_Length
- Alen
) :=
1091 Result
.Data
(1 .. Blen
- Droplen
) :=
1092 Source
.Data
(Droplen
+ 1 .. Blen
);
1095 when Strings
.Error
=>
1096 raise Ada
.Strings
.Length_Error
;
1103 procedure Super_Insert
1104 (Source
: in out Super_String
;
1106 New_Item
: Wide_Wide_String
;
1107 Drop
: Strings
.Truncation
:= Strings
.Error
)
1110 -- We do a double copy here because this is one of the situations
1111 -- in which we move data to the right, and at least at the moment,
1112 -- GNAT is not handling such cases correctly ???
1114 Source
:= Super_Insert
(Source
, Before
, New_Item
, Drop
);
1121 function Super_Length
(Source
: Super_String
) return Natural is
1123 return Source
.Current_Length
;
1126 ---------------------
1127 -- Super_Overwrite --
1128 ---------------------
1130 function Super_Overwrite
1131 (Source
: Super_String
;
1132 Position
: Positive;
1133 New_Item
: Wide_Wide_String
;
1134 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1136 Max_Length
: constant Positive := Source
.Max_Length
;
1137 Result
: Super_String
(Max_Length
);
1138 Endpos
: constant Natural := Position
+ New_Item
'Length - 1;
1139 Slen
: constant Natural := Source
.Current_Length
;
1143 if Position
> Slen
+ 1 then
1144 raise Ada
.Strings
.Index_Error
;
1146 elsif New_Item
'Length = 0 then
1149 elsif Endpos
<= Slen
then
1150 Result
.Current_Length
:= Source
.Current_Length
;
1151 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
1152 Result
.Data
(Position
.. Endpos
) := New_Item
;
1155 elsif Endpos
<= Max_Length
then
1156 Result
.Current_Length
:= Endpos
;
1157 Result
.Data
(1 .. Position
- 1) := Source
.Data
(1 .. Position
- 1);
1158 Result
.Data
(Position
.. Endpos
) := New_Item
;
1162 Result
.Current_Length
:= Max_Length
;
1163 Droplen
:= Endpos
- Max_Length
;
1166 when Strings
.Right
=>
1167 Result
.Data
(1 .. Position
- 1) :=
1168 Source
.Data
(1 .. Position
- 1);
1170 Result
.Data
(Position
.. Max_Length
) :=
1171 New_Item
(New_Item
'First .. New_Item
'Last - Droplen
);
1174 when Strings
.Left
=>
1175 if New_Item
'Length >= Max_Length
then
1176 Result
.Data
(1 .. Max_Length
) :=
1177 New_Item
(New_Item
'Last - Max_Length
+ 1 ..
1182 Result
.Data
(1 .. Max_Length
- New_Item
'Length) :=
1183 Source
.Data
(Droplen
+ 1 .. Position
- 1);
1185 (Max_Length
- New_Item
'Length + 1 .. Max_Length
) :=
1190 when Strings
.Error
=>
1191 raise Ada
.Strings
.Length_Error
;
1194 end Super_Overwrite
;
1196 procedure Super_Overwrite
1197 (Source
: in out Super_String
;
1198 Position
: Positive;
1199 New_Item
: Wide_Wide_String
;
1200 Drop
: Strings
.Truncation
:= Strings
.Error
)
1202 Max_Length
: constant Positive := Source
.Max_Length
;
1203 Endpos
: constant Positive := Position
+ New_Item
'Length - 1;
1204 Slen
: constant Natural := Source
.Current_Length
;
1208 if Position
> Slen
+ 1 then
1209 raise Ada
.Strings
.Index_Error
;
1211 elsif Endpos
<= Slen
then
1212 Source
.Data
(Position
.. Endpos
) := New_Item
;
1214 elsif Endpos
<= Max_Length
then
1215 Source
.Data
(Position
.. Endpos
) := New_Item
;
1216 Source
.Current_Length
:= Endpos
;
1219 Source
.Current_Length
:= Max_Length
;
1220 Droplen
:= Endpos
- Max_Length
;
1223 when Strings
.Right
=>
1224 Source
.Data
(Position
.. Max_Length
) :=
1225 New_Item
(New_Item
'First .. New_Item
'Last - Droplen
);
1227 when Strings
.Left
=>
1228 if New_Item
'Length > Max_Length
then
1229 Source
.Data
(1 .. Max_Length
) :=
1230 New_Item
(New_Item
'Last - Max_Length
+ 1 ..
1234 Source
.Data
(1 .. Max_Length
- New_Item
'Length) :=
1235 Source
.Data
(Droplen
+ 1 .. Position
- 1);
1238 (Max_Length
- New_Item
'Length + 1 .. Max_Length
) :=
1242 when Strings
.Error
=>
1243 raise Ada
.Strings
.Length_Error
;
1246 end Super_Overwrite
;
1248 ---------------------------
1249 -- Super_Replace_Element --
1250 ---------------------------
1252 procedure Super_Replace_Element
1253 (Source
: in out Super_String
;
1255 By
: Wide_Wide_Character
)
1258 if Index
<= Source
.Current_Length
then
1259 Source
.Data
(Index
) := By
;
1261 raise Ada
.Strings
.Index_Error
;
1263 end Super_Replace_Element
;
1265 -------------------------
1266 -- Super_Replace_Slice --
1267 -------------------------
1269 function Super_Replace_Slice
1270 (Source
: Super_String
;
1273 By
: Wide_Wide_String
;
1274 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1276 Max_Length
: constant Positive := Source
.Max_Length
;
1277 Slen
: constant Natural := Source
.Current_Length
;
1280 if Low
> Slen
+ 1 then
1281 raise Strings
.Index_Error
;
1283 elsif High
< Low
then
1284 return Super_Insert
(Source
, Low
, By
, Drop
);
1288 Blen
: constant Natural := Natural'Max (0, Low
- 1);
1289 Alen
: constant Natural := Natural'Max (0, Slen
- High
);
1290 Tlen
: constant Natural := Blen
+ By
'Length + Alen
;
1291 Droplen
: constant Integer := Tlen
- Max_Length
;
1292 Result
: Super_String
(Max_Length
);
1294 -- Tlen is the total length of the result string before any
1295 -- truncation. Blen and Alen are the lengths of the pieces
1296 -- of the original string that end up in the result string
1297 -- before and after the replaced slice.
1300 if Droplen
<= 0 then
1301 Result
.Current_Length
:= Tlen
;
1302 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1303 Result
.Data
(Low
.. Low
+ By
'Length - 1) := By
;
1304 Result
.Data
(Low
+ By
'Length .. Tlen
) :=
1305 Source
.Data
(High
+ 1 .. Slen
);
1308 Result
.Current_Length
:= Max_Length
;
1311 when Strings
.Right
=>
1312 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1314 if Droplen
> Alen
then
1315 Result
.Data
(Low
.. Max_Length
) :=
1316 By
(By
'First .. By
'First + Max_Length
- Low
);
1318 Result
.Data
(Low
.. Low
+ By
'Length - 1) := By
;
1319 Result
.Data
(Low
+ By
'Length .. Max_Length
) :=
1320 Source
.Data
(High
+ 1 .. Slen
- Droplen
);
1323 when Strings
.Left
=>
1324 Result
.Data
(Max_Length
- (Alen
- 1) .. Max_Length
) :=
1325 Source
.Data
(High
+ 1 .. Slen
);
1327 if Droplen
>= Blen
then
1328 Result
.Data
(1 .. Max_Length
- Alen
) :=
1329 By
(By
'Last - (Max_Length
- Alen
) + 1 .. By
'Last);
1332 (Blen
- Droplen
+ 1 .. Max_Length
- Alen
) := By
;
1333 Result
.Data
(1 .. Blen
- Droplen
) :=
1334 Source
.Data
(Droplen
+ 1 .. Blen
);
1337 when Strings
.Error
=>
1338 raise Ada
.Strings
.Length_Error
;
1345 end Super_Replace_Slice
;
1347 procedure Super_Replace_Slice
1348 (Source
: in out Super_String
;
1351 By
: Wide_Wide_String
;
1352 Drop
: Strings
.Truncation
:= Strings
.Error
)
1355 -- We do a double copy here because this is one of the situations
1356 -- in which we move data to the right, and at least at the moment,
1357 -- GNAT is not handling such cases correctly ???
1359 Source
:= Super_Replace_Slice
(Source
, Low
, High
, By
, Drop
);
1360 end Super_Replace_Slice
;
1362 ---------------------
1363 -- Super_Replicate --
1364 ---------------------
1366 function Super_Replicate
1368 Item
: Wide_Wide_Character
;
1369 Drop
: Truncation
:= Error
;
1370 Max_Length
: Positive) return Super_String
1372 Result
: Super_String
(Max_Length
);
1375 if Count
<= Max_Length
then
1376 Result
.Current_Length
:= Count
;
1378 elsif Drop
= Strings
.Error
then
1379 raise Ada
.Strings
.Length_Error
;
1382 Result
.Current_Length
:= Max_Length
;
1385 Result
.Data
(1 .. Result
.Current_Length
) := (others => Item
);
1387 end Super_Replicate
;
1389 function Super_Replicate
1391 Item
: Wide_Wide_String
;
1392 Drop
: Truncation
:= Error
;
1393 Max_Length
: Positive) return Super_String
1395 Length
: constant Integer := Count
* Item
'Length;
1396 Result
: Super_String
(Max_Length
);
1400 if Length
<= Max_Length
then
1401 Result
.Current_Length
:= Length
;
1406 for J
in 1 .. Count
loop
1407 Result
.Data
(Indx
.. Indx
+ Item
'Length - 1) := Item
;
1408 Indx
:= Indx
+ Item
'Length;
1413 Result
.Current_Length
:= Max_Length
;
1416 when Strings
.Right
=>
1419 while Indx
+ Item
'Length <= Max_Length
+ 1 loop
1420 Result
.Data
(Indx
.. Indx
+ Item
'Length - 1) := Item
;
1421 Indx
:= Indx
+ Item
'Length;
1424 Result
.Data
(Indx
.. Max_Length
) :=
1425 Item
(Item
'First .. Item
'First + Max_Length
- Indx
);
1427 when Strings
.Left
=>
1430 while Indx
- Item
'Length >= 1 loop
1431 Result
.Data
(Indx
- (Item
'Length - 1) .. Indx
) := Item
;
1432 Indx
:= Indx
- Item
'Length;
1435 Result
.Data
(1 .. Indx
) :=
1436 Item
(Item
'Last - Indx
+ 1 .. Item
'Last);
1438 when Strings
.Error
=>
1439 raise Ada
.Strings
.Length_Error
;
1444 end Super_Replicate
;
1446 function Super_Replicate
1448 Item
: Super_String
;
1449 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1455 Item
.Data
(1 .. Item
.Current_Length
),
1458 end Super_Replicate
;
1464 function Super_Slice
1465 (Source
: Super_String
;
1467 High
: Natural) return Wide_Wide_String
1470 -- Note: test of High > Length is in accordance with AI95-00128
1472 if Low
> Source
.Current_Length
+ 1
1473 or else High
> Source
.Current_Length
1477 return Source
.Data
(Low
.. High
);
1481 function Super_Slice
1482 (Source
: Super_String
;
1484 High
: Natural) return Super_String
1486 Result
: Super_String
(Source
.Max_Length
);
1489 if Low
> Source
.Current_Length
+ 1
1490 or else High
> Source
.Current_Length
1494 Result
.Current_Length
:= High
- Low
+ 1;
1495 Result
.Data
(1 .. Result
.Current_Length
) := Source
.Data
(Low
.. High
);
1501 procedure Super_Slice
1502 (Source
: Super_String
;
1503 Target
: out Super_String
;
1508 if Low
> Source
.Current_Length
+ 1
1509 or else High
> Source
.Current_Length
1513 Target
.Current_Length
:= High
- Low
+ 1;
1514 Target
.Data
(1 .. Target
.Current_Length
) := Source
.Data
(Low
.. High
);
1523 (Source
: Super_String
;
1525 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
1526 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1528 Max_Length
: constant Positive := Source
.Max_Length
;
1529 Result
: Super_String
(Max_Length
);
1530 Slen
: constant Natural := Source
.Current_Length
;
1531 Npad
: constant Integer := Count
- Slen
;
1535 Result
.Current_Length
:= Count
;
1536 Result
.Data
(1 .. Count
) :=
1537 Source
.Data
(Slen
- (Count
- 1) .. Slen
);
1539 elsif Count
<= Max_Length
then
1540 Result
.Current_Length
:= Count
;
1541 Result
.Data
(1 .. Npad
) := (others => Pad
);
1542 Result
.Data
(Npad
+ 1 .. Count
) := Source
.Data
(1 .. Slen
);
1545 Result
.Current_Length
:= Max_Length
;
1548 when Strings
.Right
=>
1549 if Npad
>= Max_Length
then
1550 Result
.Data
:= (others => Pad
);
1553 Result
.Data
(1 .. Npad
) := (others => Pad
);
1554 Result
.Data
(Npad
+ 1 .. Max_Length
) :=
1555 Source
.Data
(1 .. Max_Length
- Npad
);
1558 when Strings
.Left
=>
1559 Result
.Data
(1 .. Max_Length
- Slen
) := (others => Pad
);
1560 Result
.Data
(Max_Length
- Slen
+ 1 .. Max_Length
) :=
1561 Source
.Data
(1 .. Slen
);
1563 when Strings
.Error
=>
1564 raise Ada
.Strings
.Length_Error
;
1571 procedure Super_Tail
1572 (Source
: in out Super_String
;
1574 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
1575 Drop
: Truncation
:= Error
)
1577 Max_Length
: constant Positive := Source
.Max_Length
;
1578 Slen
: constant Natural := Source
.Current_Length
;
1579 Npad
: constant Integer := Count
- Slen
;
1581 Temp
: constant Wide_Wide_String
(1 .. Max_Length
) := Source
.Data
;
1585 Source
.Current_Length
:= Count
;
1586 Source
.Data
(1 .. Count
) :=
1587 Temp
(Slen
- (Count
- 1) .. Slen
);
1589 elsif Count
<= Max_Length
then
1590 Source
.Current_Length
:= Count
;
1591 Source
.Data
(1 .. Npad
) := (others => Pad
);
1592 Source
.Data
(Npad
+ 1 .. Count
) := Temp
(1 .. Slen
);
1595 Source
.Current_Length
:= Max_Length
;
1598 when Strings
.Right
=>
1599 if Npad
>= Max_Length
then
1600 Source
.Data
:= (others => Pad
);
1603 Source
.Data
(1 .. Npad
) := (others => Pad
);
1604 Source
.Data
(Npad
+ 1 .. Max_Length
) :=
1605 Temp
(1 .. Max_Length
- Npad
);
1608 when Strings
.Left
=>
1609 for J
in 1 .. Max_Length
- Slen
loop
1610 Source
.Data
(J
) := Pad
;
1613 Source
.Data
(Max_Length
- Slen
+ 1 .. Max_Length
) :=
1616 when Strings
.Error
=>
1617 raise Ada
.Strings
.Length_Error
;
1622 ---------------------
1623 -- Super_To_String --
1624 ---------------------
1626 function Super_To_String
1627 (Source
: Super_String
) return Wide_Wide_String
1630 return Source
.Data
(1 .. Source
.Current_Length
);
1631 end Super_To_String
;
1633 ---------------------
1634 -- Super_Translate --
1635 ---------------------
1637 function Super_Translate
1638 (Source
: Super_String
;
1639 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
)
1642 Result
: Super_String
(Source
.Max_Length
);
1645 Result
.Current_Length
:= Source
.Current_Length
;
1647 for J
in 1 .. Source
.Current_Length
loop
1648 Result
.Data
(J
) := Value
(Mapping
, Source
.Data
(J
));
1652 end Super_Translate
;
1654 procedure Super_Translate
1655 (Source
: in out Super_String
;
1656 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
)
1659 for J
in 1 .. Source
.Current_Length
loop
1660 Source
.Data
(J
) := Value
(Mapping
, Source
.Data
(J
));
1662 end Super_Translate
;
1664 function Super_Translate
1665 (Source
: Super_String
;
1666 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
1669 Result
: Super_String
(Source
.Max_Length
);
1672 Result
.Current_Length
:= Source
.Current_Length
;
1674 for J
in 1 .. Source
.Current_Length
loop
1675 Result
.Data
(J
) := Mapping
.all (Source
.Data
(J
));
1679 end Super_Translate
;
1681 procedure Super_Translate
1682 (Source
: in out Super_String
;
1683 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
1686 for J
in 1 .. Source
.Current_Length
loop
1687 Source
.Data
(J
) := Mapping
.all (Source
.Data
(J
));
1689 end Super_Translate
;
1696 (Source
: Super_String
;
1697 Side
: Trim_End
) return Super_String
1699 Result
: Super_String
(Source
.Max_Length
);
1700 Last
: Natural := Source
.Current_Length
;
1701 First
: Positive := 1;
1704 if Side
= Left
or else Side
= Both
then
1705 while First
<= Last
and then Source
.Data
(First
) = ' ' loop
1710 if Side
= Right
or else Side
= Both
then
1711 while Last
>= First
and then Source
.Data
(Last
) = ' ' loop
1716 Result
.Current_Length
:= Last
- First
+ 1;
1717 Result
.Data
(1 .. Result
.Current_Length
) := Source
.Data
(First
.. Last
);
1721 procedure Super_Trim
1722 (Source
: in out Super_String
;
1725 Max_Length
: constant Positive := Source
.Max_Length
;
1726 Last
: Natural := Source
.Current_Length
;
1727 First
: Positive := 1;
1728 Temp
: Wide_Wide_String
(1 .. Max_Length
);
1731 Temp
(1 .. Last
) := Source
.Data
(1 .. Last
);
1733 if Side
= Left
or else Side
= Both
then
1734 while First
<= Last
and then Temp
(First
) = ' ' loop
1739 if Side
= Right
or else Side
= Both
then
1740 while Last
>= First
and then Temp
(Last
) = ' ' loop
1745 Source
.Data
:= (others => Wide_Wide_NUL
);
1746 Source
.Current_Length
:= Last
- First
+ 1;
1747 Source
.Data
(1 .. Source
.Current_Length
) := Temp
(First
.. Last
);
1751 (Source
: Super_String
;
1752 Left
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
1753 Right
: Wide_Wide_Maps
.Wide_Wide_Character_Set
) return Super_String
1755 Result
: Super_String
(Source
.Max_Length
);
1758 for First
in 1 .. Source
.Current_Length
loop
1759 if not Is_In
(Source
.Data
(First
), Left
) then
1760 for Last
in reverse First
.. Source
.Current_Length
loop
1761 if not Is_In
(Source
.Data
(Last
), Right
) then
1762 Result
.Current_Length
:= Last
- First
+ 1;
1763 Result
.Data
(1 .. Result
.Current_Length
) :=
1764 Source
.Data
(First
.. Last
);
1771 Result
.Current_Length
:= 0;
1775 procedure Super_Trim
1776 (Source
: in out Super_String
;
1777 Left
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
1778 Right
: Wide_Wide_Maps
.Wide_Wide_Character_Set
)
1781 for First
in 1 .. Source
.Current_Length
loop
1782 if not Is_In
(Source
.Data
(First
), Left
) then
1783 for Last
in reverse First
.. Source
.Current_Length
loop
1784 if not Is_In
(Source
.Data
(Last
), Right
) then
1786 Source
.Current_Length
:= Last
;
1789 Source
.Current_Length
:= Last
- First
+ 1;
1790 Source
.Data
(1 .. Source
.Current_Length
) :=
1791 Source
.Data
(First
.. Last
);
1793 for J
in Source
.Current_Length
+ 1 ..
1796 Source
.Data
(J
) := Wide_Wide_NUL
;
1804 Source
.Current_Length
:= 0;
1809 Source
.Current_Length
:= 0;
1818 Right
: Wide_Wide_Character
;
1819 Max_Length
: Positive) return Super_String
1821 Result
: Super_String
(Max_Length
);
1824 if Left
> Max_Length
then
1825 raise Ada
.Strings
.Length_Error
;
1828 Result
.Current_Length
:= Left
;
1830 for J
in 1 .. Left
loop
1831 Result
.Data
(J
) := Right
;
1840 Right
: Wide_Wide_String
;
1841 Max_Length
: Positive) return Super_String
1843 Result
: Super_String
(Max_Length
);
1844 Pos
: Positive := 1;
1845 Rlen
: constant Natural := Right
'Length;
1846 Nlen
: constant Natural := Left
* Rlen
;
1849 if Nlen
> Max_Length
then
1850 raise Ada
.Strings
.Index_Error
;
1853 Result
.Current_Length
:= Nlen
;
1856 for J
in 1 .. Left
loop
1857 Result
.Data
(Pos
.. Pos
+ Rlen
- 1) := Right
;
1868 Right
: Super_String
) return Super_String
1870 Result
: Super_String
(Right
.Max_Length
);
1871 Pos
: Positive := 1;
1872 Rlen
: constant Natural := Right
.Current_Length
;
1873 Nlen
: constant Natural := Left
* Rlen
;
1876 if Nlen
> Right
.Max_Length
then
1877 raise Ada
.Strings
.Length_Error
;
1880 Result
.Current_Length
:= Nlen
;
1883 for J
in 1 .. Left
loop
1884 Result
.Data
(Pos
.. Pos
+ Rlen
- 1) :=
1885 Right
.Data
(1 .. Rlen
);
1894 ---------------------
1895 -- To_Super_String --
1896 ---------------------
1898 function To_Super_String
1899 (Source
: Wide_Wide_String
;
1900 Max_Length
: Natural;
1901 Drop
: Truncation
:= Error
) return Super_String
1903 Result
: Super_String
(Max_Length
);
1904 Slen
: constant Natural := Source
'Length;
1907 if Slen
<= Max_Length
then
1908 Result
.Current_Length
:= Slen
;
1909 Result
.Data
(1 .. Slen
) := Source
;
1913 when Strings
.Right
=>
1914 Result
.Current_Length
:= Max_Length
;
1915 Result
.Data
(1 .. Max_Length
) :=
1916 Source
(Source
'First .. Source
'First - 1 + Max_Length
);
1918 when Strings
.Left
=>
1919 Result
.Current_Length
:= Max_Length
;
1920 Result
.Data
(1 .. Max_Length
) :=
1921 Source
(Source
'Last - (Max_Length
- 1) .. Source
'Last);
1923 when Strings
.Error
=>
1924 raise Ada
.Strings
.Length_Error
;
1929 end To_Super_String
;
1931 end Ada
.Strings
.Wide_Wide_Superbounded
;