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-2006, 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 with Ada
.Strings
.Wide_Wide_Maps
; use Ada
.Strings
.Wide_Wide_Maps
;
35 with Ada
.Strings
.Wide_Wide_Search
;
37 package body Ada
.Strings
.Wide_Wide_Superbounded
is
45 Right
: Super_String
) return Super_String
47 Result
: Super_String
(Left
.Max_Length
);
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
68 Result
: Super_String
(Left
.Max_Length
);
69 Llen
: constant Natural := Left
.Current_Length
;
71 Nlen
: constant Natural := Llen
+ Right
'Length;
74 if Nlen
> Left
.Max_Length
then
75 raise Ada
.Strings
.Length_Error
;
77 Result
.Current_Length
:= Nlen
;
78 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
79 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
;
85 (Left
: Wide_Wide_String
;
86 Right
: Super_String
) return Super_String
88 Result
: Super_String
(Right
.Max_Length
);
89 Llen
: constant Natural := Left
'Length;
90 Rlen
: constant Natural := Right
.Current_Length
;
91 Nlen
: constant Natural := Llen
+ Rlen
;
94 if Nlen
> Right
.Max_Length
then
95 raise Ada
.Strings
.Length_Error
;
97 Result
.Current_Length
:= Nlen
;
98 Result
.Data
(1 .. Llen
) := Left
;
99 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
.Data
(1 .. Rlen
);
106 (Left
: Super_String
;
107 Right
: Wide_Wide_Character
) return Super_String
109 Result
: Super_String
(Left
.Max_Length
);
110 Llen
: constant Natural := Left
.Current_Length
;
113 if Llen
= Left
.Max_Length
then
114 raise Ada
.Strings
.Length_Error
;
116 Result
.Current_Length
:= Llen
+ 1;
117 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
118 Result
.Data
(Result
.Current_Length
) := Right
;
125 (Left
: Wide_Wide_Character
;
126 Right
: Super_String
) return Super_String
128 Result
: Super_String
(Right
.Max_Length
);
129 Rlen
: constant Natural := Right
.Current_Length
;
132 if Rlen
= Right
.Max_Length
then
133 raise Ada
.Strings
.Length_Error
;
135 Result
.Current_Length
:= Rlen
+ 1;
136 Result
.Data
(1) := Left
;
137 Result
.Data
(2 .. Result
.Current_Length
) := Right
.Data
(1 .. Rlen
);
148 (Left
: Super_String
;
149 Right
: Super_String
) return Boolean
152 return Left
.Current_Length
= Right
.Current_Length
153 and then Left
.Data
(1 .. Left
.Current_Length
) =
154 Right
.Data
(1 .. Right
.Current_Length
);
158 (Left
: Super_String
;
159 Right
: Wide_Wide_String
) return Boolean
162 return Left
.Current_Length
= Right
'Length
163 and then Left
.Data
(1 .. Left
.Current_Length
) = Right
;
167 (Left
: Wide_Wide_String
;
168 Right
: Super_String
) return Boolean
171 return Left
'Length = Right
.Current_Length
172 and then Left
= Right
.Data
(1 .. Right
.Current_Length
);
180 (Left
: Super_String
;
181 Right
: Super_String
) return Boolean
184 return Left
.Data
(1 .. Left
.Current_Length
) >
185 Right
.Data
(1 .. Right
.Current_Length
);
189 (Left
: Super_String
;
190 Right
: Wide_Wide_String
) return Boolean
193 return Left
.Data
(1 .. Left
.Current_Length
) > Right
;
197 (Left
: Wide_Wide_String
;
198 Right
: Super_String
) return Boolean
201 return Left
> Right
.Data
(1 .. Right
.Current_Length
);
204 ----------------------
205 -- Greater_Or_Equal --
206 ----------------------
208 function Greater_Or_Equal
209 (Left
: Super_String
;
210 Right
: Super_String
) return Boolean
213 return Left
.Data
(1 .. Left
.Current_Length
) >=
214 Right
.Data
(1 .. Right
.Current_Length
);
215 end Greater_Or_Equal
;
217 function Greater_Or_Equal
218 (Left
: Super_String
;
219 Right
: Wide_Wide_String
) return Boolean
222 return Left
.Data
(1 .. Left
.Current_Length
) >= Right
;
223 end Greater_Or_Equal
;
225 function Greater_Or_Equal
226 (Left
: Wide_Wide_String
;
227 Right
: Super_String
) return Boolean
230 return Left
>= Right
.Data
(1 .. Right
.Current_Length
);
231 end Greater_Or_Equal
;
238 (Left
: Super_String
;
239 Right
: Super_String
) return Boolean
242 return Left
.Data
(1 .. Left
.Current_Length
) <
243 Right
.Data
(1 .. Right
.Current_Length
);
247 (Left
: Super_String
;
248 Right
: Wide_Wide_String
) return Boolean
251 return Left
.Data
(1 .. Left
.Current_Length
) < Right
;
255 (Left
: Wide_Wide_String
;
256 Right
: Super_String
) return Boolean
259 return Left
< Right
.Data
(1 .. Right
.Current_Length
);
266 function Less_Or_Equal
267 (Left
: Super_String
;
268 Right
: Super_String
) return Boolean
271 return Left
.Data
(1 .. Left
.Current_Length
) <=
272 Right
.Data
(1 .. Right
.Current_Length
);
275 function Less_Or_Equal
276 (Left
: Super_String
;
277 Right
: Wide_Wide_String
) return Boolean
280 return Left
.Data
(1 .. Left
.Current_Length
) <= Right
;
283 function Less_Or_Equal
284 (Left
: Wide_Wide_String
;
285 Right
: Super_String
) return Boolean
288 return Left
<= Right
.Data
(1 .. Right
.Current_Length
);
291 ----------------------
292 -- Set_Super_String --
293 ----------------------
295 procedure Set_Super_String
296 (Target
: out Super_String
;
297 Source
: Wide_Wide_String
;
298 Drop
: Truncation
:= Error
)
300 Slen
: constant Natural := Source
'Length;
301 Max_Length
: constant Positive := Target
.Max_Length
;
304 if Slen
<= Max_Length
then
305 Target
.Current_Length
:= Slen
;
306 Target
.Data
(1 .. Slen
) := Source
;
310 when Strings
.Right
=>
311 Target
.Current_Length
:= Max_Length
;
312 Target
.Data
(1 .. Max_Length
) :=
313 Source
(Source
'First .. Source
'First - 1 + Max_Length
);
316 Target
.Current_Length
:= Max_Length
;
317 Target
.Data
(1 .. Max_Length
) :=
318 Source
(Source
'Last - (Max_Length
- 1) .. Source
'Last);
320 when Strings
.Error
=>
321 raise Ada
.Strings
.Length_Error
;
324 end Set_Super_String
;
330 -- Case of Super_String and Super_String
332 function Super_Append
333 (Left
: Super_String
;
334 Right
: Super_String
;
335 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
337 Max_Length
: constant Positive := Left
.Max_Length
;
338 Result
: Super_String
(Max_Length
);
339 Llen
: constant Natural := Left
.Current_Length
;
340 Rlen
: constant Natural := Right
.Current_Length
;
341 Nlen
: constant Natural := Llen
+ Rlen
;
344 if Nlen
<= Max_Length
then
345 Result
.Current_Length
:= Nlen
;
346 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
347 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
.Data
(1 .. Rlen
);
350 Result
.Current_Length
:= Max_Length
;
353 when Strings
.Right
=>
354 if Llen
>= Max_Length
then -- only case is Llen = Max_Length
355 Result
.Data
:= Left
.Data
;
358 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
359 Result
.Data
(Llen
+ 1 .. Max_Length
) :=
360 Right
.Data
(1 .. Max_Length
- Llen
);
364 if Rlen
>= Max_Length
then -- only case is Rlen = Max_Length
365 Result
.Data
:= Right
.Data
;
368 Result
.Data
(1 .. Max_Length
- Rlen
) :=
369 Left
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
370 Result
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
371 Right
.Data
(1 .. Rlen
);
374 when Strings
.Error
=>
375 raise Ada
.Strings
.Length_Error
;
382 procedure Super_Append
383 (Source
: in out Super_String
;
384 New_Item
: Super_String
;
385 Drop
: Truncation
:= Error
)
387 Max_Length
: constant Positive := Source
.Max_Length
;
388 Llen
: constant Natural := Source
.Current_Length
;
389 Rlen
: constant Natural := New_Item
.Current_Length
;
390 Nlen
: constant Natural := Llen
+ Rlen
;
393 if Nlen
<= Max_Length
then
394 Source
.Current_Length
:= Nlen
;
395 Source
.Data
(Llen
+ 1 .. Nlen
) := New_Item
.Data
(1 .. Rlen
);
398 Source
.Current_Length
:= Max_Length
;
401 when Strings
.Right
=>
402 if Llen
< Max_Length
then
403 Source
.Data
(Llen
+ 1 .. Max_Length
) :=
404 New_Item
.Data
(1 .. Max_Length
- Llen
);
408 if Rlen
>= Max_Length
then -- only case is Rlen = Max_Length
409 Source
.Data
:= New_Item
.Data
;
412 Source
.Data
(1 .. Max_Length
- Rlen
) :=
413 Source
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
414 Source
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
415 New_Item
.Data
(1 .. Rlen
);
418 when Strings
.Error
=>
419 raise Ada
.Strings
.Length_Error
;
425 -- Case of Super_String and Wide_Wide_String
427 function Super_Append
428 (Left
: Super_String
;
429 Right
: Wide_Wide_String
;
430 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
432 Max_Length
: constant Positive := Left
.Max_Length
;
433 Result
: Super_String
(Max_Length
);
434 Llen
: constant Natural := Left
.Current_Length
;
435 Rlen
: constant Natural := Right
'Length;
436 Nlen
: constant Natural := Llen
+ Rlen
;
439 if Nlen
<= Max_Length
then
440 Result
.Current_Length
:= Nlen
;
441 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
442 Result
.Data
(Llen
+ 1 .. Nlen
) := Right
;
445 Result
.Current_Length
:= Max_Length
;
448 when Strings
.Right
=>
449 if Llen
>= Max_Length
then -- only case is Llen = Max_Length
450 Result
.Data
:= Left
.Data
;
453 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
454 Result
.Data
(Llen
+ 1 .. Max_Length
) :=
455 Right
(Right
'First .. Right
'First - 1 +
461 if Rlen
>= Max_Length
then
462 Result
.Data
(1 .. Max_Length
) :=
463 Right
(Right
'Last - (Max_Length
- 1) .. Right
'Last);
466 Result
.Data
(1 .. Max_Length
- Rlen
) :=
467 Left
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
468 Result
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
472 when Strings
.Error
=>
473 raise Ada
.Strings
.Length_Error
;
480 procedure Super_Append
481 (Source
: in out Super_String
;
482 New_Item
: Wide_Wide_String
;
483 Drop
: Truncation
:= Error
)
485 Max_Length
: constant Positive := Source
.Max_Length
;
486 Llen
: constant Natural := Source
.Current_Length
;
487 Rlen
: constant Natural := New_Item
'Length;
488 Nlen
: constant Natural := Llen
+ Rlen
;
491 if Nlen
<= Max_Length
then
492 Source
.Current_Length
:= Nlen
;
493 Source
.Data
(Llen
+ 1 .. Nlen
) := New_Item
;
496 Source
.Current_Length
:= Max_Length
;
499 when Strings
.Right
=>
500 if Llen
< Max_Length
then
501 Source
.Data
(Llen
+ 1 .. Max_Length
) :=
502 New_Item
(New_Item
'First ..
503 New_Item
'First - 1 + Max_Length
- Llen
);
507 if Rlen
>= Max_Length
then
508 Source
.Data
(1 .. Max_Length
) :=
509 New_Item
(New_Item
'Last - (Max_Length
- 1) ..
513 Source
.Data
(1 .. Max_Length
- Rlen
) :=
514 Source
.Data
(Llen
- (Max_Length
- Rlen
- 1) .. Llen
);
515 Source
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
519 when Strings
.Error
=>
520 raise Ada
.Strings
.Length_Error
;
526 -- Case of Wide_Wide_String and Super_String
528 function Super_Append
529 (Left
: Wide_Wide_String
;
530 Right
: Super_String
;
531 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
533 Max_Length
: constant Positive := Right
.Max_Length
;
534 Result
: Super_String
(Max_Length
);
535 Llen
: constant Natural := Left
'Length;
536 Rlen
: constant Natural := Right
.Current_Length
;
537 Nlen
: constant Natural := Llen
+ Rlen
;
540 if Nlen
<= Max_Length
then
541 Result
.Current_Length
:= Nlen
;
542 Result
.Data
(1 .. Llen
) := Left
;
543 Result
.Data
(Llen
+ 1 .. Llen
+ Rlen
) := Right
.Data
(1 .. Rlen
);
546 Result
.Current_Length
:= Max_Length
;
549 when Strings
.Right
=>
550 if Llen
>= Max_Length
then
551 Result
.Data
(1 .. Max_Length
) :=
552 Left
(Left
'First .. Left
'First + (Max_Length
- 1));
555 Result
.Data
(1 .. Llen
) := Left
;
556 Result
.Data
(Llen
+ 1 .. Max_Length
) :=
557 Right
.Data
(1 .. Max_Length
- Llen
);
561 if Rlen
>= Max_Length
then
562 Result
.Data
(1 .. Max_Length
) :=
563 Right
.Data
(Rlen
- (Max_Length
- 1) .. Rlen
);
566 Result
.Data
(1 .. Max_Length
- Rlen
) :=
567 Left
(Left
'Last - (Max_Length
- Rlen
- 1) .. Left
'Last);
568 Result
.Data
(Max_Length
- Rlen
+ 1 .. Max_Length
) :=
569 Right
.Data
(1 .. Rlen
);
572 when Strings
.Error
=>
573 raise Ada
.Strings
.Length_Error
;
580 -- Case of Super_String and Wide_Wide_Character
582 function Super_Append
583 (Left
: Super_String
;
584 Right
: Wide_Wide_Character
;
585 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
587 Max_Length
: constant Positive := Left
.Max_Length
;
588 Result
: Super_String
(Max_Length
);
589 Llen
: constant Natural := Left
.Current_Length
;
592 if Llen
< Max_Length
then
593 Result
.Current_Length
:= Llen
+ 1;
594 Result
.Data
(1 .. Llen
) := Left
.Data
(1 .. Llen
);
595 Result
.Data
(Llen
+ 1) := Right
;
600 when Strings
.Right
=>
604 Result
.Current_Length
:= Max_Length
;
605 Result
.Data
(1 .. Max_Length
- 1) :=
606 Left
.Data
(2 .. Max_Length
);
607 Result
.Data
(Max_Length
) := Right
;
610 when Strings
.Error
=>
611 raise Ada
.Strings
.Length_Error
;
616 procedure Super_Append
617 (Source
: in out Super_String
;
618 New_Item
: Wide_Wide_Character
;
619 Drop
: Truncation
:= Error
)
621 Max_Length
: constant Positive := Source
.Max_Length
;
622 Llen
: constant Natural := Source
.Current_Length
;
625 if Llen
< Max_Length
then
626 Source
.Current_Length
:= Llen
+ 1;
627 Source
.Data
(Llen
+ 1) := New_Item
;
630 Source
.Current_Length
:= Max_Length
;
633 when Strings
.Right
=>
637 Source
.Data
(1 .. Max_Length
- 1) :=
638 Source
.Data
(2 .. Max_Length
);
639 Source
.Data
(Max_Length
) := New_Item
;
641 when Strings
.Error
=>
642 raise Ada
.Strings
.Length_Error
;
648 -- Case of Wide_Wide_Character and Super_String
650 function Super_Append
651 (Left
: Wide_Wide_Character
;
652 Right
: Super_String
;
653 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
655 Max_Length
: constant Positive := Right
.Max_Length
;
656 Result
: Super_String
(Max_Length
);
657 Rlen
: constant Natural := Right
.Current_Length
;
660 if Rlen
< Max_Length
then
661 Result
.Current_Length
:= Rlen
+ 1;
662 Result
.Data
(1) := Left
;
663 Result
.Data
(2 .. Rlen
+ 1) := Right
.Data
(1 .. Rlen
);
668 when Strings
.Right
=>
669 Result
.Current_Length
:= Max_Length
;
670 Result
.Data
(1) := Left
;
671 Result
.Data
(2 .. Max_Length
) :=
672 Right
.Data
(1 .. Max_Length
- 1);
678 when Strings
.Error
=>
679 raise Ada
.Strings
.Length_Error
;
689 (Source
: Super_String
;
690 Pattern
: Wide_Wide_String
;
691 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
692 Wide_Wide_Maps
.Identity
)
697 Wide_Wide_Search
.Count
698 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Mapping
);
702 (Source
: Super_String
;
703 Pattern
: Wide_Wide_String
;
704 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
709 Wide_Wide_Search
.Count
710 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Mapping
);
714 (Source
: Super_String
;
715 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
) return Natural
718 return Wide_Wide_Search
.Count
719 (Source
.Data
(1 .. Source
.Current_Length
), Set
);
726 function Super_Delete
727 (Source
: Super_String
;
729 Through
: Natural) return Super_String
731 Result
: Super_String
(Source
.Max_Length
);
732 Slen
: constant Natural := Source
.Current_Length
;
733 Num_Delete
: constant Integer := Through
- From
+ 1;
736 if Num_Delete
<= 0 then
739 elsif From
> Slen
+ 1 then
740 raise Ada
.Strings
.Index_Error
;
742 elsif Through
>= Slen
then
743 Result
.Current_Length
:= From
- 1;
744 Result
.Data
(1 .. From
- 1) := Source
.Data
(1 .. From
- 1);
748 Result
.Current_Length
:= Slen
- Num_Delete
;
749 Result
.Data
(1 .. From
- 1) := Source
.Data
(1 .. From
- 1);
750 Result
.Data
(From
.. Result
.Current_Length
) :=
751 Source
.Data
(Through
+ 1 .. Slen
);
756 procedure Super_Delete
757 (Source
: in out Super_String
;
761 Slen
: constant Natural := Source
.Current_Length
;
762 Num_Delete
: constant Integer := Through
- From
+ 1;
765 if Num_Delete
<= 0 then
768 elsif From
> Slen
+ 1 then
769 raise Ada
.Strings
.Index_Error
;
771 elsif Through
>= Slen
then
772 Source
.Current_Length
:= From
- 1;
775 Source
.Current_Length
:= Slen
- Num_Delete
;
776 Source
.Data
(From
.. Source
.Current_Length
) :=
777 Source
.Data
(Through
+ 1 .. Slen
);
785 function Super_Element
786 (Source
: Super_String
;
787 Index
: Positive) return Wide_Wide_Character
790 if Index
in 1 .. Source
.Current_Length
then
791 return Source
.Data
(Index
);
793 raise Strings
.Index_Error
;
797 ----------------------
798 -- Super_Find_Token --
799 ----------------------
801 procedure Super_Find_Token
802 (Source
: Super_String
;
803 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
804 Test
: Strings
.Membership
;
805 First
: out Positive;
809 Wide_Wide_Search
.Find_Token
810 (Source
.Data
(1 .. Source
.Current_Length
), Set
, Test
, First
, Last
);
811 end Super_Find_Token
;
818 (Source
: Super_String
;
820 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
821 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
823 Max_Length
: constant Positive := Source
.Max_Length
;
824 Result
: Super_String
(Max_Length
);
825 Slen
: constant Natural := Source
.Current_Length
;
826 Npad
: constant Integer := Count
- Slen
;
830 Result
.Current_Length
:= Count
;
831 Result
.Data
(1 .. Count
) := Source
.Data
(1 .. Count
);
833 elsif Count
<= Max_Length
then
834 Result
.Current_Length
:= Count
;
835 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
836 Result
.Data
(Slen
+ 1 .. Count
) := (others => Pad
);
839 Result
.Current_Length
:= Max_Length
;
842 when Strings
.Right
=>
843 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
844 Result
.Data
(Slen
+ 1 .. Max_Length
) := (others => Pad
);
847 if Npad
>= Max_Length
then
848 Result
.Data
:= (others => Pad
);
851 Result
.Data
(1 .. Max_Length
- Npad
) :=
852 Source
.Data
(Count
- Max_Length
+ 1 .. Slen
);
853 Result
.Data
(Max_Length
- Npad
+ 1 .. Max_Length
) :=
857 when Strings
.Error
=>
858 raise Ada
.Strings
.Length_Error
;
866 (Source
: in out Super_String
;
868 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
869 Drop
: Truncation
:= Error
)
871 Max_Length
: constant Positive := Source
.Max_Length
;
872 Slen
: constant Natural := Source
.Current_Length
;
873 Npad
: constant Integer := Count
- Slen
;
874 Temp
: Wide_Wide_String
(1 .. Max_Length
);
878 Source
.Current_Length
:= Count
;
880 elsif Count
<= Max_Length
then
881 Source
.Current_Length
:= Count
;
882 Source
.Data
(Slen
+ 1 .. Count
) := (others => Pad
);
885 Source
.Current_Length
:= Max_Length
;
888 when Strings
.Right
=>
889 Source
.Data
(Slen
+ 1 .. Max_Length
) := (others => Pad
);
892 if Npad
> Max_Length
then
893 Source
.Data
:= (others => Pad
);
897 Source
.Data
(1 .. Max_Length
- Npad
) :=
898 Temp
(Count
- Max_Length
+ 1 .. Slen
);
900 for J
in Max_Length
- Npad
+ 1 .. Max_Length
loop
901 Source
.Data
(J
) := Pad
;
905 when Strings
.Error
=>
906 raise Ada
.Strings
.Length_Error
;
916 (Source
: Super_String
;
917 Pattern
: Wide_Wide_String
;
918 Going
: Strings
.Direction
:= Strings
.Forward
;
919 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
920 Wide_Wide_Maps
.Identity
)
924 return Wide_Wide_Search
.Index
925 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Going
, Mapping
);
929 (Source
: Super_String
;
930 Pattern
: Wide_Wide_String
;
931 Going
: Direction
:= Forward
;
932 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
936 return Wide_Wide_Search
.Index
937 (Source
.Data
(1 .. Source
.Current_Length
), Pattern
, Going
, Mapping
);
941 (Source
: Super_String
;
942 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
943 Test
: Strings
.Membership
:= Strings
.Inside
;
944 Going
: Strings
.Direction
:= Strings
.Forward
) return Natural
947 return Wide_Wide_Search
.Index
948 (Source
.Data
(1 .. Source
.Current_Length
), Set
, Test
, Going
);
952 (Source
: Super_String
;
953 Pattern
: Wide_Wide_String
;
955 Going
: Direction
:= Forward
;
956 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
:=
957 Wide_Wide_Maps
.Identity
)
961 return Wide_Wide_Search
.Index
962 (Source
.Data
(1 .. Source
.Current_Length
),
963 Pattern
, From
, Going
, Mapping
);
967 (Source
: Super_String
;
968 Pattern
: Wide_Wide_String
;
970 Going
: Direction
:= Forward
;
971 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
975 return Wide_Wide_Search
.Index
976 (Source
.Data
(1 .. Source
.Current_Length
),
977 Pattern
, From
, Going
, Mapping
);
981 (Source
: Super_String
;
982 Set
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
984 Test
: Membership
:= Inside
;
985 Going
: Direction
:= Forward
) return Natural
988 return Wide_Wide_Search
.Index
989 (Source
.Data
(1 .. Source
.Current_Length
), Set
, From
, Test
, Going
);
992 ---------------------------
993 -- Super_Index_Non_Blank --
994 ---------------------------
996 function Super_Index_Non_Blank
997 (Source
: Super_String
;
998 Going
: Strings
.Direction
:= Strings
.Forward
) return Natural
1002 Wide_Wide_Search
.Index_Non_Blank
1003 (Source
.Data
(1 .. Source
.Current_Length
), Going
);
1004 end Super_Index_Non_Blank
;
1006 function Super_Index_Non_Blank
1007 (Source
: Super_String
;
1009 Going
: Direction
:= Forward
) return Natural
1013 Wide_Wide_Search
.Index_Non_Blank
1014 (Source
.Data
(1 .. Source
.Current_Length
), From
, Going
);
1015 end Super_Index_Non_Blank
;
1021 function Super_Insert
1022 (Source
: Super_String
;
1024 New_Item
: Wide_Wide_String
;
1025 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1027 Max_Length
: constant Positive := Source
.Max_Length
;
1028 Result
: Super_String
(Max_Length
);
1029 Slen
: constant Natural := Source
.Current_Length
;
1030 Nlen
: constant Natural := New_Item
'Length;
1031 Tlen
: constant Natural := Slen
+ Nlen
;
1032 Blen
: constant Natural := Before
- 1;
1033 Alen
: constant Integer := Slen
- Blen
;
1034 Droplen
: constant Integer := Tlen
- Max_Length
;
1036 -- Tlen is the length of the total string before possible truncation.
1037 -- Blen, Alen are the lengths of the before and after pieces of the
1042 raise Ada
.Strings
.Index_Error
;
1044 elsif Droplen
<= 0 then
1045 Result
.Current_Length
:= Tlen
;
1046 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1047 Result
.Data
(Before
.. Before
+ Nlen
- 1) := New_Item
;
1048 Result
.Data
(Before
+ Nlen
.. Tlen
) :=
1049 Source
.Data
(Before
.. Slen
);
1052 Result
.Current_Length
:= Max_Length
;
1055 when Strings
.Right
=>
1056 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1058 if Droplen
> Alen
then
1059 Result
.Data
(Before
.. Max_Length
) :=
1060 New_Item
(New_Item
'First
1061 .. New_Item
'First + Max_Length
- Before
);
1063 Result
.Data
(Before
.. Before
+ Nlen
- 1) := New_Item
;
1064 Result
.Data
(Before
+ Nlen
.. Max_Length
) :=
1065 Source
.Data
(Before
.. Slen
- Droplen
);
1068 when Strings
.Left
=>
1069 Result
.Data
(Max_Length
- (Alen
- 1) .. Max_Length
) :=
1070 Source
.Data
(Before
.. Slen
);
1072 if Droplen
>= Blen
then
1073 Result
.Data
(1 .. Max_Length
- Alen
) :=
1074 New_Item
(New_Item
'Last - (Max_Length
- Alen
) + 1
1078 (Blen
- Droplen
+ 1 .. Max_Length
- Alen
) :=
1080 Result
.Data
(1 .. Blen
- Droplen
) :=
1081 Source
.Data
(Droplen
+ 1 .. Blen
);
1084 when Strings
.Error
=>
1085 raise Ada
.Strings
.Length_Error
;
1092 procedure Super_Insert
1093 (Source
: in out Super_String
;
1095 New_Item
: Wide_Wide_String
;
1096 Drop
: Strings
.Truncation
:= Strings
.Error
)
1099 -- We do a double copy here because this is one of the situations
1100 -- in which we move data to the right, and at least at the moment,
1101 -- GNAT is not handling such cases correctly ???
1103 Source
:= Super_Insert
(Source
, Before
, New_Item
, Drop
);
1110 function Super_Length
(Source
: Super_String
) return Natural is
1112 return Source
.Current_Length
;
1115 ---------------------
1116 -- Super_Overwrite --
1117 ---------------------
1119 function Super_Overwrite
1120 (Source
: Super_String
;
1121 Position
: Positive;
1122 New_Item
: Wide_Wide_String
;
1123 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1125 Max_Length
: constant Positive := Source
.Max_Length
;
1126 Result
: Super_String
(Max_Length
);
1127 Endpos
: constant Natural := Position
+ New_Item
'Length - 1;
1128 Slen
: constant Natural := Source
.Current_Length
;
1132 if Position
> Slen
+ 1 then
1133 raise Ada
.Strings
.Index_Error
;
1135 elsif New_Item
'Length = 0 then
1138 elsif Endpos
<= Slen
then
1139 Result
.Current_Length
:= Source
.Current_Length
;
1140 Result
.Data
(1 .. Slen
) := Source
.Data
(1 .. Slen
);
1141 Result
.Data
(Position
.. Endpos
) := New_Item
;
1144 elsif Endpos
<= Max_Length
then
1145 Result
.Current_Length
:= Endpos
;
1146 Result
.Data
(1 .. Position
- 1) := Source
.Data
(1 .. Position
- 1);
1147 Result
.Data
(Position
.. Endpos
) := New_Item
;
1151 Result
.Current_Length
:= Max_Length
;
1152 Droplen
:= Endpos
- Max_Length
;
1155 when Strings
.Right
=>
1156 Result
.Data
(1 .. Position
- 1) :=
1157 Source
.Data
(1 .. Position
- 1);
1159 Result
.Data
(Position
.. Max_Length
) :=
1160 New_Item
(New_Item
'First .. New_Item
'Last - Droplen
);
1163 when Strings
.Left
=>
1164 if New_Item
'Length >= Max_Length
then
1165 Result
.Data
(1 .. Max_Length
) :=
1166 New_Item
(New_Item
'Last - Max_Length
+ 1 ..
1171 Result
.Data
(1 .. Max_Length
- New_Item
'Length) :=
1172 Source
.Data
(Droplen
+ 1 .. Position
- 1);
1174 (Max_Length
- New_Item
'Length + 1 .. Max_Length
) :=
1179 when Strings
.Error
=>
1180 raise Ada
.Strings
.Length_Error
;
1183 end Super_Overwrite
;
1185 procedure Super_Overwrite
1186 (Source
: in out Super_String
;
1187 Position
: Positive;
1188 New_Item
: Wide_Wide_String
;
1189 Drop
: Strings
.Truncation
:= Strings
.Error
)
1191 Max_Length
: constant Positive := Source
.Max_Length
;
1192 Endpos
: constant Positive := Position
+ New_Item
'Length - 1;
1193 Slen
: constant Natural := Source
.Current_Length
;
1197 if Position
> Slen
+ 1 then
1198 raise Ada
.Strings
.Index_Error
;
1200 elsif Endpos
<= Slen
then
1201 Source
.Data
(Position
.. Endpos
) := New_Item
;
1203 elsif Endpos
<= Max_Length
then
1204 Source
.Data
(Position
.. Endpos
) := New_Item
;
1205 Source
.Current_Length
:= Endpos
;
1208 Source
.Current_Length
:= Max_Length
;
1209 Droplen
:= Endpos
- Max_Length
;
1212 when Strings
.Right
=>
1213 Source
.Data
(Position
.. Max_Length
) :=
1214 New_Item
(New_Item
'First .. New_Item
'Last - Droplen
);
1216 when Strings
.Left
=>
1217 if New_Item
'Length > Max_Length
then
1218 Source
.Data
(1 .. Max_Length
) :=
1219 New_Item
(New_Item
'Last - Max_Length
+ 1 ..
1223 Source
.Data
(1 .. Max_Length
- New_Item
'Length) :=
1224 Source
.Data
(Droplen
+ 1 .. Position
- 1);
1227 (Max_Length
- New_Item
'Length + 1 .. Max_Length
) :=
1231 when Strings
.Error
=>
1232 raise Ada
.Strings
.Length_Error
;
1235 end Super_Overwrite
;
1237 ---------------------------
1238 -- Super_Replace_Element --
1239 ---------------------------
1241 procedure Super_Replace_Element
1242 (Source
: in out Super_String
;
1244 By
: Wide_Wide_Character
)
1247 if Index
<= Source
.Current_Length
then
1248 Source
.Data
(Index
) := By
;
1250 raise Ada
.Strings
.Index_Error
;
1252 end Super_Replace_Element
;
1254 -------------------------
1255 -- Super_Replace_Slice --
1256 -------------------------
1258 function Super_Replace_Slice
1259 (Source
: Super_String
;
1262 By
: Wide_Wide_String
;
1263 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1265 Max_Length
: constant Positive := Source
.Max_Length
;
1266 Slen
: constant Natural := Source
.Current_Length
;
1269 if Low
> Slen
+ 1 then
1270 raise Strings
.Index_Error
;
1272 elsif High
< Low
then
1273 return Super_Insert
(Source
, Low
, By
, Drop
);
1277 Blen
: constant Natural := Natural'Max (0, Low
- 1);
1278 Alen
: constant Natural := Natural'Max (0, Slen
- High
);
1279 Tlen
: constant Natural := Blen
+ By
'Length + Alen
;
1280 Droplen
: constant Integer := Tlen
- Max_Length
;
1281 Result
: Super_String
(Max_Length
);
1283 -- Tlen is the total length of the result string before any
1284 -- truncation. Blen and Alen are the lengths of the pieces
1285 -- of the original string that end up in the result string
1286 -- before and after the replaced slice.
1289 if Droplen
<= 0 then
1290 Result
.Current_Length
:= Tlen
;
1291 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1292 Result
.Data
(Low
.. Low
+ By
'Length - 1) := By
;
1293 Result
.Data
(Low
+ By
'Length .. Tlen
) :=
1294 Source
.Data
(High
+ 1 .. Slen
);
1297 Result
.Current_Length
:= Max_Length
;
1300 when Strings
.Right
=>
1301 Result
.Data
(1 .. Blen
) := Source
.Data
(1 .. Blen
);
1303 if Droplen
> Alen
then
1304 Result
.Data
(Low
.. Max_Length
) :=
1305 By
(By
'First .. By
'First + Max_Length
- Low
);
1307 Result
.Data
(Low
.. Low
+ By
'Length - 1) := By
;
1308 Result
.Data
(Low
+ By
'Length .. Max_Length
) :=
1309 Source
.Data
(High
+ 1 .. Slen
- Droplen
);
1312 when Strings
.Left
=>
1313 Result
.Data
(Max_Length
- (Alen
- 1) .. Max_Length
) :=
1314 Source
.Data
(High
+ 1 .. Slen
);
1316 if Droplen
>= Blen
then
1317 Result
.Data
(1 .. Max_Length
- Alen
) :=
1318 By
(By
'Last - (Max_Length
- Alen
) + 1 .. By
'Last);
1321 (Blen
- Droplen
+ 1 .. Max_Length
- Alen
) := By
;
1322 Result
.Data
(1 .. Blen
- Droplen
) :=
1323 Source
.Data
(Droplen
+ 1 .. Blen
);
1326 when Strings
.Error
=>
1327 raise Ada
.Strings
.Length_Error
;
1334 end Super_Replace_Slice
;
1336 procedure Super_Replace_Slice
1337 (Source
: in out Super_String
;
1340 By
: Wide_Wide_String
;
1341 Drop
: Strings
.Truncation
:= Strings
.Error
)
1344 -- We do a double copy here because this is one of the situations
1345 -- in which we move data to the right, and at least at the moment,
1346 -- GNAT is not handling such cases correctly ???
1348 Source
:= Super_Replace_Slice
(Source
, Low
, High
, By
, Drop
);
1349 end Super_Replace_Slice
;
1351 ---------------------
1352 -- Super_Replicate --
1353 ---------------------
1355 function Super_Replicate
1357 Item
: Wide_Wide_Character
;
1358 Drop
: Truncation
:= Error
;
1359 Max_Length
: Positive) return Super_String
1361 Result
: Super_String
(Max_Length
);
1364 if Count
<= Max_Length
then
1365 Result
.Current_Length
:= Count
;
1367 elsif Drop
= Strings
.Error
then
1368 raise Ada
.Strings
.Length_Error
;
1371 Result
.Current_Length
:= Max_Length
;
1374 Result
.Data
(1 .. Result
.Current_Length
) := (others => Item
);
1376 end Super_Replicate
;
1378 function Super_Replicate
1380 Item
: Wide_Wide_String
;
1381 Drop
: Truncation
:= Error
;
1382 Max_Length
: Positive) return Super_String
1384 Length
: constant Integer := Count
* Item
'Length;
1385 Result
: Super_String
(Max_Length
);
1389 if Length
<= Max_Length
then
1390 Result
.Current_Length
:= Length
;
1395 for J
in 1 .. Count
loop
1396 Result
.Data
(Indx
.. Indx
+ Item
'Length - 1) := Item
;
1397 Indx
:= Indx
+ Item
'Length;
1402 Result
.Current_Length
:= Max_Length
;
1405 when Strings
.Right
=>
1408 while Indx
+ Item
'Length <= Max_Length
+ 1 loop
1409 Result
.Data
(Indx
.. Indx
+ Item
'Length - 1) := Item
;
1410 Indx
:= Indx
+ Item
'Length;
1413 Result
.Data
(Indx
.. Max_Length
) :=
1414 Item
(Item
'First .. Item
'First + Max_Length
- Indx
);
1416 when Strings
.Left
=>
1419 while Indx
- Item
'Length >= 1 loop
1420 Result
.Data
(Indx
- (Item
'Length - 1) .. Indx
) := Item
;
1421 Indx
:= Indx
- Item
'Length;
1424 Result
.Data
(1 .. Indx
) :=
1425 Item
(Item
'Last - Indx
+ 1 .. Item
'Last);
1427 when Strings
.Error
=>
1428 raise Ada
.Strings
.Length_Error
;
1433 end Super_Replicate
;
1435 function Super_Replicate
1437 Item
: Super_String
;
1438 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1444 Item
.Data
(1 .. Item
.Current_Length
),
1447 end Super_Replicate
;
1453 function Super_Slice
1454 (Source
: Super_String
;
1456 High
: Natural) return Wide_Wide_String
1459 -- Note: test of High > Length is in accordance with AI95-00128
1461 if Low
> Source
.Current_Length
+ 1
1462 or else High
> Source
.Current_Length
1466 return Source
.Data
(Low
.. High
);
1470 function Super_Slice
1471 (Source
: Super_String
;
1473 High
: Natural) return Super_String
1475 Result
: Super_String
(Source
.Max_Length
);
1478 if Low
> Source
.Current_Length
+ 1
1479 or else High
> Source
.Current_Length
1483 Result
.Current_Length
:= High
- Low
+ 1;
1484 Result
.Data
(1 .. Result
.Current_Length
) := Source
.Data
(Low
.. High
);
1490 procedure Super_Slice
1491 (Source
: Super_String
;
1492 Target
: out Super_String
;
1497 if Low
> Source
.Current_Length
+ 1
1498 or else High
> Source
.Current_Length
1502 Target
.Current_Length
:= High
- Low
+ 1;
1503 Target
.Data
(1 .. Target
.Current_Length
) := Source
.Data
(Low
.. High
);
1512 (Source
: Super_String
;
1514 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
1515 Drop
: Strings
.Truncation
:= Strings
.Error
) return Super_String
1517 Max_Length
: constant Positive := Source
.Max_Length
;
1518 Result
: Super_String
(Max_Length
);
1519 Slen
: constant Natural := Source
.Current_Length
;
1520 Npad
: constant Integer := Count
- Slen
;
1524 Result
.Current_Length
:= Count
;
1525 Result
.Data
(1 .. Count
) :=
1526 Source
.Data
(Slen
- (Count
- 1) .. Slen
);
1528 elsif Count
<= Max_Length
then
1529 Result
.Current_Length
:= Count
;
1530 Result
.Data
(1 .. Npad
) := (others => Pad
);
1531 Result
.Data
(Npad
+ 1 .. Count
) := Source
.Data
(1 .. Slen
);
1534 Result
.Current_Length
:= Max_Length
;
1537 when Strings
.Right
=>
1538 if Npad
>= Max_Length
then
1539 Result
.Data
:= (others => Pad
);
1542 Result
.Data
(1 .. Npad
) := (others => Pad
);
1543 Result
.Data
(Npad
+ 1 .. Max_Length
) :=
1544 Source
.Data
(1 .. Max_Length
- Npad
);
1547 when Strings
.Left
=>
1548 Result
.Data
(1 .. Max_Length
- Slen
) := (others => Pad
);
1549 Result
.Data
(Max_Length
- Slen
+ 1 .. Max_Length
) :=
1550 Source
.Data
(1 .. Slen
);
1552 when Strings
.Error
=>
1553 raise Ada
.Strings
.Length_Error
;
1560 procedure Super_Tail
1561 (Source
: in out Super_String
;
1563 Pad
: Wide_Wide_Character
:= Wide_Wide_Space
;
1564 Drop
: Truncation
:= Error
)
1566 Max_Length
: constant Positive := Source
.Max_Length
;
1567 Slen
: constant Natural := Source
.Current_Length
;
1568 Npad
: constant Integer := Count
- Slen
;
1570 Temp
: constant Wide_Wide_String
(1 .. Max_Length
) := Source
.Data
;
1574 Source
.Current_Length
:= Count
;
1575 Source
.Data
(1 .. Count
) :=
1576 Temp
(Slen
- (Count
- 1) .. Slen
);
1578 elsif Count
<= Max_Length
then
1579 Source
.Current_Length
:= Count
;
1580 Source
.Data
(1 .. Npad
) := (others => Pad
);
1581 Source
.Data
(Npad
+ 1 .. Count
) := Temp
(1 .. Slen
);
1584 Source
.Current_Length
:= Max_Length
;
1587 when Strings
.Right
=>
1588 if Npad
>= Max_Length
then
1589 Source
.Data
:= (others => Pad
);
1592 Source
.Data
(1 .. Npad
) := (others => Pad
);
1593 Source
.Data
(Npad
+ 1 .. Max_Length
) :=
1594 Temp
(1 .. Max_Length
- Npad
);
1597 when Strings
.Left
=>
1598 for J
in 1 .. Max_Length
- Slen
loop
1599 Source
.Data
(J
) := Pad
;
1602 Source
.Data
(Max_Length
- Slen
+ 1 .. Max_Length
) :=
1605 when Strings
.Error
=>
1606 raise Ada
.Strings
.Length_Error
;
1611 ---------------------
1612 -- Super_To_String --
1613 ---------------------
1615 function Super_To_String
1616 (Source
: Super_String
) return Wide_Wide_String
1619 return Source
.Data
(1 .. Source
.Current_Length
);
1620 end Super_To_String
;
1622 ---------------------
1623 -- Super_Translate --
1624 ---------------------
1626 function Super_Translate
1627 (Source
: Super_String
;
1628 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
)
1631 Result
: Super_String
(Source
.Max_Length
);
1634 Result
.Current_Length
:= Source
.Current_Length
;
1636 for J
in 1 .. Source
.Current_Length
loop
1637 Result
.Data
(J
) := Value
(Mapping
, Source
.Data
(J
));
1641 end Super_Translate
;
1643 procedure Super_Translate
1644 (Source
: in out Super_String
;
1645 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping
)
1648 for J
in 1 .. Source
.Current_Length
loop
1649 Source
.Data
(J
) := Value
(Mapping
, Source
.Data
(J
));
1651 end Super_Translate
;
1653 function Super_Translate
1654 (Source
: Super_String
;
1655 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
1658 Result
: Super_String
(Source
.Max_Length
);
1661 Result
.Current_Length
:= Source
.Current_Length
;
1663 for J
in 1 .. Source
.Current_Length
loop
1664 Result
.Data
(J
) := Mapping
.all (Source
.Data
(J
));
1668 end Super_Translate
;
1670 procedure Super_Translate
1671 (Source
: in out Super_String
;
1672 Mapping
: Wide_Wide_Maps
.Wide_Wide_Character_Mapping_Function
)
1675 for J
in 1 .. Source
.Current_Length
loop
1676 Source
.Data
(J
) := Mapping
.all (Source
.Data
(J
));
1678 end Super_Translate
;
1685 (Source
: Super_String
;
1686 Side
: Trim_End
) return Super_String
1688 Result
: Super_String
(Source
.Max_Length
);
1689 Last
: Natural := Source
.Current_Length
;
1690 First
: Positive := 1;
1693 if Side
= Left
or else Side
= Both
then
1694 while First
<= Last
and then Source
.Data
(First
) = ' ' loop
1699 if Side
= Right
or else Side
= Both
then
1700 while Last
>= First
and then Source
.Data
(Last
) = ' ' loop
1705 Result
.Current_Length
:= Last
- First
+ 1;
1706 Result
.Data
(1 .. Result
.Current_Length
) := Source
.Data
(First
.. Last
);
1710 procedure Super_Trim
1711 (Source
: in out Super_String
;
1714 Max_Length
: constant Positive := Source
.Max_Length
;
1715 Last
: Natural := Source
.Current_Length
;
1716 First
: Positive := 1;
1717 Temp
: Wide_Wide_String
(1 .. Max_Length
);
1720 Temp
(1 .. Last
) := Source
.Data
(1 .. Last
);
1722 if Side
= Left
or else Side
= Both
then
1723 while First
<= Last
and then Temp
(First
) = ' ' loop
1728 if Side
= Right
or else Side
= Both
then
1729 while Last
>= First
and then Temp
(Last
) = ' ' loop
1734 Source
.Data
:= (others => Wide_Wide_NUL
);
1735 Source
.Current_Length
:= Last
- First
+ 1;
1736 Source
.Data
(1 .. Source
.Current_Length
) := Temp
(First
.. Last
);
1740 (Source
: Super_String
;
1741 Left
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
1742 Right
: Wide_Wide_Maps
.Wide_Wide_Character_Set
) return Super_String
1744 Result
: Super_String
(Source
.Max_Length
);
1747 for First
in 1 .. Source
.Current_Length
loop
1748 if not Is_In
(Source
.Data
(First
), Left
) then
1749 for Last
in reverse First
.. Source
.Current_Length
loop
1750 if not Is_In
(Source
.Data
(Last
), Right
) then
1751 Result
.Current_Length
:= Last
- First
+ 1;
1752 Result
.Data
(1 .. Result
.Current_Length
) :=
1753 Source
.Data
(First
.. Last
);
1760 Result
.Current_Length
:= 0;
1764 procedure Super_Trim
1765 (Source
: in out Super_String
;
1766 Left
: Wide_Wide_Maps
.Wide_Wide_Character_Set
;
1767 Right
: Wide_Wide_Maps
.Wide_Wide_Character_Set
)
1770 for First
in 1 .. Source
.Current_Length
loop
1771 if not Is_In
(Source
.Data
(First
), Left
) then
1772 for Last
in reverse First
.. Source
.Current_Length
loop
1773 if not Is_In
(Source
.Data
(Last
), Right
) then
1775 Source
.Current_Length
:= Last
;
1778 Source
.Current_Length
:= Last
- First
+ 1;
1779 Source
.Data
(1 .. Source
.Current_Length
) :=
1780 Source
.Data
(First
.. Last
);
1782 for J
in Source
.Current_Length
+ 1 ..
1785 Source
.Data
(J
) := Wide_Wide_NUL
;
1793 Source
.Current_Length
:= 0;
1798 Source
.Current_Length
:= 0;
1807 Right
: Wide_Wide_Character
;
1808 Max_Length
: Positive) return Super_String
1810 Result
: Super_String
(Max_Length
);
1813 if Left
> Max_Length
then
1814 raise Ada
.Strings
.Length_Error
;
1817 Result
.Current_Length
:= Left
;
1819 for J
in 1 .. Left
loop
1820 Result
.Data
(J
) := Right
;
1829 Right
: Wide_Wide_String
;
1830 Max_Length
: Positive) return Super_String
1832 Result
: Super_String
(Max_Length
);
1833 Pos
: Positive := 1;
1834 Rlen
: constant Natural := Right
'Length;
1835 Nlen
: constant Natural := Left
* Rlen
;
1838 if Nlen
> Max_Length
then
1839 raise Ada
.Strings
.Index_Error
;
1842 Result
.Current_Length
:= Nlen
;
1845 for J
in 1 .. Left
loop
1846 Result
.Data
(Pos
.. Pos
+ Rlen
- 1) := Right
;
1857 Right
: Super_String
) return Super_String
1859 Result
: Super_String
(Right
.Max_Length
);
1860 Pos
: Positive := 1;
1861 Rlen
: constant Natural := Right
.Current_Length
;
1862 Nlen
: constant Natural := Left
* Rlen
;
1865 if Nlen
> Right
.Max_Length
then
1866 raise Ada
.Strings
.Length_Error
;
1869 Result
.Current_Length
:= Nlen
;
1872 for J
in 1 .. Left
loop
1873 Result
.Data
(Pos
.. Pos
+ Rlen
- 1) :=
1874 Right
.Data
(1 .. Rlen
);
1883 ---------------------
1884 -- To_Super_String --
1885 ---------------------
1887 function To_Super_String
1888 (Source
: Wide_Wide_String
;
1889 Max_Length
: Natural;
1890 Drop
: Truncation
:= Error
) return Super_String
1892 Result
: Super_String
(Max_Length
);
1893 Slen
: constant Natural := Source
'Length;
1896 if Slen
<= Max_Length
then
1897 Result
.Current_Length
:= Slen
;
1898 Result
.Data
(1 .. Slen
) := Source
;
1902 when Strings
.Right
=>
1903 Result
.Current_Length
:= Max_Length
;
1904 Result
.Data
(1 .. Max_Length
) :=
1905 Source
(Source
'First .. Source
'First - 1 + Max_Length
);
1907 when Strings
.Left
=>
1908 Result
.Current_Length
:= Max_Length
;
1909 Result
.Data
(1 .. Max_Length
) :=
1910 Source
(Source
'Last - (Max_Length
- 1) .. Source
'Last);
1912 when Strings
.Error
=>
1913 raise Ada
.Strings
.Length_Error
;
1918 end To_Super_String
;
1920 end Ada
.Strings
.Wide_Wide_Superbounded
;