Debian Codegraph @

gcc/ada/libgnat/a-strsup.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . S T R I N G S . S U P E R B O U N D E D --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2003-2025, 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 ------------------------------------------------------------------------------
31
32 -- Ghost code, loop (in)variants and assertions in this unit are meant for
33 -- analysis only, not for run-time checking, as it would be too costly
34 -- otherwise. This is enforced by setting the assertion policy to Ignore.
35
36 pragma Assertion_Policy (Ghost => Ignore,
37 Loop_Invariant => Ignore,
38 Loop_Variant => Ignore,
39 Assert => Ignore);
40
41 with Ada.Strings.Maps; use Ada.Strings.Maps;
42
43 package body Ada.Strings.Superbounded with SPARK_Mode is
44
45 ------------
46 -- Concat --
47 ------------
48
49 function Concat
50 (Left : Super_String;
51 Right : Super_String) return Super_String
52 is
53 begin
54 return Result : Super_String (Left.Max_Length) do
55 declare
56 Llen : constant Natural := Left.Current_Length;
57 Rlen : constant Natural := Right.Current_Length;
58 Nlen : constant Natural := Llen + Rlen;
59 begin
60 if Nlen > Left.Max_Length then
61 raise Ada.Strings.Length_Error;
62 end if;
63
64 Result.Data (1 .. Llen) := Left.Data (1 .. Llen);
65
66 if Rlen > 0 then
67 Result.Data (Llen + 1 .. Nlen) := Right.Data (1 .. Rlen);
68 end if;
69
70 Result.Current_Length := Nlen;
71 end;
72 end return;
73 end Concat;
74
75 function Concat
76 (Left : Super_String;
77 Right : String) return Super_String
78 is
79 begin
80 return Result : Super_String (Left.Max_Length) do
81 declare
82 Llen : constant Natural := Left.Current_Length;
83 Nlen : constant Natural := Llen + Right'Length;
84 begin
85 if Nlen > Left.Max_Length then
86 raise Ada.Strings.Length_Error;
87 end if;
88
89 Result.Data (1 .. Llen) := Left.Data (1 .. Llen);
90
91 if Right'Length > 0 then
92 Result.Data (Llen + 1 .. Nlen) := Super_String_Data (Right);
93 end if;
94
95 Result.Current_Length := Nlen;
96 end;
97 end return;
98 end Concat;
99
100 function Concat
101 (Left : String;
102 Right : Super_String) return Super_String
103 is
104
105 begin
106 return Result : Super_String (Right.Max_Length) do
107 declare
108 Llen : constant Natural := Left'Length;
109 Rlen : constant Natural := Right.Current_Length;
110 Nlen : constant Natural := Llen + Rlen;
111 begin
112 if Nlen > Right.Max_Length then
113 raise Ada.Strings.Length_Error;
114 end if;
115
116 Result.Data (1 .. Llen) := Super_String_Data (Left);
117
118 if Rlen > 0 then
119 Result.Data (Llen + 1 .. Nlen) := Right.Data (1 .. Rlen);
120 end if;
121
122 Result.Current_Length := Nlen;
123 end;
124 end return;
125 end Concat;
126
127 function Concat
128 (Left : Super_String;
129 Right : Character) return Super_String
130 is
131 begin
132 return Result : Super_String (Left.Max_Length) do
133 declare
134 Llen : constant Natural := Left.Current_Length;
135 begin
136 if Llen = Left.Max_Length then
137 raise Ada.Strings.Length_Error;
138 end if;
139
140 Result.Data (1 .. Llen) := Left.Data (1 .. Llen);
141 Result.Data (Llen + 1) := Right;
142 Result.Current_Length := Llen + 1;
143 end;
144 end return;
145 end Concat;
146
147 function Concat
148 (Left : Character;
149 Right : Super_String) return Super_String
150 is
151 begin
152 return Result : Super_String (Right.Max_Length) do
153 declare
154 Rlen : constant Natural := Right.Current_Length;
155 begin
156 if Rlen = Right.Max_Length then
157 raise Ada.Strings.Length_Error;
158 end if;
159
160 Result.Data (1) := Left;
161 Result.Data (2 .. Rlen + 1) := Right.Data (1 .. Rlen);
162 Result.Current_Length := Rlen + 1;
163 end;
164 end return;
165 end Concat;
166
167 -----------
168 -- Equal --
169 -----------
170
171 function "="
172 (Left : Super_String;
173 Right : Super_String) return Boolean
174 is
175 begin
176 return Super_To_String (Left) = Super_To_String (Right);
177 end "=";
178
179 function Equal
180 (Left : Super_String;
181 Right : String) return Boolean
182 is
183 begin
184 return Super_To_String (Left) = Right;
185 end Equal;
186
187 function Equal
188 (Left : String;
189 Right : Super_String) return Boolean
190 is
191 begin
192 return Left = Super_To_String (Right);
193 end Equal;
194
195 -------------
196 -- Greater --
197 -------------
198
199 function Greater
200 (Left : Super_String;
201 Right : Super_String) return Boolean
202 is
203 begin
204 return Super_To_String (Left) > Super_To_String (Right);
205 end Greater;
206
207 function Greater
208 (Left : Super_String;
209 Right : String) return Boolean
210 is
211 begin
212 return Super_To_String (Left) > Right;
213 end Greater;
214
215 function Greater
216 (Left : String;
217 Right : Super_String) return Boolean
218 is
219 begin
220 return Left > Super_To_String (Right);
221 end Greater;
222
223 ----------------------
224 -- Greater_Or_Equal --
225 ----------------------
226
227 function Greater_Or_Equal
228 (Left : Super_String;
229 Right : Super_String) return Boolean
230 is
231 begin
232 return Super_To_String (Left) >= Super_To_String (Right);
233 end Greater_Or_Equal;
234
235 function Greater_Or_Equal
236 (Left : Super_String;
237 Right : String) return Boolean
238 is
239 begin
240 return Super_To_String (Left) >= Right;
241 end Greater_Or_Equal;
242
243 function Greater_Or_Equal
244 (Left : String;
245 Right : Super_String) return Boolean
246 is
247 begin
248 return Left >= Super_To_String (Right);
249 end Greater_Or_Equal;
250
251 ----------
252 -- Less --
253 ----------
254
255 function Less
256 (Left : Super_String;
257 Right : Super_String) return Boolean
258 is
259 begin
260 return Super_To_String (Left) < Super_To_String (Right);
261 end Less;
262
263 function Less
264 (Left : Super_String;
265 Right : String) return Boolean
266 is
267 begin
268 return Super_To_String (Left) < Right;
269 end Less;
270
271 function Less
272 (Left : String;
273 Right : Super_String) return Boolean
274 is
275 begin
276 return Left < Super_To_String (Right);
277 end Less;
278
279 -------------------
280 -- Less_Or_Equal --
281 -------------------
282
283 function Less_Or_Equal
284 (Left : Super_String;
285 Right : Super_String) return Boolean
286 is
287 begin
288 return Super_To_String (Left) <= Super_To_String (Right);
289 end Less_Or_Equal;
290
291 function Less_Or_Equal
292 (Left : Super_String;
293 Right : String) return Boolean
294 is
295 begin
296 return Super_To_String (Left) <= Right;
297 end Less_Or_Equal;
298
299 function Less_Or_Equal
300 (Left : String;
301 Right : Super_String) return Boolean
302 is
303 begin
304 return Left <= Super_To_String (Right);
305 end Less_Or_Equal;
306
307 ---------------
308 -- Put_Image --
309 ---------------
310
311 procedure Put_Image
312 (S : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class;
313 Source : Super_String) is
314 begin
315 String'Put_Image (S, Super_To_String (Source));
316 end Put_Image;
317
318 ----------------------
319 -- Set_Super_String --
320 ----------------------
321
322 procedure Set_Super_String
323 (Target : out Super_String;
324 Source : String;
325 Drop : Truncation := Error)
326 is
327 Slen : constant Natural := Source'Length;
328 Max_Length : constant Positive := Target.Max_Length;
329
330 begin
331 if Slen <= Max_Length then
332 Target.Data (1 .. Slen) := Super_String_Data (Source);
333 Target.Current_Length := Slen;
334
335 else
336 case Drop is
337 when Strings.Right =>
338 Target.Data (1 .. Max_Length) := Super_String_Data
339 (Source (Source'First .. Source'First - 1 + Max_Length));
340 Target.Current_Length := Max_Length;
341
342 when Strings.Left =>
343 Target.Data (1 .. Max_Length) := Super_String_Data
344 (Source (Source'Last - (Max_Length - 1) .. Source'Last));
345 Target.Current_Length := Max_Length;
346
347 when Strings.Error =>
348 raise Ada.Strings.Length_Error;
349 end case;
350 end if;
351 end Set_Super_String;
352
353 ------------------
354 -- Super_Append --
355 ------------------
356
357 -- Case of Super_String and Super_String
358
359 function Super_Append
360 (Left : Super_String;
361 Right : Super_String;
362 Drop : Truncation := Error) return Super_String
363 is
364 Max_Length : constant Positive := Left.Max_Length;
365 Result : Super_String (Max_Length);
366 Llen : constant Natural := Left.Current_Length;
367 Rlen : constant Natural := Right.Current_Length;
368
369 begin
370 if Llen <= Max_Length - Rlen then
371 Result.Data (1 .. Llen) := Left.Data (1 .. Llen);
372
373 if Rlen > 0 then
374 Result.Data (Llen + 1 .. Llen + Rlen) := Right.Data (1 .. Rlen);
375 end if;
376
377 Result.Current_Length := Llen + Rlen;
378
379 else
380 case Drop is
381 when Strings.Right =>
382 if Llen >= Max_Length then -- only case is Llen = Max_Length
383 Result.Data := Left.Data;
384
385 else
386 Result.Data (1 .. Llen) := Left.Data (1 .. Llen);
387 Result.Data (Llen + 1 .. Max_Length) :=
388 Right.Data (1 .. Max_Length - Llen);
389 end if;
390
391 when Strings.Left =>
392 if Rlen >= Max_Length then -- only case is Rlen = Max_Length
393 Result.Data := Right.Data;
394
395 else
396 Result.Data (1 .. Max_Length - Rlen) :=
397 Left.Data (Llen - (Max_Length - Rlen - 1) .. Llen);
398 Result.Data (Max_Length - Rlen + 1 .. Max_Length) :=
399 Right.Data (1 .. Rlen);
400 end if;
401
402 when Strings.Error =>
403 raise Ada.Strings.Length_Error;
404 end case;
405
406 Result.Current_Length := Max_Length;
407 end if;
408
409 return Result;
410 end Super_Append;
411
412 procedure Super_Append
413 (Source : in out Super_String;
414 New_Item : Super_String;
415 Drop : Truncation := Error)
416 is
417 Max_Length : constant Positive := Source.Max_Length;
418 Llen : constant Natural := Source.Current_Length;
419 Rlen : constant Natural := New_Item.Current_Length;
420
421 begin
422 if Llen <= Max_Length - Rlen then
423 if Rlen > 0 then
424 Source.Data (Llen + 1 .. Llen + Rlen) := New_Item.Data (1 .. Rlen);
425 Source.Current_Length := Llen + Rlen;
426 end if;
427
428 else
429 case Drop is
430 when Strings.Right =>
431 if Llen < Max_Length then
432 Source.Data (Llen + 1 .. Max_Length) :=
433 New_Item.Data (1 .. Max_Length - Llen);
434 end if;
435
436 when Strings.Left =>
437 if Rlen >= Max_Length then -- only case is Rlen = Max_Length
438 Source.Data := New_Item.Data;
439
440 else
441 Source.Data (1 .. Max_Length - Rlen) :=
442 Source.Data (Llen - (Max_Length - Rlen - 1) .. Llen);
443 Source.Data (Max_Length - Rlen + 1 .. Max_Length) :=
444 New_Item.Data (1 .. Rlen);
445 end if;
446
447 when Strings.Error =>
448 raise Ada.Strings.Length_Error;
449 end case;
450
451 Source.Current_Length := Max_Length;
452 end if;
453
454 end Super_Append;
455
456 -- Case of Super_String and String
457
458 function Super_Append
459 (Left : Super_String;
460 Right : String;
461 Drop : Strings.Truncation := Strings.Error) return Super_String
462 is
463 Max_Length : constant Positive := Left.Max_Length;
464 Result : Super_String (Max_Length);
465 Llen : constant Natural := Left.Current_Length;
466 Rlen : constant Natural := Right'Length;
467
468 begin
469 if Llen <= Max_Length - Rlen then
470 Result.Data (1 .. Llen) := Left.Data (1 .. Llen);
471
472 if Rlen > 0 then
473 Result.Data (Llen + 1 .. Llen + Rlen) := Super_String_Data (Right);
474 end if;
475
476 Result.Current_Length := Llen + Rlen;
477
478 else
479 case Drop is
480 when Strings.Right =>
481 if Llen >= Max_Length then -- only case is Llen = Max_Length
482 Result.Data := Left.Data;
483
484 else
485 Result.Data (1 .. Llen) := Left.Data (1 .. Llen);
486 Result.Data (Llen + 1 .. Max_Length) := Super_String_Data
487 (Right
488 (Right'First .. Right'First - 1 - Llen + Max_Length));
489
490 end if;
491
492 when Strings.Left =>
493 if Rlen >= Max_Length then
494 Result.Data (1 .. Max_Length) := Super_String_Data
495 (Right (Right'Last - (Max_Length - 1) .. Right'Last));
496
497 else
498 Result.Data (1 .. Max_Length - Rlen) :=
499 Left.Data (Llen - (Max_Length - Rlen - 1) .. Llen);
500 Result.Data (Max_Length - Rlen + 1 .. Max_Length) :=
501 Super_String_Data (Right);
502 end if;
503
504 when Strings.Error =>
505 raise Ada.Strings.Length_Error;
506 end case;
507
508 Result.Current_Length := Max_Length;
509 end if;
510
511 return Result;
512 end Super_Append;
513
514 procedure Super_Append
515 (Source : in out Super_String;
516 New_Item : String;
517 Drop : Truncation := Error)
518 is
519 Max_Length : constant Positive := Source.Max_Length;
520 Llen : constant Natural := Source.Current_Length;
521 Rlen : constant Natural := New_Item'Length;
522
523 begin
524 if Llen <= Max_Length - Rlen then
525 if Rlen > 0 then
526 Source.Data (Llen + 1 .. Llen + Rlen) :=
527 Super_String_Data (New_Item);
528 Source.Current_Length := Llen + Rlen;
529 end if;
530
531 else
532 case Drop is
533 when Strings.Right =>
534 if Llen < Max_Length then
535 Source.Data (Llen + 1 .. Max_Length) := Super_String_Data
536 (New_Item (New_Item'First ..
537 New_Item'First - 1 - Llen + Max_Length));
538 end if;
539
540 when Strings.Left =>
541 if Rlen >= Max_Length then
542 Source.Data (1 .. Max_Length) := Super_String_Data
543 (New_Item (New_Item'Last - (Max_Length - 1) ..
544 New_Item'Last));
545
546 else
547 Source.Data (1 .. Max_Length - Rlen) :=
548 Source.Data (Llen - (Max_Length - Rlen - 1) .. Llen);
549 Source.Data (Max_Length - Rlen + 1 .. Max_Length) :=
550 Super_String_Data (New_Item);
551 end if;
552
553 when Strings.Error =>
554 raise Ada.Strings.Length_Error;
555 end case;
556
557 Source.Current_Length := Max_Length;
558 end if;
559
560 end Super_Append;
561
562 -- Case of String and Super_String
563
564 function Super_Append
565 (Left : String;
566 Right : Super_String;
567 Drop : Strings.Truncation := Strings.Error) return Super_String
568 is
569 Max_Length : constant Positive := Right.Max_Length;
570 Result : Super_String (Max_Length);
571 Llen : constant Natural := Left'Length;
572 Rlen : constant Natural := Right.Current_Length;
573
574 begin
575 if Llen <= Max_Length - Rlen then
576 Result.Data (1 .. Llen) := Super_String_Data (Left);
577
578 if Rlen > 0 then
579 Result.Data (Llen + 1 .. Llen + Rlen) := Right.Data (1 .. Rlen);
580 end if;
581
582 Result.Current_Length := Llen + Rlen;
583 else
584 case Drop is
585 when Strings.Right =>
586 if Llen >= Max_Length then
587 Result.Data (1 .. Max_Length) := Super_String_Data
588 (Left (Left'First .. Left'First + (Max_Length - 1)));
589
590 else
591 Result.Data (1 .. Llen) := Super_String_Data (Left);
592 Result.Data (Llen + 1 .. Max_Length) :=
593 Right.Data (1 .. Max_Length - Llen);
594 end if;
595
596 when Strings.Left =>
597 if Rlen >= Max_Length then
598 Result.Data (1 .. Max_Length) :=
599 Right.Data (Rlen - (Max_Length - 1) .. Rlen);
600
601 else
602 Result.Data (1 .. Max_Length - Rlen) := Super_String_Data
603 (Left (Left'Last - (Max_Length - Rlen - 1) .. Left'Last));
604 Result.Data (Max_Length - Rlen + 1 .. Max_Length) :=
605 Right.Data (1 .. Rlen);
606 end if;
607
608 when Strings.Error =>
609 raise Ada.Strings.Length_Error;
610 end case;
611
612 Result.Current_Length := Max_Length;
613 end if;
614
615 return Result;
616 end Super_Append;
617
618 -- Case of Super_String and Character
619
620 function Super_Append
621 (Left : Super_String;
622 Right : Character;
623 Drop : Strings.Truncation := Strings.Error) return Super_String
624 is
625 Max_Length : constant Positive := Left.Max_Length;
626 Result : Super_String (Max_Length);
627 Llen : constant Natural := Left.Current_Length;
628
629 begin
630 if Llen < Max_Length then
631 Result.Data (1 .. Llen) := Left.Data (1 .. Llen);
632 Result.Data (Llen + 1) := Right;
633 Result.Current_Length := Llen + 1;
634 return Result;
635
636 else
637 case Drop is
638 when Strings.Right =>
639 return Left;
640
641 when Strings.Left =>
642 Result.Data (1 .. Max_Length - 1) :=
643 Left.Data (2 .. Max_Length);
644 Result.Data (Max_Length) := Right;
645 Result.Current_Length := Max_Length;
646 return Result;
647
648 when Strings.Error =>
649 raise Ada.Strings.Length_Error;
650 end case;
651 end if;
652 end Super_Append;
653
654 procedure Super_Append
655 (Source : in out Super_String;
656 New_Item : Character;
657 Drop : Truncation := Error)
658 is
659 Max_Length : constant Positive := Source.Max_Length;
660 Llen : constant Natural := Source.Current_Length;
661
662 begin
663 if Llen < Max_Length then
664 Source.Data (Llen + 1) := New_Item;
665 Source.Current_Length := Llen + 1;
666
667 else
668 case Drop is
669 when Strings.Right =>
670 null;
671
672 when Strings.Left =>
673 Source.Data (1 .. Max_Length - 1) :=
674 Source.Data (2 .. Max_Length);
675 Source.Data (Max_Length) := New_Item;
676
677 when Strings.Error =>
678 raise Ada.Strings.Length_Error;
679 end case;
680 end if;
681
682 end Super_Append;
683
684 -- Case of Character and Super_String
685
686 function Super_Append
687 (Left : Character;
688 Right : Super_String;
689 Drop : Strings.Truncation := Strings.Error) return Super_String
690 is
691 Max_Length : constant Positive := Right.Max_Length;
692 Result : Super_String (Max_Length);
693 Rlen : constant Natural := Right.Current_Length;
694
695 begin
696 if Rlen < Max_Length then
697 Result.Data (1) := Left;
698 Result.Data (2 .. Rlen + 1) := Right.Data (1 .. Rlen);
699 Result.Current_Length := Rlen + 1;
700 return Result;
701
702 else
703 case Drop is
704 when Strings.Right =>
705 Result.Data (1) := Left;
706 Result.Data (2 .. Max_Length) :=
707 Right.Data (1 .. Max_Length - 1);
708 Result.Current_Length := Max_Length;
709 return Result;
710
711 when Strings.Left =>
712 return Right;
713
714 when Strings.Error =>
715 raise Ada.Strings.Length_Error;
716 end case;
717 end if;
718 end Super_Append;
719
720 -----------------
721 -- Super_Count --
722 -----------------
723
724 function Super_Count
725 (Source : Super_String;
726 Pattern : String;
727 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
728 is
729 begin
730 return Search.Count (Super_To_String (Source), Pattern, Mapping);
731 end Super_Count;
732
733 function Super_Count
734 (Source : Super_String;
735 Pattern : String;
736 Mapping : Maps.Character_Mapping_Function) return Natural
737 is
738 begin
739 return Search.Count (Super_To_String (Source), Pattern, Mapping);
740 end Super_Count;
741
742 function Super_Count
743 (Source : Super_String;
744 Set : Maps.Character_Set) return Natural
745 is
746 begin
747 return Search.Count (Super_To_String (Source), Set);
748 end Super_Count;
749
750 ------------------
751 -- Super_Delete --
752 ------------------
753
754 function Super_Delete
755 (Source : Super_String;
756 From : Positive;
757 Through : Natural) return Super_String
758 is
759 Result : Super_String (Source.Max_Length);
760 Slen : constant Natural := Source.Current_Length;
761 Num_Delete : constant Integer := Through - From + 1;
762
763 begin
764 if Num_Delete <= 0 then
765 return Source;
766
767 elsif From - 1 > Slen then
768 raise Ada.Strings.Index_Error;
769
770 elsif Through >= Slen then
771 Result.Data (1 .. From - 1) := Source.Data (1 .. From - 1);
772 Result.Current_Length := From - 1;
773 return Result;
774
775 else
776 Result.Data (1 .. From - 1) := Source.Data (1 .. From - 1);
777 Result.Data (From .. Slen - Num_Delete) :=
778 Source.Data (Through + 1 .. Slen);
779 Result.Current_Length := Slen - Num_Delete;
780 return Result;
781 end if;
782 end Super_Delete;
783
784 procedure Super_Delete
785 (Source : in out Super_String;
786 From : Positive;
787 Through : Natural)
788 is
789 Slen : constant Natural := Source.Current_Length;
790 Num_Delete : constant Integer := Through - From + 1;
791
792 begin
793 if Num_Delete <= 0 then
794 return;
795
796 elsif From - 1 > Slen then
797 raise Ada.Strings.Index_Error;
798
799 elsif Through >= Slen then
800 Source.Current_Length := From - 1;
801
802 else
803 Source.Current_Length := Slen - Num_Delete;
804 Source.Data (From .. Source.Current_Length) :=
805 Source.Data (Through + 1 .. Slen);
806 end if;
807 end Super_Delete;
808
809 ----------------------
810 -- Super_Find_Token --
811 ----------------------
812
813 procedure Super_Find_Token
814 (Source : Super_String;
815 Set : Maps.Character_Set;
816 From : Positive;
817 Test : Strings.Membership;
818 First : out Positive;
819 Last : out Natural)
820 is
821 begin
822 Search.Find_Token
823 (Super_To_String (Source), Set, From, Test, First, Last);
824 end Super_Find_Token;
825
826 procedure Super_Find_Token
827 (Source : Super_String;
828 Set : Maps.Character_Set;
829 Test : Strings.Membership;
830 First : out Positive;
831 Last : out Natural)
832 is
833 begin
834 Search.Find_Token (Super_To_String (Source), Set, Test, First, Last);
835 end Super_Find_Token;
836
837 ----------------
838 -- Super_Head --
839 ----------------
840
841 function Super_Head
842 (Source : Super_String;
843 Count : Natural;
844 Pad : Character := Space;
845 Drop : Strings.Truncation := Strings.Error) return Super_String
846 is
847 Max_Length : constant Positive := Source.Max_Length;
848 Result : Super_String (Max_Length);
849 Slen : constant Natural := Source.Current_Length;
850 Npad : constant Integer := Count - Slen;
851
852 begin
853 if Npad <= 0 then
854 Result.Data (1 .. Count) := Source.Data (1 .. Count);
855 Result.Current_Length := Count;
856
857 elsif Count <= Max_Length then
858 Result.Data (1 .. Slen) := Source.Data (1 .. Slen);
859 Result.Data (Slen + 1 .. Count) := [others => Pad];
860 Result.Current_Length := Count;
861
862 else
863 case Drop is
864 when Strings.Right =>
865 Result.Data (1 .. Slen) := Source.Data (1 .. Slen);
866
867 if Slen < Max_Length then
868 Result.Data (Slen + 1 .. Max_Length) := [others => Pad];
869 end if;
870
871 when Strings.Left =>
872 if Npad >= Max_Length then
873 Result.Data := [others => Pad];
874
875 else
876 Result.Data (1 .. Max_Length - Npad) :=
877 Source.Data (Count - Max_Length + 1 .. Slen);
878 Result.Data (Max_Length - Npad + 1 .. Max_Length) :=
879 [others => Pad];
880 end if;
881
882 when Strings.Error =>
883 raise Ada.Strings.Length_Error;
884 end case;
885
886 Result.Current_Length := Max_Length;
887 end if;
888
889 return Result;
890 end Super_Head;
891
892 procedure Super_Head
893 (Source : in out Super_String;
894 Count : Natural;
895 Pad : Character := Space;
896 Drop : Truncation := Error)
897 is
898 Max_Length : constant Positive := Source.Max_Length;
899 Slen : constant Natural := Source.Current_Length;
900 Npad : constant Integer := Count - Slen;
901 Temp : Super_String_Data (1 .. Max_Length);
902
903 begin
904 if Npad <= 0 then
905 Source.Current_Length := Count;
906
907 elsif Count <= Max_Length then
908 Source.Data (Slen + 1 .. Count) := [others => Pad];
909 Source.Current_Length := Count;
910
911 else
912 case Drop is
913 when Strings.Right =>
914 if Slen < Max_Length then
915 Source.Data (Slen + 1 .. Max_Length) := [others => Pad];
916 end if;
917
918 when Strings.Left =>
919 if Npad > Max_Length then
920 Source.Data := [others => Pad];
921
922 else
923 Temp := Source.Data;
924 Source.Data (1 .. Max_Length - Npad) :=
925 Temp (Count - Max_Length + 1 .. Slen);
926 Source.Data (Max_Length - Npad + 1 .. Max_Length) :=
927 [others => Pad];
928 end if;
929
930 when Strings.Error =>
931 raise Ada.Strings.Length_Error;
932 end case;
933
934 Source.Current_Length := Max_Length;
935 end if;
936 end Super_Head;
937
938 -----------------
939 -- Super_Index --
940 -----------------
941
942 function Super_Index
943 (Source : Super_String;
944 Pattern : String;
945 Going : Strings.Direction := Strings.Forward;
946 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
947 is
948 begin
949 return Search.Index (Super_To_String (Source), Pattern, Going, Mapping);
950 end Super_Index;
951
952 function Super_Index
953 (Source : Super_String;
954 Pattern : String;
955 Going : Direction := Forward;
956 Mapping : Maps.Character_Mapping_Function) return Natural
957 is
958 begin
959 return Search.Index (Super_To_String (Source), Pattern, Going, Mapping);
960 end Super_Index;
961
962 function Super_Index
963 (Source : Super_String;
964 Set : Maps.Character_Set;
965 Test : Strings.Membership := Strings.Inside;
966 Going : Strings.Direction := Strings.Forward) return Natural
967 is
968 begin
969 return Search.Index (Super_To_String (Source), Set, Test, Going);
970 end Super_Index;
971
972 function Super_Index
973 (Source : Super_String;
974 Pattern : String;
975 From : Positive;
976 Going : Direction := Forward;
977 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
978 is
979 begin
980 return Search.Index
981 (Super_To_String (Source), Pattern, From, Going, Mapping);
982 end Super_Index;
983
984 function Super_Index
985 (Source : Super_String;
986 Pattern : String;
987 From : Positive;
988 Going : Direction := Forward;
989 Mapping : Maps.Character_Mapping_Function) return Natural
990 is
991 begin
992 return Search.Index
993 (Super_To_String (Source), Pattern, From, Going, Mapping);
994 end Super_Index;
995
996 function Super_Index
997 (Source : Super_String;
998 Set : Maps.Character_Set;
999 From : Positive;
1000 Test : Membership := Inside;
1001 Going : Direction := Forward) return Natural
1002 is
1003 begin
1004 return Result : Natural do
1005 Result :=
1006 Search.Index (Super_To_String (Source), Set, From, Test, Going);
1007 pragma Assert
1008 (if (for all J in 1 .. Super_Length (Source) =>
1009 (if J = From or else (J > From) = (Going = Forward) then
1010 (Test = Inside) /= Maps.Is_In (Source.Data (J), Set)))
1011 then Result = 0);
1012 end return;
1013 end Super_Index;
1014
1015 ---------------------------
1016 -- Super_Index_Non_Blank --
1017 ---------------------------
1018
1019 function Super_Index_Non_Blank
1020 (Source : Super_String;
1021 Going : Strings.Direction := Strings.Forward) return Natural
1022 is
1023 begin
1024 return Search.Index_Non_Blank (Super_To_String (Source), Going);
1025 end Super_Index_Non_Blank;
1026
1027 function Super_Index_Non_Blank
1028 (Source : Super_String;
1029 From : Positive;
1030 Going : Direction := Forward) return Natural
1031 is
1032 begin
1033 return Search.Index_Non_Blank (Super_To_String (Source), From, Going);
1034 end Super_Index_Non_Blank;
1035
1036 ------------------
1037 -- Super_Insert --
1038 ------------------
1039
1040 function Super_Insert
1041 (Source : Super_String;
1042 Before : Positive;
1043 New_Item : String;
1044 Drop : Strings.Truncation := Strings.Error) return Super_String
1045 with SPARK_Mode => Off
1046 is
1047 Max_Length : constant Positive := Source.Max_Length;
1048 Result : Super_String (Max_Length);
1049 Slen : constant Natural := Source.Current_Length;
1050 Nlen : constant Natural := New_Item'Length;
1051 Blen : constant Natural := Before - 1;
1052 Alen : constant Integer := Slen - Blen;
1053 Droplen : constant Integer := Slen - Max_Length + Nlen;
1054
1055 -- Blen, Alen are the lengths of the before and after pieces of the
1056 -- source string. The number of dropped characters is Natural'Max (0,
1057 -- Droplen).
1058
1059 begin
1060 if Alen < 0 then
1061 raise Ada.Strings.Index_Error;
1062
1063 elsif Droplen <= 0 then
1064 Result.Data (1 .. Blen) := Source.Data (1 .. Blen);
1065 Result.Data (Before .. Before - 1 + Nlen) :=
1066 Super_String_Data (New_Item);
1067
1068 if Before <= Slen then
1069 Result.Data (Before + Nlen .. Slen + Nlen) :=
1070 Source.Data (Before .. Slen);
1071 end if;
1072
1073 Result.Current_Length := Slen + Nlen;
1074
1075 else
1076 case Drop is
1077 when Strings.Right =>
1078 Result.Data (1 .. Blen) := Source.Data (1 .. Blen);
1079
1080 if Droplen >= Alen then
1081 Result.Data (Before .. Max_Length) := Super_String_Data
1082 (New_Item (New_Item'First
1083 .. New_Item'First - Before + Max_Length));
1084 pragma Assert
1085 (String (Result.Data (Before .. Max_Length)) =
1086 New_Item (New_Item'First
1087 .. New_Item'First - Before + Max_Length));
1088 else
1089 Result.Data (Before .. Before - 1 + Nlen) :=
1090 Super_String_Data (New_Item);
1091 Result.Data (Before + Nlen .. Max_Length) :=
1092 Source.Data (Before .. Slen - Droplen);
1093 end if;
1094
1095 when Strings.Left =>
1096 if Alen > 0 then
1097 Result.Data (Max_Length - (Alen - 1) .. Max_Length) :=
1098 Source.Data (Before .. Slen);
1099 end if;
1100
1101 if Droplen > Blen then
1102 if Alen < Max_Length then
1103 Result.Data (1 .. Max_Length - Alen) := Super_String_Data
1104 (New_Item (New_Item'Last - (Max_Length - Alen) + 1
1105 .. New_Item'Last));
1106 end if;
1107 else
1108 Result.Data (Blen - Droplen + 1 .. Max_Length - Alen) :=
1109 Super_String_Data (New_Item);
1110 Result.Data (1 .. Blen - Droplen) :=
1111 Source.Data (Droplen + 1 .. Blen);
1112 end if;
1113
1114 when Strings.Error =>
1115 raise Ada.Strings.Length_Error;
1116 end case;
1117
1118 Result.Current_Length := Max_Length;
1119 end if;
1120
1121 return Result;
1122 end Super_Insert;
1123
1124 procedure Super_Insert
1125 (Source : in out Super_String;
1126 Before : Positive;
1127 New_Item : String;
1128 Drop : Strings.Truncation := Strings.Error)
1129 is
1130 begin
1131 -- We do a double copy here because this is one of the situations
1132 -- in which we move data to the right, and at least at the moment,
1133 -- GNAT is not handling such cases correctly ???
1134
1135 Source := Super_Insert (Source, Before, New_Item, Drop);
1136 end Super_Insert;
1137
1138 ---------------------
1139 -- Super_Overwrite --
1140 ---------------------
1141
1142 function Super_Overwrite
1143 (Source : Super_String;
1144 Position : Positive;
1145 New_Item : String;
1146 Drop : Strings.Truncation := Strings.Error) return Super_String
1147 is
1148 Max_Length : constant Positive := Source.Max_Length;
1149 Result : Super_String (Max_Length);
1150 Slen : constant Natural := Source.Current_Length;
1151 Droplen : Natural;
1152
1153 begin
1154 if Position - 1 > Slen then
1155 raise Ada.Strings.Index_Error;
1156
1157 elsif New_Item'Length = 0 then
1158 return Source;
1159
1160 elsif Position - 1 <= Slen - New_Item'Length then
1161 Result.Data (1 .. Slen) := Source.Data (1 .. Slen);
1162 Result.Data (Position .. Position - 1 + New_Item'Length) :=
1163 Super_String_Data (New_Item);
1164 Result.Current_Length := Source.Current_Length;
1165 pragma Assert
1166 (String'(Super_Slice (Result, 1, Position - 1)) =
1167 Super_Slice (Source, 1, Position - 1));
1168 pragma Assert
1169 (Super_Slice (Result,
1170 Position, Position - 1 + New_Item'Length) =
1171 New_Item);
1172
1173 return Result;
1174
1175 elsif Position - 1 <= Max_Length - New_Item'Length then
1176 Result.Data (1 .. Position - 1) := Source.Data (1 .. Position - 1);
1177 Result.Data (Position .. Position - 1 + New_Item'Length) :=
1178 Super_String_Data (New_Item);
1179 Result.Current_Length := Position - 1 + New_Item'Length;
1180 pragma Assert
1181 (String'(Super_Slice (Result, 1, Position - 1)) =
1182 Super_Slice (Source, 1, Position - 1));
1183 pragma Assert
1184 (Super_Slice (Result,
1185 Position, Position - 1 + New_Item'Length) =
1186 New_Item);
1187
1188 return Result;
1189
1190 else
1191 Droplen := Position - 1 - Max_Length + New_Item'Length;
1192
1193 case Drop is
1194 when Strings.Right =>
1195 Result.Data (1 .. Position - 1) :=
1196 Source.Data (1 .. Position - 1);
1197
1198 Result.Data (Position .. Max_Length) := Super_String_Data
1199 (New_Item (New_Item'First .. New_Item'Last - Droplen));
1200
1201 when Strings.Left =>
1202 if New_Item'Length >= Max_Length then
1203 Result.Data (1 .. Max_Length) := Super_String_Data
1204 (New_Item (New_Item'Last - Max_Length + 1 ..
1205 New_Item'Last));
1206
1207 else
1208 Result.Data (1 .. Max_Length - New_Item'Length) :=
1209 Source.Data (Droplen + 1 .. Position - 1);
1210 Result.Data
1211 (Max_Length - New_Item'Length + 1 .. Max_Length) :=
1212 Super_String_Data (New_Item);
1213 end if;
1214
1215 when Strings.Error =>
1216 raise Ada.Strings.Length_Error;
1217 end case;
1218
1219 Result.Current_Length := Max_Length;
1220 pragma Assert (Super_Length (Result) = Source.Max_Length);
1221 return Result;
1222 end if;
1223 end Super_Overwrite;
1224
1225 procedure Super_Overwrite
1226 (Source : in out Super_String;
1227 Position : Positive;
1228 New_Item : String;
1229 Drop : Strings.Truncation := Strings.Error)
1230 with SPARK_Mode => Off
1231 is
1232 Max_Length : constant Positive := Source.Max_Length;
1233 Slen : constant Natural := Source.Current_Length;
1234 Droplen : Natural;
1235
1236 begin
1237 if Position - 1 > Slen then
1238 raise Ada.Strings.Index_Error;
1239
1240 elsif Position - 1 <= Slen - New_Item'Length then
1241 Source.Data (Position .. Position - 1 + New_Item'Length) :=
1242 Super_String_Data (New_Item);
1243
1244 elsif Position - 1 <= Max_Length - New_Item'Length then
1245 Source.Data (Position .. Position - 1 + New_Item'Length) :=
1246 Super_String_Data (New_Item);
1247 Source.Current_Length := Position - 1 + New_Item'Length;
1248
1249 else
1250 Droplen := Position - 1 - Max_Length + New_Item'Length;
1251
1252 case Drop is
1253 when Strings.Right =>
1254 Source.Data (Position .. Max_Length) := Super_String_Data
1255 (New_Item (New_Item'First .. New_Item'Last - Droplen));
1256
1257 when Strings.Left =>
1258 if New_Item'Length >= Max_Length then
1259 Source.Data (1 .. Max_Length) := Super_String_Data
1260 (New_Item
1261 (New_Item'Last - Max_Length + 1 .. New_Item'Last));
1262
1263 else
1264 Source.Data (1 .. Max_Length - New_Item'Length) :=
1265 Source.Data (Droplen + 1 .. Position - 1);
1266 Source.Data
1267 (Max_Length - New_Item'Length + 1 .. Max_Length) :=
1268 Super_String_Data (New_Item);
1269 end if;
1270
1271 when Strings.Error =>
1272 raise Ada.Strings.Length_Error;
1273 end case;
1274
1275 Source.Current_Length := Max_Length;
1276 end if;
1277 end Super_Overwrite;
1278
1279 ---------------------------
1280 -- Super_Replace_Element --
1281 ---------------------------
1282
1283 procedure Super_Replace_Element
1284 (Source : in out Super_String;
1285 Index : Positive;
1286 By : Character)
1287 is
1288 begin
1289 if Index <= Source.Current_Length then
1290 Source.Data (Index) := By;
1291 else
1292 raise Ada.Strings.Index_Error;
1293 end if;
1294 end Super_Replace_Element;
1295
1296 -------------------------
1297 -- Super_Replace_Slice --
1298 -------------------------
1299
1300 function Super_Replace_Slice
1301 (Source : Super_String;
1302 Low : Positive;
1303 High : Natural;
1304 By : String;
1305 Drop : Strings.Truncation := Strings.Error) return Super_String
1306 with SPARK_Mode => Off
1307 is
1308 Max_Length : constant Positive := Source.Max_Length;
1309 Slen : constant Natural := Source.Current_Length;
1310
1311 begin
1312 if Low - 1 > Slen then
1313 raise Strings.Index_Error;
1314
1315 elsif High < Low then
1316 return Super_Insert (Source, Low, By, Drop);
1317
1318 else
1319 declare
1320 Blen : constant Natural := Low - 1;
1321 Alen : constant Natural := Natural'Max (0, Slen - High);
1322 Droplen : constant Integer := Blen + Alen - Max_Length + By'Length;
1323 Result : Super_String (Max_Length);
1324
1325 -- Blen and Alen are the lengths of the pieces of the original
1326 -- string that end up in the result string before and after the
1327 -- replaced slice. The number of dropped characters is Natural'Max
1328 -- (0, Droplen).
1329
1330 begin
1331 if Droplen <= 0 then
1332 Result.Data (1 .. Blen) := Source.Data (1 .. Blen);
1333 Result.Data (Low .. Blen + By'Length) :=
1334 Super_String_Data (By);
1335
1336 if Alen > 0 then
1337 Result.Data (Low + By'Length .. Blen + By'Length + Alen) :=
1338 Source.Data (High + 1 .. Slen);
1339 end if;
1340
1341 Result.Current_Length := Blen + By'Length + Alen;
1342
1343 else
1344 case Drop is
1345 when Strings.Right =>
1346 Result.Data (1 .. Blen) := Source.Data (1 .. Blen);
1347
1348 if Droplen >= Alen then
1349 Result.Data (Low .. Max_Length) := Super_String_Data
1350 (By (By'First .. By'First - Low + Max_Length));
1351 else
1352 Result.Data (Low .. Low - 1 + By'Length) :=
1353 Super_String_Data (By);
1354 Result.Data (Low + By'Length .. Max_Length) :=
1355 Source.Data (High + 1 .. Slen - Droplen);
1356 end if;
1357
1358 when Strings.Left =>
1359 if Alen > 0 then
1360 Result.Data (Max_Length - (Alen - 1) .. Max_Length) :=
1361 Source.Data (High + 1 .. Slen);
1362 end if;
1363
1364 if Droplen >= Blen then
1365 Result.Data (1 .. Max_Length - Alen) :=
1366 Super_String_Data (By
1367 (By'Last - (Max_Length - Alen) + 1 .. By'Last));
1368 else
1369 Result.Data
1370 (Blen - Droplen + 1 .. Max_Length - Alen) :=
1371 Super_String_Data (By);
1372 Result.Data (1 .. Blen - Droplen) :=
1373 Source.Data (Droplen + 1 .. Blen);
1374 end if;
1375
1376 when Strings.Error =>
1377 raise Ada.Strings.Length_Error;
1378 end case;
1379
1380 Result.Current_Length := Max_Length;
1381 end if;
1382
1383 return Result;
1384 end;
1385 end if;
1386 end Super_Replace_Slice;
1387
1388 procedure Super_Replace_Slice
1389 (Source : in out Super_String;
1390 Low : Positive;
1391 High : Natural;
1392 By : String;
1393 Drop : Strings.Truncation := Strings.Error)
1394 is
1395 begin
1396 -- We do a double copy here because this is one of the situations
1397 -- in which we move data to the right, and at least at the moment,
1398 -- GNAT is not handling such cases correctly ???
1399
1400 Source := Super_Replace_Slice (Source, Low, High, By, Drop);
1401 end Super_Replace_Slice;
1402
1403 ---------------------
1404 -- Super_Replicate --
1405 ---------------------
1406
1407 function Super_Replicate
1408 (Count : Natural;
1409 Item : Character;
1410 Drop : Truncation := Error;
1411 Max_Length : Positive) return Super_String
1412 is
1413 Result : Super_String (Max_Length);
1414
1415 begin
1416 if Count <= Max_Length then
1417 Result.Data (1 .. Count) := [others => Item];
1418 Result.Current_Length := Count;
1419
1420 elsif Drop = Strings.Error then
1421 raise Ada.Strings.Length_Error;
1422
1423 else
1424 Result.Data (1 .. Max_Length) := [others => Item];
1425 Result.Current_Length := Max_Length;
1426 end if;
1427
1428 return Result;
1429 end Super_Replicate;
1430
1431 function Super_Replicate
1432 (Count : Natural;
1433 Item : String;
1434 Drop : Truncation := Error;
1435 Max_Length : Positive) return Super_String
1436 is
1437 Result : Super_String (Max_Length);
1438 Indx : Natural;
1439 Ilen : constant Natural := Item'Length;
1440
1441 -- Parts of the proof involving manipulations with the modulo operator
1442 -- are complicated for the prover and can't be done automatically in
1443 -- the global subprogram. That's why we isolate them in these two ghost
1444 -- lemmas.
1445
1446 procedure Lemma_Mod (K : Natural; Q : Natural) with
1447 Ghost,
1448 Pre => Ilen /= 0
1449 and then Q mod Ilen = 0
1450 and then K - Q in 0 .. Ilen - 1,
1451 Post => K mod Ilen = K - Q;
1452 -- Lemma_Mod is applied to an index considered in Lemma_Split to prove
1453 -- that it has the right value modulo Item'Length.
1454
1455 procedure Lemma_Mod_Zero (X : Natural) with
1456 Ghost,
1457 Pre => Ilen /= 0
1458 and then X mod Ilen = 0
1459 and then X <= Natural'Last - Ilen,
1460 Post => (X + Ilen) mod Ilen = 0;
1461 -- Lemma_Mod_Zero is applied to prove that the length of the range
1462 -- of indexes considered in the loop, when dropping on the Left, is
1463 -- a multiple of Item'Length.
1464
1465 procedure Lemma_Split (Going : Direction) with
1466 Ghost,
1467 Pre =>
1468 Ilen /= 0
1469 and then Indx in 0 .. Max_Length - Ilen
1470 and then
1471 (if Going = Forward
1472 then Indx mod Ilen = 0
1473 else (Max_Length - Indx - Ilen) mod Ilen = 0)
1474 and then Result.Data (Indx + 1 .. Indx + Ilen)'Initialized
1475 and then String (Result.Data (Indx + 1 .. Indx + Ilen)) = Item,
1476 Post =>
1477 (if Going = Forward then
1478 (for all J in Indx + 1 .. Indx + Ilen =>
1479 Result.Data (J) = Item (Item'First + (J - 1) mod Ilen))
1480 else
1481 (for all J in Indx + 1 .. Indx + Ilen =>
1482 Result.Data (J) =
1483 Item (Item'Last - (Max_Length - J) mod Ilen)));
1484 -- Lemma_Split is used after Result.Data (Indx + 1 .. Indx + Ilen) is
1485 -- updated to Item and concludes that the characters match for each
1486 -- index when taken modulo Item'Length, as the considered slice starts
1487 -- at index 1 (or ends at index Max_Length, if Going = Backward) modulo
1488 -- Item'Length.
1489
1490 ---------------
1491 -- Lemma_Mod --
1492 ---------------
1493
1494 procedure Lemma_Mod (K : Natural; Q : Natural) is null;
1495
1496 --------------------
1497 -- Lemma_Mod_Zero --
1498 --------------------
1499
1500 procedure Lemma_Mod_Zero (X : Natural) is null;
1501
1502 -----------------
1503 -- Lemma_Split --
1504 -----------------
1505
1506 procedure Lemma_Split (Going : Direction) is
1507 begin
1508 if Going = Forward then
1509 for K in Indx + 1 .. Indx + Ilen loop
1510 Lemma_Mod (K - 1, Indx);
1511 pragma Loop_Invariant
1512 (for all J in Indx + 1 .. K =>
1513 Result.Data (J) = Item (Item'First + (J - 1) mod Ilen));
1514 end loop;
1515 else
1516 for K in Indx + 1 .. Indx + Ilen loop
1517 Lemma_Mod (Max_Length - K, Max_Length - Indx - Ilen);
1518 pragma Loop_Invariant
1519 (for all J in Indx + 1 .. K =>
1520 Result.Data (J) =
1521 Item (Item'Last - (Max_Length - J) mod Ilen));
1522 end loop;
1523 end if;
1524 end Lemma_Split;
1525
1526 begin
1527 if Count = 0 or else Ilen <= Max_Length / Count then
1528 if Count * Ilen > 0 then
1529 Indx := 0;
1530
1531 for J in 1 .. Count loop
1532 Result.Data (Indx + 1 .. Indx + Ilen) :=
1533 Super_String_Data (Item);
1534 pragma Assert
1535 (for all K in 1 .. Ilen =>
1536 Result.Data (Indx + K) = Item (Item'First - 1 + K));
1537 pragma Assert
1538 (String (Result.Data (Indx + 1 .. Indx + Ilen)) = Item);
1539 Lemma_Split (Forward);
1540 Indx := Indx + Ilen;
1541 pragma Loop_Invariant (Indx = J * Ilen);
1542 pragma Loop_Invariant (Result.Data (1 .. Indx)'Initialized);
1543 pragma Loop_Invariant
1544 (for all K in 1 .. Indx =>
1545 Result.Data (K) =
1546 Item (Item'First + (K - 1) mod Ilen));
1547 end loop;
1548 end if;
1549
1550 Result.Current_Length := Count * Ilen;
1551
1552 else
1553 case Drop is
1554 when Strings.Right =>
1555 Indx := 0;
1556
1557 while Indx < Max_Length - Ilen loop
1558 Result.Data (Indx + 1 .. Indx + Ilen) :=
1559 Super_String_Data (Item);
1560 pragma Assert
1561 (for all K in 1 .. Ilen =>
1562 Result.Data (Indx + K) = Item (Item'First - 1 + K));
1563 pragma Assert
1564 (String (Result.Data (Indx + 1 .. Indx + Ilen)) = Item);
1565 Lemma_Split (Forward);
1566 Indx := Indx + Ilen;
1567 pragma Loop_Invariant (Indx mod Ilen = 0);
1568 pragma Loop_Invariant (Indx in 0 .. Max_Length - 1);
1569 pragma Loop_Invariant (Result.Data (1 .. Indx)'Initialized);
1570 pragma Loop_Invariant
1571 (for all K in 1 .. Indx =>
1572 Result.Data (K) =
1573 Item (Item'First + (K - 1) mod Ilen));
1574 pragma Loop_Variant (Increases => Indx);
1575 end loop;
1576
1577 Result.Data (Indx + 1 .. Max_Length) := Super_String_Data
1578 (Item (Item'First .. Item'First + (Max_Length - Indx - 1)));
1579 pragma Assert
1580 (for all J in Indx + 1 .. Max_Length =>
1581 Result.Data (J) = Item (Item'First - 1 - Indx + J));
1582
1583 for J in Indx + 1 .. Max_Length loop
1584 Lemma_Mod (J - 1, Indx);
1585 pragma Loop_Invariant
1586 (for all K in 1 .. J =>
1587 Result.Data (K) =
1588 Item (Item'First + (K - 1) mod Ilen));
1589 end loop;
1590
1591 when Strings.Left =>
1592 Indx := Max_Length;
1593
1594 while Indx > Ilen loop
1595 Indx := Indx - Ilen;
1596 Result.Data (Indx + 1 .. Indx + Ilen) :=
1597 Super_String_Data (Item);
1598 pragma Assert
1599 (for all K in 1 .. Ilen =>
1600 Result.Data (Indx + K) = Item (Item'First - 1 + K));
1601 pragma Assert
1602 (String (Result.Data (Indx + 1 .. Indx + Ilen)) = Item);
1603 Lemma_Split (Backward);
1604 Lemma_Mod_Zero (Max_Length - Indx - Ilen);
1605 pragma Loop_Invariant
1606 ((Max_Length - Indx) mod Ilen = 0);
1607 pragma Loop_Invariant (Indx in 1 .. Max_Length);
1608 pragma Loop_Invariant
1609 (Result.Data (Indx + 1 .. Max_Length)'Initialized);
1610 pragma Loop_Invariant
1611 (for all K in Indx + 1 .. Max_Length =>
1612 Result.Data (K) =
1613 Item (Item'Last - (Max_Length - K) mod Ilen));
1614 pragma Loop_Variant (Decreases => Indx);
1615 end loop;
1616
1617 Result.Data (1 .. Indx) :=
1618 Super_String_Data (Item (Item'Last - Indx + 1 .. Item'Last));
1619 pragma Assert
1620 (for all J in 1 .. Indx =>
1621 Result.Data (J) = Item (Item'Last - Indx + J));
1622
1623 for J in reverse 1 .. Indx loop
1624 Lemma_Mod (Max_Length - J, Max_Length - Indx);
1625 pragma Loop_Invariant
1626 (for all K in J .. Max_Length =>
1627 Result.Data (K) =
1628 Item (Item'Last - (Max_Length - K) mod Ilen));
1629 end loop;
1630 pragma Assert
1631 (Result.Data (1 .. Max_Length)'Initialized);
1632
1633 when Strings.Error =>
1634 raise Ada.Strings.Length_Error;
1635 end case;
1636
1637 Result.Current_Length := Max_Length;
1638 end if;
1639
1640 return Result;
1641 end Super_Replicate;
1642
1643 function Super_Replicate
1644 (Count : Natural;
1645 Item : Super_String;
1646 Drop : Strings.Truncation := Strings.Error) return Super_String
1647 is
1648 begin
1649 return
1650 Super_Replicate (Count, Super_To_String (Item), Drop, Item.Max_Length);
1651 end Super_Replicate;
1652
1653 -----------------
1654 -- Super_Slice --
1655 -----------------
1656
1657 function Super_Slice
1658 (Source : Super_String;
1659 Low : Positive;
1660 High : Natural) return Super_String
1661 is
1662 Len : constant Natural := (if Low > High then 0 else High - Low + 1);
1663 begin
1664 return Result : Super_String (Source.Max_Length) do
1665 if Low - 1 > Source.Current_Length
1666 or else High > Source.Current_Length
1667 then
1668 raise Index_Error;
1669 end if;
1670
1671 Result.Data (1 .. Len) := Source.Data (Low .. High);
1672 Result.Current_Length := Len;
1673 end return;
1674 end Super_Slice;
1675
1676 procedure Super_Slice
1677 (Source : Super_String;
1678 Target : out Super_String;
1679 Low : Positive;
1680 High : Natural)
1681 is
1682 Len : constant Natural := (if Low > High then 0 else High - Low + 1);
1683 begin
1684 if Low - 1 > Source.Current_Length
1685 or else High > Source.Current_Length
1686 then
1687 raise Index_Error;
1688 end if;
1689
1690 Target.Data (1 .. Len) := Source.Data (Low .. High);
1691 Target.Current_Length := Len;
1692 end Super_Slice;
1693
1694 ----------------
1695 -- Super_Tail --
1696 ----------------
1697
1698 function Super_Tail
1699 (Source : Super_String;
1700 Count : Natural;
1701 Pad : Character := Space;
1702 Drop : Strings.Truncation := Strings.Error) return Super_String
1703 is
1704 Max_Length : constant Positive := Source.Max_Length;
1705 Result : Super_String (Max_Length);
1706 Slen : constant Natural := Source.Current_Length;
1707 Npad : constant Integer := Count - Slen;
1708
1709 begin
1710 if Npad <= 0 then
1711 if Count > 0 then
1712 Result.Data (1 .. Count) :=
1713 Source.Data (Slen - (Count - 1) .. Slen);
1714 Result.Current_Length := Count;
1715 end if;
1716
1717 elsif Count <= Max_Length then
1718 Result.Data (1 .. Npad) := [others => Pad];
1719
1720 if Slen > 0 then
1721 Result.Data (Npad + 1 .. Count) := Source.Data (1 .. Slen);
1722 end if;
1723
1724 Result.Current_Length := Count;
1725
1726 else
1727 case Drop is
1728 when Strings.Right =>
1729 if Npad >= Max_Length then
1730 Result.Data := [others => Pad];
1731
1732 else
1733 Result.Data (1 .. Npad) := [others => Pad];
1734 Result.Data (Npad + 1 .. Max_Length) :=
1735 Source.Data (1 .. Max_Length - Npad);
1736 end if;
1737
1738 when Strings.Left =>
1739 Result.Data (1 .. Max_Length - Slen) := [others => Pad];
1740 Result.Data (Max_Length - Slen + 1 .. Max_Length) :=
1741 Source.Data (1 .. Slen);
1742
1743 when Strings.Error =>
1744 raise Ada.Strings.Length_Error;
1745 end case;
1746
1747 Result.Current_Length := Max_Length;
1748 end if;
1749
1750 return Result;
1751 end Super_Tail;
1752
1753 procedure Super_Tail
1754 (Source : in out Super_String;
1755 Count : Natural;
1756 Pad : Character := Space;
1757 Drop : Truncation := Error)
1758 is
1759 Max_Length : constant Positive := Source.Max_Length;
1760 Slen : constant Natural := Source.Current_Length;
1761 Npad : constant Integer := Count - Slen;
1762
1763 Temp : constant Super_String_Data (1 .. Max_Length) := Source.Data;
1764
1765 begin
1766 if Npad <= 0 then
1767 Source.Current_Length := Count;
1768
1769 if Count > 0 then
1770 Source.Data (1 .. Count) :=
1771 Temp (Slen - (Count - 1) .. Slen);
1772 end if;
1773
1774 elsif Count <= Max_Length then
1775 Source.Data (1 .. Npad) := [others => Pad];
1776
1777 if Slen > 0 then
1778 Source.Data (Npad + 1 .. Count) := Temp (1 .. Slen);
1779 end if;
1780
1781 Source.Current_Length := Count;
1782
1783 else
1784 case Drop is
1785 when Strings.Right =>
1786 if Npad >= Max_Length then
1787 Source.Data := [others => Pad];
1788
1789 else
1790 Source.Data (1 .. Npad) := [others => Pad];
1791 Source.Data (Npad + 1 .. Max_Length) :=
1792 Temp (1 .. Max_Length - Npad);
1793
1794 pragma Assert
1795 (Source.Data (1 .. Npad) = [1 .. Npad => Pad]);
1796 pragma Assert
1797 (Source.Data (Npad + 1 .. Max_Length)
1798 = Temp (1 .. Max_Length - Npad));
1799 end if;
1800
1801 when Strings.Left =>
1802 Source.Data (1 .. Max_Length - Slen) := [others => Pad];
1803 Source.Data (Max_Length - Slen + 1 .. Max_Length) :=
1804 Temp (1 .. Slen);
1805
1806 when Strings.Error =>
1807 raise Ada.Strings.Length_Error;
1808 end case;
1809
1810 Source.Current_Length := Max_Length;
1811 end if;
1812 end Super_Tail;
1813
1814 ---------------------
1815 -- Super_Translate --
1816 ---------------------
1817
1818 function Super_Translate
1819 (Source : Super_String;
1820 Mapping : Maps.Character_Mapping) return Super_String
1821 is
1822 Result : Super_String (Source.Max_Length);
1823
1824 begin
1825 for J in 1 .. Source.Current_Length loop
1826 Result.Data (J) := Value (Mapping, Source.Data (J));
1827 pragma Loop_Invariant (Result.Data (1 .. J)'Initialized);
1828 pragma Loop_Invariant
1829 (for all K in 1 .. J =>
1830 Result.Data (K) = Value (Mapping, Source.Data (K)));
1831 end loop;
1832
1833 Result.Current_Length := Source.Current_Length;
1834 return Result;
1835 end Super_Translate;
1836
1837 procedure Super_Translate
1838 (Source : in out Super_String;
1839 Mapping : Maps.Character_Mapping)
1840 is
1841 begin
1842 for J in 1 .. Source.Current_Length loop
1843 Source.Data (J) := Value (Mapping, Source.Data (J));
1844 pragma Loop_Invariant
1845 (for all K in 1 .. J =>
1846 Source.Data (K) = Value (Mapping, Source'Loop_Entry.Data (K)));
1847 end loop;
1848 end Super_Translate;
1849
1850 function Super_Translate
1851 (Source : Super_String;
1852 Mapping : Maps.Character_Mapping_Function) return Super_String
1853 is
1854 Result : Super_String (Source.Max_Length);
1855
1856 begin
1857 for J in 1 .. Source.Current_Length loop
1858 Result.Data (J) := Mapping.all (Source.Data (J));
1859 pragma Annotate (GNATprove, False_Positive,
1860 "call via access-to-subprogram",
1861 "function Mapping must always terminate");
1862 pragma Loop_Invariant (Result.Data (1 .. J)'Initialized);
1863 pragma Loop_Invariant
1864 (for all K in 1 .. J =>
1865 Result.Data (K) = Mapping (Source.Data (K)));
1866 pragma Annotate (GNATprove, False_Positive,
1867 "call via access-to-subprogram",
1868 "function Mapping must always terminate");
1869 end loop;
1870
1871 Result.Current_Length := Source.Current_Length;
1872 return Result;
1873 end Super_Translate;
1874
1875 procedure Super_Translate
1876 (Source : in out Super_String;
1877 Mapping : Maps.Character_Mapping_Function)
1878 is
1879 begin
1880 for J in 1 .. Source.Current_Length loop
1881 Source.Data (J) := Mapping.all (Source.Data (J));
1882 pragma Annotate (GNATprove, False_Positive,
1883 "call via access-to-subprogram",
1884 "function Mapping must always terminate");
1885 pragma Loop_Invariant
1886 (for all K in 1 .. J =>
1887 Source.Data (K) = Mapping (Source'Loop_Entry.Data (K)));
1888 pragma Annotate (GNATprove, False_Positive,
1889 "call via access-to-subprogram",
1890 "function Mapping must always terminate");
1891 end loop;
1892 end Super_Translate;
1893
1894 ----------------
1895 -- Super_Trim --
1896 ----------------
1897
1898 function Super_Trim
1899 (Source : Super_String;
1900 Side : Trim_End) return Super_String
1901 is
1902 Result : Super_String (Source.Max_Length);
1903 Last : constant Natural := Source.Current_Length;
1904
1905 begin
1906 case Side is
1907 when Strings.Left =>
1908 declare
1909 Low : constant Natural :=
1910 Super_Index_Non_Blank (Source, Forward);
1911 begin
1912 -- All blanks case
1913
1914 if Low = 0 then
1915 return Result;
1916 end if;
1917
1918 Result.Data (1 .. Last - Low + 1) := Source.Data (Low .. Last);
1919 Result.Current_Length := Last - Low + 1;
1920 end;
1921
1922 when Strings.Right =>
1923 declare
1924 High : constant Natural :=
1925 Super_Index_Non_Blank (Source, Backward);
1926 begin
1927 -- All blanks case
1928
1929 if High = 0 then
1930 return Result;
1931 end if;
1932
1933 Result.Data (1 .. High) := Source.Data (1 .. High);
1934 Result.Current_Length := High;
1935 end;
1936
1937 when Strings.Both =>
1938 declare
1939 Low : constant Natural :=
1940 Super_Index_Non_Blank (Source, Forward);
1941 begin
1942 -- All blanks case
1943
1944 if Low = 0 then
1945 return Result;
1946 end if;
1947
1948 declare
1949 High : constant Natural :=
1950 Super_Index_Non_Blank (Source, Backward);
1951 begin
1952 Result.Data (1 .. High - Low + 1) :=
1953 Source.Data (Low .. High);
1954 Result.Current_Length := High - Low + 1;
1955 end;
1956 end;
1957 end case;
1958
1959 return Result;
1960 end Super_Trim;
1961
1962 procedure Super_Trim
1963 (Source : in out Super_String;
1964 Side : Trim_End)
1965 is
1966 Last : constant Natural := Source.Current_Length;
1967 begin
1968 case Side is
1969 when Strings.Left =>
1970 declare
1971 Low : constant Natural :=
1972 Super_Index_Non_Blank (Source, Forward);
1973 begin
1974 -- All blanks case
1975
1976 if Low = 0 then
1977 Source.Current_Length := 0;
1978 else
1979 Source.Data (1 .. Last - Low + 1) :=
1980 Source.Data (Low .. Last);
1981 Source.Current_Length := Last - Low + 1;
1982 end if;
1983 end;
1984
1985 when Strings.Right =>
1986 declare
1987 High : constant Natural :=
1988 Super_Index_Non_Blank (Source, Backward);
1989 begin
1990 Source.Current_Length := High;
1991 end;
1992
1993 when Strings.Both =>
1994 declare
1995 Low : constant Natural :=
1996 Super_Index_Non_Blank (Source, Forward);
1997 begin
1998 -- All blanks case
1999
2000 if Low = 0 then
2001 Source.Current_Length := 0;
2002 else
2003 declare
2004 High : constant Natural :=
2005 Super_Index_Non_Blank (Source, Backward);
2006 begin
2007 Source.Data (1 .. High - Low + 1) :=
2008 Source.Data (Low .. High);
2009 Source.Current_Length := High - Low + 1;
2010 end;
2011 end if;
2012 end;
2013 end case;
2014 end Super_Trim;
2015
2016 function Super_Trim
2017 (Source : Super_String;
2018 Left : Maps.Character_Set;
2019 Right : Maps.Character_Set) return Super_String
2020 is
2021 Result : Super_String (Source.Max_Length);
2022 Low : Natural;
2023 High : Natural;
2024
2025 begin
2026 Low := Super_Index (Source, Left, Outside, Forward);
2027
2028 -- Case where source comprises only characters in Left
2029
2030 if Low = 0 then
2031 return Result;
2032 end if;
2033
2034 High := Super_Index (Source, Right, Outside, Backward);
2035
2036 -- Case where source comprises only characters in Right
2037
2038 if High = 0 then
2039 return Result;
2040 end if;
2041
2042 if High >= Low then
2043 Result.Data (1 .. High - Low + 1) := Source.Data (Low .. High);
2044 Result.Current_Length := High - Low + 1;
2045 end if;
2046
2047 return Result;
2048 end Super_Trim;
2049
2050 procedure Super_Trim
2051 (Source : in out Super_String;
2052 Left : Maps.Character_Set;
2053 Right : Maps.Character_Set)
2054 is
2055 Last : constant Natural := Source.Current_Length;
2056 Temp : Super_String_Data (1 .. Last);
2057 Low : Natural;
2058 High : Natural;
2059
2060 begin
2061 Temp := Source.Data (1 .. Last);
2062 Low := Super_Index (Source, Left, Outside, Forward);
2063
2064 -- Case where source comprises only characters in Left
2065
2066 if Low = 0 then
2067 Source.Current_Length := 0;
2068
2069 else
2070 High := Super_Index (Source, Right, Outside, Backward);
2071
2072 -- Case where source comprises only characters in Right
2073
2074 if High = 0 then
2075 Source.Current_Length := 0;
2076
2077 elsif Low = 1 then
2078 Source.Current_Length := High;
2079
2080 elsif High < Low then
2081 Source.Current_Length := 0;
2082
2083 else
2084 Source.Data (1 .. High - Low + 1) := Temp (Low .. High);
2085 Source.Current_Length := High - Low + 1;
2086 end if;
2087 end if;
2088 end Super_Trim;
2089
2090 -----------
2091 -- Times --
2092 -----------
2093
2094 function Times
2095 (Left : Natural;
2096 Right : Character;
2097 Max_Length : Positive) return Super_String
2098 is
2099 Result : Super_String (Max_Length);
2100
2101 begin
2102 if Left > Max_Length then
2103 raise Ada.Strings.Length_Error;
2104
2105 else
2106 for J in 1 .. Left loop
2107 Result.Data (J) := Right;
2108 pragma Loop_Invariant (Result.Data (1 .. J)'Initialized);
2109 pragma Loop_Invariant
2110 (for all K in 1 .. J => Result.Data (K) = Right);
2111 end loop;
2112
2113 Result.Current_Length := Left;
2114 end if;
2115
2116 return Result;
2117 end Times;
2118
2119 function Times
2120 (Left : Natural;
2121 Right : String;
2122 Max_Length : Positive) return Super_String
2123 is
2124 Result : Super_String (Max_Length);
2125 Pos : Natural := 0;
2126 Rlen : constant Natural := Right'Length;
2127 Nlen : constant Natural := Left * Rlen;
2128
2129 -- Parts of the proof involving manipulations with the modulo operator
2130 -- are complicated for the prover and can't be done automatically in
2131 -- the global subprogram. That's why we isolate them in these two ghost
2132 -- lemmas.
2133
2134 procedure Lemma_Mod (K : Integer) with
2135 Ghost,
2136 Pre =>
2137 Rlen /= 0
2138 and then Pos mod Rlen = 0
2139 and then Pos in 0 .. Max_Length - Rlen
2140 and then K in Pos .. Pos + Rlen - 1,
2141 Post => K mod Rlen = K - Pos;
2142 -- Lemma_Mod is applied to an index considered in Lemma_Split to prove
2143 -- that it has the right value modulo Right'Length.
2144
2145 procedure Lemma_Split with
2146 Ghost,
2147 Pre =>
2148 Rlen /= 0
2149 and then Pos mod Rlen = 0
2150 and then Pos in 0 .. Max_Length - Rlen
2151 and then Result.Data (1 .. Pos + Rlen)'Initialized
2152 and then String (Result.Data (Pos + 1 .. Pos + Rlen)) = Right,
2153 Post =>
2154 (for all K in Pos + 1 .. Pos + Rlen =>
2155 Result.Data (K) = Right (Right'First + (K - 1) mod Rlen));
2156 -- Lemma_Split is used after Result.Data (Pos + 1 .. Pos + Rlen) is
2157 -- updated to Right and concludes that the characters match for each
2158 -- index when taken modulo Right'Length, as the considered slice starts
2159 -- at index 1 modulo Right'Length.
2160
2161 ---------------
2162 -- Lemma_Mod --
2163 ---------------
2164
2165 procedure Lemma_Mod (K : Integer) is null;
2166
2167 -----------------
2168 -- Lemma_Split --
2169 -----------------
2170
2171 procedure Lemma_Split is
2172 begin
2173 for K in Pos + 1 .. Pos + Rlen loop
2174 Lemma_Mod (K - 1);
2175 pragma Loop_Invariant
2176 (for all J in Pos + 1 .. K =>
2177 Result.Data (J) = Right (Right'First + (J - 1) mod Rlen));
2178 end loop;
2179 end Lemma_Split;
2180
2181 begin
2182 if Nlen > Max_Length then
2183 raise Ada.Strings.Length_Error;
2184
2185 else
2186 if Nlen > 0 then
2187 for J in 1 .. Left loop
2188 Result.Data (Pos + 1 .. Pos + Rlen) :=
2189 Super_String_Data (Right);
2190 pragma Assert
2191 (for all K in 1 .. Rlen => Result.Data (Pos + K) =
2192 Right (Right'First - 1 + K));
2193 pragma Assert
2194 (String (Result.Data (Pos + 1 .. Pos + Rlen)) = Right);
2195 Lemma_Split;
2196 Pos := Pos + Rlen;
2197 pragma Loop_Invariant (Pos = J * Rlen);
2198 pragma Loop_Invariant (Result.Data (1 .. Pos)'Initialized);
2199 pragma Loop_Invariant
2200 (for all K in 1 .. Pos =>
2201 Result.Data (K) =
2202 Right (Right'First + (K - 1) mod Rlen));
2203 end loop;
2204 end if;
2205
2206 Result.Current_Length := Nlen;
2207 end if;
2208
2209 return Result;
2210 end Times;
2211
2212 function Times
2213 (Left : Natural;
2214 Right : Super_String) return Super_String
2215 is
2216 Result : Super_String (Right.Max_Length);
2217 Pos : Natural := 0;
2218 Rlen : constant Natural := Right.Current_Length;
2219 Nlen : constant Natural := Left * Rlen;
2220
2221 begin
2222 if Nlen > Right.Max_Length then
2223 raise Ada.Strings.Length_Error;
2224
2225 else
2226 if Nlen > 0 then
2227 for J in 1 .. Left loop
2228 Result.Data (Pos + 1 .. Pos + Rlen) :=
2229 Right.Data (1 .. Rlen);
2230 Pos := Pos + Rlen;
2231 pragma Loop_Invariant (Pos = J * Rlen);
2232 pragma Loop_Invariant (Result.Data (1 .. Pos)'Initialized);
2233 pragma Loop_Invariant
2234 (for all K in 1 .. Pos =>
2235 Result.Data (K) =
2236 Right.Data (1 + (K - 1) mod Rlen));
2237 end loop;
2238 end if;
2239
2240 Result.Current_Length := Nlen;
2241 end if;
2242
2243 return Result;
2244 end Times;
2245
2246 ---------------------
2247 -- To_Super_String --
2248 ---------------------
2249
2250 function To_Super_String
2251 (Source : String;
2252 Max_Length : Positive;
2253 Drop : Truncation := Error) return Super_String
2254 is
2255 Result : Super_String (Max_Length);
2256 Slen : constant Natural := Source'Length;
2257
2258 begin
2259 if Slen <= Max_Length then
2260 Result.Data (1 .. Slen) := Super_String_Data (Source);
2261 Result.Current_Length := Slen;
2262
2263 else
2264 case Drop is
2265 when Strings.Right =>
2266 Result.Data (1 .. Max_Length) := Super_String_Data
2267 (Source (Source'First .. Source'First - 1 + Max_Length));
2268 Result.Current_Length := Max_Length;
2269
2270 when Strings.Left =>
2271 Result.Data (1 .. Max_Length) := Super_String_Data
2272 (Source (Source'Last - (Max_Length - 1) .. Source'Last));
2273 Result.Current_Length := Max_Length;
2274
2275 when Strings.Error =>
2276 raise Ada.Strings.Length_Error;
2277 end case;
2278 end if;
2279
2280 return Result;
2281 end To_Super_String;
2282
2283 end Ada.Strings.Superbounded;