In gcc/testsuite/: 2010-09-30 Nicola Pero <nicola.pero@meta-innovation.com>
[official-gcc.git] / gcc / ada / a-stzsup.adb
blob7eca54d3cfa58cb9e3bbb9a509a5368bdd99f640
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
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 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2003-2009, Free Software Foundation, Inc. --
10 -- --
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. --
17 -- --
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. --
21 -- --
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/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
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
37 ------------
38 -- Concat --
39 ------------
41 function Concat
42 (Left : Super_String;
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;
50 begin
51 if Nlen > Left.Max_Length then
52 raise Ada.Strings.Length_Error;
53 else
54 Result.Current_Length := Nlen;
55 Result.Data (1 .. Llen) := Left.Data (1 .. Llen);
56 Result.Data (Llen + 1 .. Nlen) := Right.Data (1 .. Rlen);
57 end if;
59 return Result;
60 end Concat;
62 function Concat
63 (Left : Super_String;
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;
71 begin
72 if Nlen > Left.Max_Length then
73 raise Ada.Strings.Length_Error;
74 else
75 Result.Current_Length := Nlen;
76 Result.Data (1 .. Llen) := Left.Data (1 .. Llen);
77 Result.Data (Llen + 1 .. Nlen) := Right;
78 end if;
79 return Result;
80 end Concat;
82 function Concat
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;
91 begin
92 if Nlen > Right.Max_Length then
93 raise Ada.Strings.Length_Error;
94 else
95 Result.Current_Length := Nlen;
96 Result.Data (1 .. Llen) := Left;
97 Result.Data (Llen + 1 .. Nlen) := Right.Data (1 .. Rlen);
98 end if;
100 return Result;
101 end Concat;
103 function Concat
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;
110 begin
111 if Llen = Left.Max_Length then
112 raise Ada.Strings.Length_Error;
113 else
114 Result.Current_Length := Llen + 1;
115 Result.Data (1 .. Llen) := Left.Data (1 .. Llen);
116 Result.Data (Result.Current_Length) := Right;
117 end if;
119 return Result;
120 end Concat;
122 function Concat
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;
129 begin
130 if Rlen = Right.Max_Length then
131 raise Ada.Strings.Length_Error;
132 else
133 Result.Current_Length := Rlen + 1;
134 Result.Data (1) := Left;
135 Result.Data (2 .. Result.Current_Length) := Right.Data (1 .. Rlen);
136 end if;
138 return Result;
139 end Concat;
141 -----------
142 -- Equal --
143 -----------
145 function "="
146 (Left : Super_String;
147 Right : Super_String) return Boolean
149 begin
150 return Left.Current_Length = Right.Current_Length
151 and then Left.Data (1 .. Left.Current_Length) =
152 Right.Data (1 .. Right.Current_Length);
153 end "=";
155 function Equal
156 (Left : Super_String;
157 Right : Wide_Wide_String) return Boolean
159 begin
160 return Left.Current_Length = Right'Length
161 and then Left.Data (1 .. Left.Current_Length) = Right;
162 end Equal;
164 function Equal
165 (Left : Wide_Wide_String;
166 Right : Super_String) return Boolean
168 begin
169 return Left'Length = Right.Current_Length
170 and then Left = Right.Data (1 .. Right.Current_Length);
171 end Equal;
173 -------------
174 -- Greater --
175 -------------
177 function Greater
178 (Left : Super_String;
179 Right : Super_String) return Boolean
181 begin
182 return Left.Data (1 .. Left.Current_Length) >
183 Right.Data (1 .. Right.Current_Length);
184 end Greater;
186 function Greater
187 (Left : Super_String;
188 Right : Wide_Wide_String) return Boolean
190 begin
191 return Left.Data (1 .. Left.Current_Length) > Right;
192 end Greater;
194 function Greater
195 (Left : Wide_Wide_String;
196 Right : Super_String) return Boolean
198 begin
199 return Left > Right.Data (1 .. Right.Current_Length);
200 end Greater;
202 ----------------------
203 -- Greater_Or_Equal --
204 ----------------------
206 function Greater_Or_Equal
207 (Left : Super_String;
208 Right : Super_String) return Boolean
210 begin
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
219 begin
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
227 begin
228 return Left >= Right.Data (1 .. Right.Current_Length);
229 end Greater_Or_Equal;
231 ----------
232 -- Less --
233 ----------
235 function Less
236 (Left : Super_String;
237 Right : Super_String) return Boolean
239 begin
240 return Left.Data (1 .. Left.Current_Length) <
241 Right.Data (1 .. Right.Current_Length);
242 end Less;
244 function Less
245 (Left : Super_String;
246 Right : Wide_Wide_String) return Boolean
248 begin
249 return Left.Data (1 .. Left.Current_Length) < Right;
250 end Less;
252 function Less
253 (Left : Wide_Wide_String;
254 Right : Super_String) return Boolean
256 begin
257 return Left < Right.Data (1 .. Right.Current_Length);
258 end Less;
260 -------------------
261 -- Less_Or_Equal --
262 -------------------
264 function Less_Or_Equal
265 (Left : Super_String;
266 Right : Super_String) return Boolean
268 begin
269 return Left.Data (1 .. Left.Current_Length) <=
270 Right.Data (1 .. Right.Current_Length);
271 end Less_Or_Equal;
273 function Less_Or_Equal
274 (Left : Super_String;
275 Right : Wide_Wide_String) return Boolean
277 begin
278 return Left.Data (1 .. Left.Current_Length) <= Right;
279 end Less_Or_Equal;
281 function Less_Or_Equal
282 (Left : Wide_Wide_String;
283 Right : Super_String) return Boolean
285 begin
286 return Left <= Right.Data (1 .. Right.Current_Length);
287 end Less_Or_Equal;
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;
301 begin
302 if Slen <= Max_Length then
303 Target.Current_Length := Slen;
304 Target.Data (1 .. Slen) := Source;
306 else
307 case Drop is
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);
313 when Strings.Left =>
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;
320 end case;
321 end if;
322 end Set_Super_String;
324 ------------------
325 -- Super_Append --
326 ------------------
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;
341 begin
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);
347 else
348 Result.Current_Length := Max_Length;
350 case Drop is
351 when Strings.Right =>
352 if Llen >= Max_Length then -- only case is Llen = Max_Length
353 Result.Data := Left.Data;
355 else
356 Result.Data (1 .. Llen) := Left.Data (1 .. Llen);
357 Result.Data (Llen + 1 .. Max_Length) :=
358 Right.Data (1 .. Max_Length - Llen);
359 end if;
361 when Strings.Left =>
362 if Rlen >= Max_Length then -- only case is Rlen = Max_Length
363 Result.Data := Right.Data;
365 else
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);
370 end if;
372 when Strings.Error =>
373 raise Ada.Strings.Length_Error;
374 end case;
375 end if;
377 return Result;
378 end Super_Append;
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;
390 begin
391 if Nlen <= Max_Length then
392 Source.Current_Length := Nlen;
393 Source.Data (Llen + 1 .. Nlen) := New_Item.Data (1 .. Rlen);
395 else
396 Source.Current_Length := Max_Length;
398 case Drop is
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);
403 end if;
405 when Strings.Left =>
406 if Rlen >= Max_Length then -- only case is Rlen = Max_Length
407 Source.Data := New_Item.Data;
409 else
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);
414 end if;
416 when Strings.Error =>
417 raise Ada.Strings.Length_Error;
418 end case;
419 end if;
421 end Super_Append;
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;
436 begin
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;
442 else
443 Result.Current_Length := Max_Length;
445 case Drop is
446 when Strings.Right =>
447 if Llen >= Max_Length then -- only case is Llen = Max_Length
448 Result.Data := Left.Data;
450 else
451 Result.Data (1 .. Llen) := Left.Data (1 .. Llen);
452 Result.Data (Llen + 1 .. Max_Length) :=
453 Right (Right'First .. Right'First - 1 +
454 Max_Length - Llen);
456 end if;
458 when Strings.Left =>
459 if Rlen >= Max_Length then
460 Result.Data (1 .. Max_Length) :=
461 Right (Right'Last - (Max_Length - 1) .. Right'Last);
463 else
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) :=
467 Right;
468 end if;
470 when Strings.Error =>
471 raise Ada.Strings.Length_Error;
472 end case;
473 end if;
475 return Result;
476 end Super_Append;
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;
488 begin
489 if Nlen <= Max_Length then
490 Source.Current_Length := Nlen;
491 Source.Data (Llen + 1 .. Nlen) := New_Item;
493 else
494 Source.Current_Length := Max_Length;
496 case Drop is
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);
502 end if;
504 when Strings.Left =>
505 if Rlen >= Max_Length then
506 Source.Data (1 .. Max_Length) :=
507 New_Item (New_Item'Last - (Max_Length - 1) ..
508 New_Item'Last);
510 else
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) :=
514 New_Item;
515 end if;
517 when Strings.Error =>
518 raise Ada.Strings.Length_Error;
519 end case;
520 end if;
522 end Super_Append;
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;
537 begin
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);
543 else
544 Result.Current_Length := Max_Length;
546 case Drop is
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));
552 else
553 Result.Data (1 .. Llen) := Left;
554 Result.Data (Llen + 1 .. Max_Length) :=
555 Right.Data (1 .. Max_Length - Llen);
556 end if;
558 when Strings.Left =>
559 if Rlen >= Max_Length then
560 Result.Data (1 .. Max_Length) :=
561 Right.Data (Rlen - (Max_Length - 1) .. Rlen);
563 else
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);
568 end if;
570 when Strings.Error =>
571 raise Ada.Strings.Length_Error;
572 end case;
573 end if;
575 return Result;
576 end Super_Append;
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;
589 begin
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;
594 return Result;
596 else
597 case Drop is
598 when Strings.Right =>
599 return Left;
601 when Strings.Left =>
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;
606 return Result;
608 when Strings.Error =>
609 raise Ada.Strings.Length_Error;
610 end case;
611 end if;
612 end Super_Append;
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;
622 begin
623 if Llen < Max_Length then
624 Source.Current_Length := Llen + 1;
625 Source.Data (Llen + 1) := New_Item;
627 else
628 Source.Current_Length := Max_Length;
630 case Drop is
631 when Strings.Right =>
632 null;
634 when Strings.Left =>
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;
641 end case;
642 end if;
644 end Super_Append;
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;
657 begin
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);
662 return Result;
664 else
665 case Drop is
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);
671 return Result;
673 when Strings.Left =>
674 return Right;
676 when Strings.Error =>
677 raise Ada.Strings.Length_Error;
678 end case;
679 end if;
680 end Super_Append;
682 -----------------
683 -- Super_Count --
684 -----------------
686 function Super_Count
687 (Source : Super_String;
688 Pattern : Wide_Wide_String;
689 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
690 Wide_Wide_Maps.Identity)
691 return Natural
693 begin
694 return
695 Wide_Wide_Search.Count
696 (Source.Data (1 .. Source.Current_Length), Pattern, Mapping);
697 end Super_Count;
699 function Super_Count
700 (Source : Super_String;
701 Pattern : Wide_Wide_String;
702 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
703 return Natural
705 begin
706 return
707 Wide_Wide_Search.Count
708 (Source.Data (1 .. Source.Current_Length), Pattern, Mapping);
709 end Super_Count;
711 function Super_Count
712 (Source : Super_String;
713 Set : Wide_Wide_Maps.Wide_Wide_Character_Set) return Natural
715 begin
716 return Wide_Wide_Search.Count
717 (Source.Data (1 .. Source.Current_Length), Set);
718 end Super_Count;
720 ------------------
721 -- Super_Delete --
722 ------------------
724 function Super_Delete
725 (Source : Super_String;
726 From : Positive;
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;
733 begin
734 if Num_Delete <= 0 then
735 return Source;
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);
743 return Result;
745 else
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);
750 return Result;
751 end if;
752 end Super_Delete;
754 procedure Super_Delete
755 (Source : in out Super_String;
756 From : Positive;
757 Through : Natural)
759 Slen : constant Natural := Source.Current_Length;
760 Num_Delete : constant Integer := Through - From + 1;
762 begin
763 if Num_Delete <= 0 then
764 return;
766 elsif From > Slen + 1 then
767 raise Ada.Strings.Index_Error;
769 elsif Through >= Slen then
770 Source.Current_Length := From - 1;
772 else
773 Source.Current_Length := Slen - Num_Delete;
774 Source.Data (From .. Source.Current_Length) :=
775 Source.Data (Through + 1 .. Slen);
776 end if;
777 end Super_Delete;
779 -------------------
780 -- Super_Element --
781 -------------------
783 function Super_Element
784 (Source : Super_String;
785 Index : Positive) return Wide_Wide_Character
787 begin
788 if Index <= Source.Current_Length then
789 return Source.Data (Index);
790 else
791 raise Strings.Index_Error;
792 end if;
793 end Super_Element;
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;
804 Last : out Natural)
806 begin
807 Wide_Wide_Search.Find_Token
808 (Source.Data (1 .. Source.Current_Length), Set, Test, First, Last);
809 end Super_Find_Token;
811 ----------------
812 -- Super_Head --
813 ----------------
815 function Super_Head
816 (Source : Super_String;
817 Count : Natural;
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;
826 begin
827 if Npad <= 0 then
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);
836 else
837 Result.Current_Length := Max_Length;
839 case Drop is
840 when Strings.Right =>
841 Result.Data (1 .. Slen) := Source.Data (1 .. Slen);
842 Result.Data (Slen + 1 .. Max_Length) := (others => Pad);
844 when Strings.Left =>
845 if Npad >= Max_Length then
846 Result.Data := (others => Pad);
848 else
849 Result.Data (1 .. Max_Length - Npad) :=
850 Source.Data (Count - Max_Length + 1 .. Slen);
851 Result.Data (Max_Length - Npad + 1 .. Max_Length) :=
852 (others => Pad);
853 end if;
855 when Strings.Error =>
856 raise Ada.Strings.Length_Error;
857 end case;
858 end if;
860 return Result;
861 end Super_Head;
863 procedure Super_Head
864 (Source : in out Super_String;
865 Count : Natural;
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);
874 begin
875 if Npad <= 0 then
876 Source.Current_Length := Count;
878 elsif Count <= Max_Length then
879 Source.Current_Length := Count;
880 Source.Data (Slen + 1 .. Count) := (others => Pad);
882 else
883 Source.Current_Length := Max_Length;
885 case Drop is
886 when Strings.Right =>
887 Source.Data (Slen + 1 .. Max_Length) := (others => Pad);
889 when Strings.Left =>
890 if Npad > Max_Length then
891 Source.Data := (others => Pad);
893 else
894 Temp := Source.Data;
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;
900 end loop;
901 end if;
903 when Strings.Error =>
904 raise Ada.Strings.Length_Error;
905 end case;
906 end if;
907 end Super_Head;
909 -----------------
910 -- Super_Index --
911 -----------------
913 function Super_Index
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)
919 return Natural
921 begin
922 return Wide_Wide_Search.Index
923 (Source.Data (1 .. Source.Current_Length), Pattern, Going, Mapping);
924 end Super_Index;
926 function Super_Index
927 (Source : Super_String;
928 Pattern : Wide_Wide_String;
929 Going : Direction := Forward;
930 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
931 return Natural
933 begin
934 return Wide_Wide_Search.Index
935 (Source.Data (1 .. Source.Current_Length), Pattern, Going, Mapping);
936 end Super_Index;
938 function Super_Index
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
944 begin
945 return Wide_Wide_Search.Index
946 (Source.Data (1 .. Source.Current_Length), Set, Test, Going);
947 end Super_Index;
949 function Super_Index
950 (Source : Super_String;
951 Pattern : Wide_Wide_String;
952 From : Positive;
953 Going : Direction := Forward;
954 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
955 Wide_Wide_Maps.Identity)
956 return Natural
958 begin
959 return Wide_Wide_Search.Index
960 (Source.Data (1 .. Source.Current_Length),
961 Pattern, From, Going, Mapping);
962 end Super_Index;
964 function Super_Index
965 (Source : Super_String;
966 Pattern : Wide_Wide_String;
967 From : Positive;
968 Going : Direction := Forward;
969 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
970 return Natural
972 begin
973 return Wide_Wide_Search.Index
974 (Source.Data (1 .. Source.Current_Length),
975 Pattern, From, Going, Mapping);
976 end Super_Index;
978 function Super_Index
979 (Source : Super_String;
980 Set : Wide_Wide_Maps.Wide_Wide_Character_Set;
981 From : Positive;
982 Test : Membership := Inside;
983 Going : Direction := Forward) return Natural
985 begin
986 return Wide_Wide_Search.Index
987 (Source.Data (1 .. Source.Current_Length), Set, From, Test, Going);
988 end Super_Index;
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
998 begin
999 return
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;
1006 From : Positive;
1007 Going : Direction := Forward) return Natural
1009 begin
1010 return
1011 Wide_Wide_Search.Index_Non_Blank
1012 (Source.Data (1 .. Source.Current_Length), From, Going);
1013 end Super_Index_Non_Blank;
1015 ------------------
1016 -- Super_Insert --
1017 ------------------
1019 function Super_Insert
1020 (Source : Super_String;
1021 Before : Positive;
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
1036 -- source string.
1038 begin
1039 if Alen < 0 then
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);
1049 else
1050 Result.Current_Length := Max_Length;
1052 case Drop is
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);
1060 else
1061 Result.Data (Before .. Before + Nlen - 1) := New_Item;
1062 Result.Data (Before + Nlen .. Max_Length) :=
1063 Source.Data (Before .. Slen - Droplen);
1064 end if;
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
1073 .. New_Item'Last);
1074 else
1075 Result.Data
1076 (Blen - Droplen + 1 .. Max_Length - Alen) :=
1077 New_Item;
1078 Result.Data (1 .. Blen - Droplen) :=
1079 Source.Data (Droplen + 1 .. Blen);
1080 end if;
1082 when Strings.Error =>
1083 raise Ada.Strings.Length_Error;
1084 end case;
1085 end if;
1087 return Result;
1088 end Super_Insert;
1090 procedure Super_Insert
1091 (Source : in out Super_String;
1092 Before : Positive;
1093 New_Item : Wide_Wide_String;
1094 Drop : Strings.Truncation := Strings.Error)
1096 begin
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);
1102 end Super_Insert;
1104 ------------------
1105 -- Super_Length --
1106 ------------------
1108 function Super_Length (Source : Super_String) return Natural is
1109 begin
1110 return Source.Current_Length;
1111 end Super_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;
1127 Droplen : Natural;
1129 begin
1130 if Position > Slen + 1 then
1131 raise Ada.Strings.Index_Error;
1133 elsif New_Item'Length = 0 then
1134 return Source;
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;
1140 return Result;
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;
1146 return Result;
1148 else
1149 Result.Current_Length := Max_Length;
1150 Droplen := Endpos - Max_Length;
1152 case Drop is
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);
1159 return Result;
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 ..
1165 New_Item'Last);
1166 return Result;
1168 else
1169 Result.Data (1 .. Max_Length - New_Item'Length) :=
1170 Source.Data (Droplen + 1 .. Position - 1);
1171 Result.Data
1172 (Max_Length - New_Item'Length + 1 .. Max_Length) :=
1173 New_Item;
1174 return Result;
1175 end if;
1177 when Strings.Error =>
1178 raise Ada.Strings.Length_Error;
1179 end case;
1180 end if;
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;
1192 Droplen : Natural;
1194 begin
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;
1205 else
1206 Source.Current_Length := Max_Length;
1207 Droplen := Endpos - Max_Length;
1209 case Drop is
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 ..
1218 New_Item'Last);
1220 else
1221 Source.Data (1 .. Max_Length - New_Item'Length) :=
1222 Source.Data (Droplen + 1 .. Position - 1);
1224 Source.Data
1225 (Max_Length - New_Item'Length + 1 .. Max_Length) :=
1226 New_Item;
1227 end if;
1229 when Strings.Error =>
1230 raise Ada.Strings.Length_Error;
1231 end case;
1232 end if;
1233 end Super_Overwrite;
1235 ---------------------------
1236 -- Super_Replace_Element --
1237 ---------------------------
1239 procedure Super_Replace_Element
1240 (Source : in out Super_String;
1241 Index : Positive;
1242 By : Wide_Wide_Character)
1244 begin
1245 if Index <= Source.Current_Length then
1246 Source.Data (Index) := By;
1247 else
1248 raise Ada.Strings.Index_Error;
1249 end if;
1250 end Super_Replace_Element;
1252 -------------------------
1253 -- Super_Replace_Slice --
1254 -------------------------
1256 function Super_Replace_Slice
1257 (Source : Super_String;
1258 Low : Positive;
1259 High : Natural;
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;
1266 begin
1267 if Low > Slen + 1 then
1268 raise Strings.Index_Error;
1270 elsif High < Low then
1271 return Super_Insert (Source, Low, By, Drop);
1273 else
1274 declare
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.
1286 begin
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);
1294 else
1295 Result.Current_Length := Max_Length;
1297 case Drop is
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);
1304 else
1305 Result.Data (Low .. Low + By'Length - 1) := By;
1306 Result.Data (Low + By'Length .. Max_Length) :=
1307 Source.Data (High + 1 .. Slen - Droplen);
1308 end if;
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);
1317 else
1318 Result.Data
1319 (Blen - Droplen + 1 .. Max_Length - Alen) := By;
1320 Result.Data (1 .. Blen - Droplen) :=
1321 Source.Data (Droplen + 1 .. Blen);
1322 end if;
1324 when Strings.Error =>
1325 raise Ada.Strings.Length_Error;
1326 end case;
1327 end if;
1329 return Result;
1330 end;
1331 end if;
1332 end Super_Replace_Slice;
1334 procedure Super_Replace_Slice
1335 (Source : in out Super_String;
1336 Low : Positive;
1337 High : Natural;
1338 By : Wide_Wide_String;
1339 Drop : Strings.Truncation := Strings.Error)
1341 begin
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
1354 (Count : Natural;
1355 Item : Wide_Wide_Character;
1356 Drop : Truncation := Error;
1357 Max_Length : Positive) return Super_String
1359 Result : Super_String (Max_Length);
1361 begin
1362 if Count <= Max_Length then
1363 Result.Current_Length := Count;
1365 elsif Drop = Strings.Error then
1366 raise Ada.Strings.Length_Error;
1368 else
1369 Result.Current_Length := Max_Length;
1370 end if;
1372 Result.Data (1 .. Result.Current_Length) := (others => Item);
1373 return Result;
1374 end Super_Replicate;
1376 function Super_Replicate
1377 (Count : Natural;
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);
1384 Indx : Positive;
1386 begin
1387 if Length <= Max_Length then
1388 Result.Current_Length := Length;
1390 if Length > 0 then
1391 Indx := 1;
1393 for J in 1 .. Count loop
1394 Result.Data (Indx .. Indx + Item'Length - 1) := Item;
1395 Indx := Indx + Item'Length;
1396 end loop;
1397 end if;
1399 else
1400 Result.Current_Length := Max_Length;
1402 case Drop is
1403 when Strings.Right =>
1404 Indx := 1;
1406 while Indx + Item'Length <= Max_Length + 1 loop
1407 Result.Data (Indx .. Indx + Item'Length - 1) := Item;
1408 Indx := Indx + Item'Length;
1409 end loop;
1411 Result.Data (Indx .. Max_Length) :=
1412 Item (Item'First .. Item'First + Max_Length - Indx);
1414 when Strings.Left =>
1415 Indx := Max_Length;
1417 while Indx - Item'Length >= 1 loop
1418 Result.Data (Indx - (Item'Length - 1) .. Indx) := Item;
1419 Indx := Indx - Item'Length;
1420 end loop;
1422 Result.Data (1 .. Indx) :=
1423 Item (Item'Last - Indx + 1 .. Item'Last);
1425 when Strings.Error =>
1426 raise Ada.Strings.Length_Error;
1427 end case;
1428 end if;
1430 return Result;
1431 end Super_Replicate;
1433 function Super_Replicate
1434 (Count : Natural;
1435 Item : Super_String;
1436 Drop : Strings.Truncation := Strings.Error) return Super_String
1438 begin
1439 return
1440 Super_Replicate
1441 (Count,
1442 Item.Data (1 .. Item.Current_Length),
1443 Drop,
1444 Item.Max_Length);
1445 end Super_Replicate;
1447 -----------------
1448 -- Super_Slice --
1449 -----------------
1451 function Super_Slice
1452 (Source : Super_String;
1453 Low : Positive;
1454 High : Natural) return Wide_Wide_String
1456 begin
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
1461 then
1462 raise Index_Error;
1463 else
1464 return Source.Data (Low .. High);
1465 end if;
1466 end Super_Slice;
1468 function Super_Slice
1469 (Source : Super_String;
1470 Low : Positive;
1471 High : Natural) return Super_String
1473 Result : Super_String (Source.Max_Length);
1475 begin
1476 if Low > Source.Current_Length + 1
1477 or else High > Source.Current_Length
1478 then
1479 raise Index_Error;
1480 else
1481 Result.Current_Length := High - Low + 1;
1482 Result.Data (1 .. Result.Current_Length) := Source.Data (Low .. High);
1483 end if;
1485 return Result;
1486 end Super_Slice;
1488 procedure Super_Slice
1489 (Source : Super_String;
1490 Target : out Super_String;
1491 Low : Positive;
1492 High : Natural)
1494 begin
1495 if Low > Source.Current_Length + 1
1496 or else High > Source.Current_Length
1497 then
1498 raise Index_Error;
1499 else
1500 Target.Current_Length := High - Low + 1;
1501 Target.Data (1 .. Target.Current_Length) := Source.Data (Low .. High);
1502 end if;
1503 end Super_Slice;
1505 ----------------
1506 -- Super_Tail --
1507 ----------------
1509 function Super_Tail
1510 (Source : Super_String;
1511 Count : Natural;
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;
1520 begin
1521 if Npad <= 0 then
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);
1531 else
1532 Result.Current_Length := Max_Length;
1534 case Drop is
1535 when Strings.Right =>
1536 if Npad >= Max_Length then
1537 Result.Data := (others => Pad);
1539 else
1540 Result.Data (1 .. Npad) := (others => Pad);
1541 Result.Data (Npad + 1 .. Max_Length) :=
1542 Source.Data (1 .. Max_Length - Npad);
1543 end if;
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;
1552 end case;
1553 end if;
1555 return Result;
1556 end Super_Tail;
1558 procedure Super_Tail
1559 (Source : in out Super_String;
1560 Count : Natural;
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;
1570 begin
1571 if Npad <= 0 then
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);
1581 else
1582 Source.Current_Length := Max_Length;
1584 case Drop is
1585 when Strings.Right =>
1586 if Npad >= Max_Length then
1587 Source.Data := (others => Pad);
1589 else
1590 Source.Data (1 .. Npad) := (others => Pad);
1591 Source.Data (Npad + 1 .. Max_Length) :=
1592 Temp (1 .. Max_Length - Npad);
1593 end if;
1595 when Strings.Left =>
1596 for J in 1 .. Max_Length - Slen loop
1597 Source.Data (J) := Pad;
1598 end loop;
1600 Source.Data (Max_Length - Slen + 1 .. Max_Length) :=
1601 Temp (1 .. Slen);
1603 when Strings.Error =>
1604 raise Ada.Strings.Length_Error;
1605 end case;
1606 end if;
1607 end Super_Tail;
1609 ---------------------
1610 -- Super_To_String --
1611 ---------------------
1613 function Super_To_String
1614 (Source : Super_String) return Wide_Wide_String
1616 begin
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)
1627 return Super_String
1629 Result : Super_String (Source.Max_Length);
1631 begin
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));
1636 end loop;
1638 return Result;
1639 end Super_Translate;
1641 procedure Super_Translate
1642 (Source : in out Super_String;
1643 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping)
1645 begin
1646 for J in 1 .. Source.Current_Length loop
1647 Source.Data (J) := Value (Mapping, Source.Data (J));
1648 end loop;
1649 end Super_Translate;
1651 function Super_Translate
1652 (Source : Super_String;
1653 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
1654 return Super_String
1656 Result : Super_String (Source.Max_Length);
1658 begin
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));
1663 end loop;
1665 return Result;
1666 end Super_Translate;
1668 procedure Super_Translate
1669 (Source : in out Super_String;
1670 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
1672 begin
1673 for J in 1 .. Source.Current_Length loop
1674 Source.Data (J) := Mapping.all (Source.Data (J));
1675 end loop;
1676 end Super_Translate;
1678 ----------------
1679 -- Super_Trim --
1680 ----------------
1682 function Super_Trim
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;
1690 begin
1691 if Side = Left or else Side = Both then
1692 while First <= Last and then Source.Data (First) = ' ' loop
1693 First := First + 1;
1694 end loop;
1695 end if;
1697 if Side = Right or else Side = Both then
1698 while Last >= First and then Source.Data (Last) = ' ' loop
1699 Last := Last - 1;
1700 end loop;
1701 end if;
1703 Result.Current_Length := Last - First + 1;
1704 Result.Data (1 .. Result.Current_Length) := Source.Data (First .. Last);
1705 return Result;
1706 end Super_Trim;
1708 procedure Super_Trim
1709 (Source : in out Super_String;
1710 Side : Trim_End)
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);
1717 begin
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
1722 First := First + 1;
1723 end loop;
1724 end if;
1726 if Side = Right or else Side = Both then
1727 while Last >= First and then Temp (Last) = ' ' loop
1728 Last := Last - 1;
1729 end loop;
1730 end if;
1732 Source.Data := (others => Wide_Wide_NUL);
1733 Source.Current_Length := Last - First + 1;
1734 Source.Data (1 .. Source.Current_Length) := Temp (First .. Last);
1735 end Super_Trim;
1737 function Super_Trim
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);
1744 begin
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);
1752 return Result;
1753 end if;
1754 end loop;
1755 end if;
1756 end loop;
1758 Result.Current_Length := 0;
1759 return Result;
1760 end Super_Trim;
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)
1767 begin
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
1772 if First = 1 then
1773 Source.Current_Length := Last;
1774 return;
1775 else
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 ..
1781 Source.Max_Length
1782 loop
1783 Source.Data (J) := Wide_Wide_NUL;
1784 end loop;
1786 return;
1787 end if;
1788 end if;
1789 end loop;
1791 Source.Current_Length := 0;
1792 return;
1793 end if;
1794 end loop;
1796 Source.Current_Length := 0;
1797 end Super_Trim;
1799 -----------
1800 -- Times --
1801 -----------
1803 function Times
1804 (Left : Natural;
1805 Right : Wide_Wide_Character;
1806 Max_Length : Positive) return Super_String
1808 Result : Super_String (Max_Length);
1810 begin
1811 if Left > Max_Length then
1812 raise Ada.Strings.Length_Error;
1814 else
1815 Result.Current_Length := Left;
1817 for J in 1 .. Left loop
1818 Result.Data (J) := Right;
1819 end loop;
1820 end if;
1822 return Result;
1823 end Times;
1825 function Times
1826 (Left : Natural;
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;
1835 begin
1836 if Nlen > Max_Length then
1837 raise Ada.Strings.Index_Error;
1839 else
1840 Result.Current_Length := Nlen;
1842 if Nlen > 0 then
1843 for J in 1 .. Left loop
1844 Result.Data (Pos .. Pos + Rlen - 1) := Right;
1845 Pos := Pos + Rlen;
1846 end loop;
1847 end if;
1848 end if;
1850 return Result;
1851 end Times;
1853 function Times
1854 (Left : Natural;
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;
1862 begin
1863 if Nlen > Right.Max_Length then
1864 raise Ada.Strings.Length_Error;
1866 else
1867 Result.Current_Length := Nlen;
1869 if Nlen > 0 then
1870 for J in 1 .. Left loop
1871 Result.Data (Pos .. Pos + Rlen - 1) :=
1872 Right.Data (1 .. Rlen);
1873 Pos := Pos + Rlen;
1874 end loop;
1875 end if;
1876 end if;
1878 return Result;
1879 end Times;
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;
1893 begin
1894 if Slen <= Max_Length then
1895 Result.Current_Length := Slen;
1896 Result.Data (1 .. Slen) := Source;
1898 else
1899 case Drop is
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;
1912 end case;
1913 end if;
1915 return Result;
1916 end To_Super_String;
1918 end Ada.Strings.Wide_Wide_Superbounded;