Debian Codegraph @

gcc/ada/libgnat/a-strbou.ads

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . S T R I N G S . B O U N D E D --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2025, Free Software Foundation, Inc. --
10 -- --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
14 -- --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
21 -- --
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
23 -- additional permissions described in the GCC Runtime Library Exception, --
24 -- version 3.1, as published by the Free Software Foundation. --
25 -- --
26 -- You should have received a copy of the GNU General Public License and --
27 -- a copy of the GCC Runtime Library Exception along with this program; --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
29 -- <http://www.gnu.org/licenses/>. --
30 -- --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 -- --
34 ------------------------------------------------------------------------------
35
36 -- The language-defined package Strings.Bounded provides a generic package
37 -- each of whose instances yields a private type Bounded_String and a set
38 -- of operations. An object of a particular Bounded_String type represents
39 -- a String whose low bound is 1 and whose length can vary conceptually
40 -- between 0 and a maximum size established at the generic instantiation. The
41 -- subprograms for fixed-length string handling are either overloaded directly
42 -- for Bounded_String, or are modified as needed to reflect the variability in
43 -- length. Additionally, since the Bounded_String type is private, appropriate
44 -- constructor and selector operations are provided.
45
46 with Ada.Strings.Maps; use type Ada.Strings.Maps.Character_Mapping_Function;
47 with Ada.Strings.Superbounded;
48 with Ada.Strings.Search;
49
50 package Ada.Strings.Bounded with
51 SPARK_Mode,
52 Always_Terminates
53 is
54 pragma Preelaborate;
55
56 generic
57 Max : Positive;
58 -- Maximum length of a Bounded_String
59
60 package Generic_Bounded_Length with SPARK_Mode,
61 Initial_Condition => Length (Null_Bounded_String) = 0,
62 Abstract_State => null,
63 Always_Terminates
64 is
65 -- Preconditions in this unit are meant for analysis only, not for
66 -- run-time checking, so that the expected exceptions are raised. This
67 -- is enforced by setting the corresponding assertion policy to Ignore.
68 -- Postconditions and contract cases should not be executed at runtime
69 -- as well, in order not to slow down the execution of these functions.
70
71 pragma Assertion_Policy (Pre => Ignore,
72 Post => Ignore,
73 Contract_Cases => Ignore,
74 Ghost => Ignore);
75
76 Max_Length : constant Positive := Max;
77
78 type Bounded_String is private;
79 pragma Preelaborable_Initialization (Bounded_String);
80
81 Null_Bounded_String : constant Bounded_String;
82 -- Null_Bounded_String represents the null string. If an object of type
83 -- Bounded_String is not otherwise initialized, it will be initialized
84 -- to the same value as Null_Bounded_String.
85
86 subtype Length_Range is Natural range 0 .. Max_Length;
87
88 function Length (Source : Bounded_String) return Length_Range with
89 Global => null;
90 -- The Length function returns the length of the string represented by
91 -- Source.
92
93 --------------------------------------------------------
94 -- Conversion, Concatenation, and Selection Functions --
95 --------------------------------------------------------
96
97 function To_Bounded_String
98 (Source : String;
99 Drop : Truncation := Error) return Bounded_String
100 with
101 Pre => (if Source'Length > Max_Length then Drop /= Error),
102 Contract_Cases =>
103 (Source'Length <= Max_Length
104 =>
105 To_String (To_Bounded_String'Result) = Source,
106
107 Source'Length > Max_Length and then Drop = Left
108 =>
109 To_String (To_Bounded_String'Result) =
110 Source (Source'Last - Max_Length + 1 .. Source'Last),
111
112 others -- Drop = Right
113 =>
114 To_String (To_Bounded_String'Result) =
115 Source (Source'First .. Source'First - 1 + Max_Length));
116 -- If Source'Length <= Max_Length, then this function returns a
117 -- Bounded_String that represents Source. Otherwise, the effect
118 -- depends on the value of Drop:
119 --
120 -- * If Drop=Left, then the result is a Bounded_String that represents
121 -- the string comprising the rightmost Max_Length characters of
122 -- Source.
123 --
124 -- * If Drop=Right, then the result is a Bounded_String that represents
125 -- the string comprising the leftmost Max_Length characters of Source.
126 --
127 -- * If Drop=Error, then Strings.Length_Error is propagated.
128
129 function To_String (Source : Bounded_String) return String with
130 Post =>
131 To_String'Result'First = 1
132 and then To_String'Result'Length = Length (Source),
133 Global => null;
134 -- To_String returns the String value with lower bound 1
135 -- represented by Source. If B is a Bounded_String, then
136 -- B = To_Bounded_String(To_String(B)).
137
138 procedure Set_Bounded_String
139 (Target : out Bounded_String;
140 Source : String;
141 Drop : Truncation := Error)
142 with
143 Pre => (if Source'Length > Max_Length then Drop /= Error),
144 Contract_Cases =>
145 (Source'Length <= Max_Length
146 =>
147 To_String (Target) = Source,
148
149 Source'Length > Max_Length and then Drop = Left
150 =>
151 To_String (Target) =
152 Source (Source'Last - Max_Length + 1 .. Source'Last),
153
154 others -- Drop = Right
155 =>
156 To_String (Target) =
157 Source (Source'First .. Source'First - 1 + Max_Length));
158 pragma Ada_05 (Set_Bounded_String);
159 -- Equivalent to Target := To_Bounded_String (Source, Drop);
160
161 -- Each of the Append functions returns a Bounded_String obtained by
162 -- concatenating the string or character given or represented by one
163 -- of the parameters, with the string or character given or represented
164 -- by the other parameter, and applying To_Bounded_String to the
165 -- concatenation result string, with Drop as provided to the Append
166 -- function.
167
168 function Append
169 (Left : Bounded_String;
170 Right : Bounded_String;
171 Drop : Truncation := Error) return Bounded_String
172 with
173 Pre =>
174 (if Length (Left) > Max_Length - Length (Right)
175 then Drop /= Error),
176 Contract_Cases =>
177 (Length (Left) <= Max_Length - Length (Right)
178 =>
179 Length (Append'Result) = Length (Left) + Length (Right)
180 and then
181 Slice (Append'Result, 1, Length (Left)) = To_String (Left)
182 and then
183 (if Length (Right) > 0 then
184 Slice (Append'Result,
185 Length (Left) + 1, Length (Append'Result)) =
186 To_String (Right)),
187
188 Length (Left) > Max_Length - Length (Right)
189 and then Drop = Strings.Left
190 =>
191 Length (Append'Result) = Max_Length
192 and then
193 (if Length (Right) < Max_Length then
194 Slice (Append'Result, 1, Max_Length - Length (Right)) =
195 Slice (Left,
196 Length (Left) - Max_Length + Length (Right) + 1,
197 Length (Left)))
198 and then
199 Slice (Append'Result,
200 Max_Length - Length (Right) + 1, Max_Length) =
201 To_String (Right),
202
203 others -- Drop = Right
204 =>
205 Length (Append'Result) = Max_Length
206 and then
207 Slice (Append'Result, 1, Length (Left)) = To_String (Left)
208 and then
209 (if Length (Left) < Max_Length then
210 Slice (Append'Result, Length (Left) + 1, Max_Length) =
211 Slice (Right, 1, Max_Length - Length (Left))));
212
213 function Append
214 (Left : Bounded_String;
215 Right : String;
216 Drop : Truncation := Error) return Bounded_String
217 with
218 Pre =>
219 (if Right'Length > Max_Length - Length (Left)
220 then Drop /= Error),
221 Contract_Cases =>
222 (Length (Left) <= Max_Length - Right'Length
223 =>
224 Length (Append'Result) = Length (Left) + Right'Length
225 and then
226 Slice (Append'Result, 1, Length (Left)) = To_String (Left)
227 and then
228 (if Right'Length > 0 then
229 Slice (Append'Result,
230 Length (Left) + 1, Length (Append'Result)) =
231 Right),
232
233 Length (Left) > Max_Length - Right'Length
234 and then Drop = Strings.Left
235 =>
236 Length (Append'Result) = Max_Length
237 and then
238 (if Right'Length < Max_Length then
239
240 -- The result is the end of Left followed by Right
241
242 Slice (Append'Result, 1, Max_Length - Right'Length) =
243 Slice (Left,
244 Length (Left) - Max_Length + Right'Length + 1,
245 Length (Left))
246 and then
247 Slice (Append'Result,
248 Max_Length - Right'Length + 1, Max_Length) =
249 Right
250 else
251 -- The result is the last Max_Length characters of Right
252
253 To_String (Append'Result) =
254 Right (Right'Last - Max_Length + 1 .. Right'Last)),
255
256 others -- Drop = Right
257 =>
258 Length (Append'Result) = Max_Length
259 and then
260 Slice (Append'Result, 1, Length (Left)) = To_String (Left)
261 and then
262 (if Length (Left) < Max_Length then
263 Slice (Append'Result, Length (Left) + 1, Max_Length) =
264 Right (Right'First
265 .. Max_Length - Length (Left) - 1 + Right'First)));
266 function Append
267 (Left : String;
268 Right : Bounded_String;
269 Drop : Truncation := Error) return Bounded_String
270 with
271 Pre =>
272 (if Left'Length > Max_Length - Length (Right)
273 then Drop /= Error),
274 Contract_Cases =>
275 (Left'Length <= Max_Length - Length (Right)
276 =>
277 Length (Append'Result) = Left'Length + Length (Right)
278 and then Slice (Append'Result, 1, Left'Length) = Left
279 and then
280 (if Length (Right) > 0 then
281 Slice (Append'Result,
282 Left'Length + 1, Length (Append'Result)) =
283 To_String (Right)),
284
285 Left'Length > Max_Length - Length (Right)
286 and then Drop = Strings.Left
287 =>
288 Length (Append'Result) = Max_Length
289 and then
290 (if Length (Right) < Max_Length then
291 Slice (Append'Result, 1, Max_Length - Length (Right)) =
292 Left (Left'Last - Max_Length + Length (Right) + 1
293 .. Left'Last))
294 and then
295 Slice (Append'Result,
296 Max_Length - Length (Right) + 1, Max_Length) =
297 To_String (Right),
298
299 others -- Drop = Right
300 =>
301 Length (Append'Result) = Max_Length
302 and then
303 (if Left'Length < Max_Length then
304
305 -- The result is Left followed by the beginning of Right
306
307 Slice (Append'Result, 1, Left'Length) = Left
308 and then
309 Slice (Append'Result, Left'Length + 1, Max_Length) =
310 Slice (Right, 1, Max_Length - Left'Length)
311 else
312 -- The result is the first Max_Length characters of Left
313
314 To_String (Append'Result) =
315 Left (Left'First .. Max_Length - 1 + Left'First)));
316
317 function Append
318 (Left : Bounded_String;
319 Right : Character;
320 Drop : Truncation := Error) return Bounded_String
321 with
322 Pre => (if Length (Left) = Max_Length then Drop /= Error),
323 Contract_Cases =>
324 (Length (Left) < Max_Length
325 =>
326 Length (Append'Result) = Length (Left) + 1
327 and then
328 Slice (Append'Result, 1, Length (Left)) = To_String (Left)
329 and then Element (Append'Result, Length (Left) + 1) = Right,
330
331 Length (Left) = Max_Length and then Drop = Strings.Right
332 =>
333 Length (Append'Result) = Max_Length
334 and then To_String (Append'Result) = To_String (Left),
335
336 others -- Drop = Left
337 =>
338 Length (Append'Result) = Max_Length
339 and then
340 Slice (Append'Result, 1, Max_Length - 1) =
341 Slice (Left, 2, Max_Length)
342 and then Element (Append'Result, Max_Length) = Right);
343
344 function Append
345 (Left : Character;
346 Right : Bounded_String;
347 Drop : Truncation := Error) return Bounded_String
348 with
349 Pre => (if Length (Right) = Max_Length then Drop /= Error),
350 Contract_Cases =>
351 (Length (Right) < Max_Length
352 =>
353 Length (Append'Result) = Length (Right) + 1
354 and then
355 Slice (Append'Result, 2, Length (Right) + 1) =
356 To_String (Right)
357 and then Element (Append'Result, 1) = Left,
358
359 Length (Right) = Max_Length and then Drop = Strings.Left
360 =>
361 Length (Append'Result) = Max_Length
362 and then To_String (Append'Result) = To_String (Right),
363
364 others -- Drop = Right
365 =>
366 Length (Append'Result) = Max_Length
367 and then
368 Slice (Append'Result, 2, Max_Length) =
369 Slice (Right, 1, Max_Length - 1)
370 and then Element (Append'Result, 1) = Left);
371
372 -- Each of the procedures Append(Source, New_Item, Drop) has the same
373 -- effect as the corresponding assignment
374 -- Source := Append(Source, New_Item, Drop).
375
376 procedure Append
377 (Source : in out Bounded_String;
378 New_Item : Bounded_String;
379 Drop : Truncation := Error)
380 with
381 Pre =>
382 (if Length (Source) > Max_Length - Length (New_Item)
383 then Drop /= Error),
384 Contract_Cases =>
385 (Length (Source) <= Max_Length - Length (New_Item)
386 =>
387 Length (Source) = Length (Source'Old) + Length (New_Item)
388 and then
389 Slice (Source, 1, Length (Source'Old)) =
390 To_String (Source'Old)
391 and then
392 (if Length (New_Item) > 0 then
393 Slice (Source, Length (Source'Old) + 1, Length (Source)) =
394 To_String (New_Item)),
395
396 Length (Source) > Max_Length - Length (New_Item)
397 and then Drop = Left
398 =>
399 Length (Source) = Max_Length
400 and then
401 (if Length (New_Item) < Max_Length then
402 Slice (Source, 1, Max_Length - Length (New_Item)) =
403 Slice (Source'Old,
404 Length (Source'Old) - Max_Length + Length (New_Item)
405 + 1,
406 Length (Source'Old)))
407 and then
408 Slice (Source, Max_Length - Length (New_Item) + 1, Max_Length)
409 = To_String (New_Item),
410
411 others -- Drop = Right
412 =>
413 Length (Source) = Max_Length
414 and then
415 Slice (Source, 1, Length (Source'Old)) =
416 To_String (Source'Old)
417 and then
418 (if Length (Source'Old) < Max_Length then
419 Slice (Source, Length (Source'Old) + 1, Max_Length) =
420 Slice (New_Item, 1, Max_Length - Length (Source'Old))));
421
422 procedure Append
423 (Source : in out Bounded_String;
424 New_Item : String;
425 Drop : Truncation := Error)
426 with
427 Pre =>
428 (if New_Item'Length > Max_Length - Length (Source)
429 then Drop /= Error),
430 Contract_Cases =>
431 (Length (Source) <= Max_Length - New_Item'Length
432 =>
433 Length (Source) = Length (Source'Old) + New_Item'Length
434 and then
435 Slice (Source, 1, Length (Source'Old)) =
436 To_String (Source'Old)
437 and then
438 (if New_Item'Length > 0 then
439 Slice (Source, Length (Source'Old) + 1, Length (Source)) =
440 New_Item),
441
442 Length (Source) > Max_Length - New_Item'Length
443 and then Drop = Left
444 =>
445 Length (Source) = Max_Length
446 and then
447 (if New_Item'Length < Max_Length then
448
449 -- The result is the end of Source followed by New_Item
450
451 Slice (Source, 1, Max_Length - New_Item'Length) =
452 Slice (Source'Old,
453 Length (Source'Old) - Max_Length + New_Item'Length + 1,
454 Length (Source'Old))
455 and then
456 Slice (Source,
457 Max_Length - New_Item'Length + 1, Max_Length) =
458 New_Item
459 else
460 -- The result is the last Max_Length characters of
461 -- New_Item.
462
463 To_String (Source) = New_Item
464 (New_Item'Last - Max_Length + 1 .. New_Item'Last)),
465
466 others -- Drop = Right
467 =>
468 Length (Source) = Max_Length
469 and then
470 Slice (Source, 1, Length (Source'Old)) =
471 To_String (Source'Old)
472 and then
473 (if Length (Source'Old) < Max_Length then
474 Slice (Source, Length (Source'Old) + 1, Max_Length) =
475 New_Item (New_Item'First
476 .. Max_Length - Length (Source'Old) - 1
477 + New_Item'First)));
478
479 procedure Append
480 (Source : in out Bounded_String;
481 New_Item : Character;
482 Drop : Truncation := Error)
483 with
484 Pre => (if Length (Source) = Max_Length then Drop /= Error),
485 Contract_Cases =>
486 (Length (Source) < Max_Length
487 =>
488 Length (Source) = Length (Source'Old) + 1
489 and then
490 Slice (Source, 1, Length (Source'Old)) =
491 To_String (Source'Old)
492 and then Element (Source, Length (Source'Old) + 1) = New_Item,
493
494 Length (Source) = Max_Length and then Drop = Right
495 =>
496 Length (Source) = Max_Length
497 and then To_String (Source) = To_String (Source'Old),
498
499 others -- Drop = Left
500 =>
501 Length (Source) = Max_Length
502 and then
503 Slice (Source, 1, Max_Length - 1) =
504 Slice (Source'Old, 2, Max_Length)
505 and then Element (Source, Max_Length) = New_Item);
506
507 -- Each of the "&" functions has the same effect as the corresponding
508 -- Append function, with Error as the Drop parameter.
509
510 function "&"
511 (Left : Bounded_String;
512 Right : Bounded_String) return Bounded_String
513 with
514 Pre => Length (Left) <= Max_Length - Length (Right),
515 Post => Length ("&"'Result) = Length (Left) + Length (Right)
516 and then Slice ("&"'Result, 1, Length (Left)) = To_String (Left)
517 and then
518 (if Length (Right) > 0 then
519 Slice ("&"'Result, Length (Left) + 1, Length ("&"'Result)) =
520 To_String (Right));
521
522 function "&"
523 (Left : Bounded_String;
524 Right : String) return Bounded_String
525 with
526 Pre => Right'Length <= Max_Length - Length (Left),
527 Post => Length ("&"'Result) = Length (Left) + Right'Length
528 and then Slice ("&"'Result, 1, Length (Left)) = To_String (Left)
529 and then
530 (if Right'Length > 0 then
531 Slice ("&"'Result, Length (Left) + 1, Length ("&"'Result)) =
532 Right);
533
534 function "&"
535 (Left : String;
536 Right : Bounded_String) return Bounded_String
537 with
538 Pre => Left'Length <= Max_Length - Length (Right),
539 Post => Length ("&"'Result) = Left'Length + Length (Right)
540 and then Slice ("&"'Result, 1, Left'Length) = Left
541 and then
542 (if Length (Right) > 0 then
543 Slice ("&"'Result, Left'Length + 1, Length ("&"'Result)) =
544 To_String (Right));
545
546 function "&"
547 (Left : Bounded_String;
548 Right : Character) return Bounded_String
549 with
550 Pre => Length (Left) < Max_Length,
551 Post => Length ("&"'Result) = Length (Left) + 1
552 and then Slice ("&"'Result, 1, Length (Left)) = To_String (Left)
553 and then Element ("&"'Result, Length (Left) + 1) = Right;
554
555 function "&"
556 (Left : Character;
557 Right : Bounded_String) return Bounded_String
558 with
559 Pre => Length (Right) < Max_Length,
560 Post => Length ("&"'Result) = 1 + Length (Right)
561 and then Element ("&"'Result, 1) = Left
562 and then
563 Slice ("&"'Result, 2, Length ("&"'Result)) = To_String (Right);
564
565 function Element
566 (Source : Bounded_String;
567 Index : Positive) return Character
568 with
569 Pre => Index <= Length (Source),
570 Global => null;
571 -- Returns the character at position Index in the string represented by
572 -- Source; propagates Index_Error if Index > Length(Source).
573
574 procedure Replace_Element
575 (Source : in out Bounded_String;
576 Index : Positive;
577 By : Character)
578 with
579 Pre => Index <= Length (Source),
580 Post => Length (Source) = Length (Source'Old)
581 and then (for all K in 1 .. Length (Source) =>
582 Element (Source, K) =
583 (if K = Index then By else Element (Source'Old, K))),
584 Global => null;
585 -- Updates Source such that the character at position Index in the
586 -- string represented by Source is By; propagates Index_Error if
587 -- Index > Length(Source).
588
589 function Slice
590 (Source : Bounded_String;
591 Low : Positive;
592 High : Natural) return String
593 with
594 Pre => Low - 1 <= Length (Source) and then High <= Length (Source),
595 Global => null;
596 -- Returns the slice at positions Low through High in the
597 -- string represented by Source; propagates Index_Error if
598 -- Low > Length(Source)+1 or High > Length(Source).
599 -- The bounds of the returned string are Low and High.
600
601 function Bounded_Slice
602 (Source : Bounded_String;
603 Low : Positive;
604 High : Natural) return Bounded_String
605 with
606 Pre => Low - 1 <= Length (Source) and then High <= Length (Source),
607 Post => To_String (Bounded_Slice'Result) = Slice (Source, Low, High),
608 Global => null;
609 pragma Ada_05 (Bounded_Slice);
610 -- Returns the slice at positions Low through High in the string
611 -- represented by Source as a bounded string; propagates Index_Error
612 -- if Low > Length(Source)+1 or High > Length(Source).
613
614 procedure Bounded_Slice
615 (Source : Bounded_String;
616 Target : out Bounded_String;
617 Low : Positive;
618 High : Natural)
619 with
620 Pre => Low - 1 <= Length (Source) and then High <= Length (Source),
621 Post => To_String (Target) = Slice (Source, Low, High),
622 Global => null;
623 pragma Ada_05 (Bounded_Slice);
624 -- Equivalent to Target := Bounded_Slice (Source, Low, High);
625
626 -- Each of the functions "=", "<", ">", "<=", and ">=" returns the same
627 -- result as the corresponding String operation applied to the String
628 -- values given or represented by the two parameters.
629
630 function "="
631 (Left : Bounded_String;
632 Right : Bounded_String) return Boolean
633 with
634 Post => "="'Result = (To_String (Left) = To_String (Right)),
635 Global => null;
636
637 function "="
638 (Left : Bounded_String;
639 Right : String) return Boolean
640 with
641 Post => "="'Result = (To_String (Left) = Right),
642 Global => null;
643
644 function "="
645 (Left : String;
646 Right : Bounded_String) return Boolean
647 with
648 Post => "="'Result = (Left = To_String (Right)),
649 Global => null;
650
651 function "<"
652 (Left : Bounded_String;
653 Right : Bounded_String) return Boolean
654 with
655 Post => "<"'Result = (To_String (Left) < To_String (Right)),
656 Global => null;
657
658 function "<"
659 (Left : Bounded_String;
660 Right : String) return Boolean
661 with
662 Post => "<"'Result = (To_String (Left) < Right),
663 Global => null;
664
665 function "<"
666 (Left : String;
667 Right : Bounded_String) return Boolean
668 with
669 Post => "<"'Result = (Left < To_String (Right)),
670 Global => null;
671
672 function "<="
673 (Left : Bounded_String;
674 Right : Bounded_String) return Boolean
675 with
676 Post => "<="'Result = (To_String (Left) <= To_String (Right)),
677 Global => null;
678
679 function "<="
680 (Left : Bounded_String;
681 Right : String) return Boolean
682 with
683 Post => "<="'Result = (To_String (Left) <= Right),
684 Global => null;
685
686 function "<="
687 (Left : String;
688 Right : Bounded_String) return Boolean
689 with
690 Post => "<="'Result = (Left <= To_String (Right)),
691 Global => null;
692
693 function ">"
694 (Left : Bounded_String;
695 Right : Bounded_String) return Boolean
696 with
697 Post => ">"'Result = (To_String (Left) > To_String (Right)),
698 Global => null;
699
700 function ">"
701 (Left : Bounded_String;
702 Right : String) return Boolean
703 with
704 Post => ">"'Result = (To_String (Left) > Right),
705 Global => null;
706
707 function ">"
708 (Left : String;
709 Right : Bounded_String) return Boolean
710 with
711 Post => ">"'Result = (Left > To_String (Right)),
712 Global => null;
713
714 function ">="
715 (Left : Bounded_String;
716 Right : Bounded_String) return Boolean
717 with
718 Post => ">="'Result = (To_String (Left) >= To_String (Right)),
719 Global => null;
720
721 function ">="
722 (Left : Bounded_String;
723 Right : String) return Boolean
724 with
725 Post => ">="'Result = (To_String (Left) >= Right),
726 Global => null;
727
728 function ">="
729 (Left : String;
730 Right : Bounded_String) return Boolean
731 with
732 Post => ">="'Result = (Left >= To_String (Right)),
733 Global => null;
734
735 ----------------------
736 -- Search Functions --
737 ----------------------
738
739 -- Each of the search subprograms (Index, Index_Non_Blank, Count,
740 -- Find_Token) has the same effect as the corresponding subprogram in
741 -- Strings.Fixed applied to the string represented by the Bounded_String
742 -- parameter.
743
744 function Index
745 (Source : Bounded_String;
746 Pattern : String;
747 Going : Direction := Forward;
748 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
749 with
750 Pre => Pattern'Length > 0,
751 Post => Index'Result <= Length (Source),
752 Contract_Cases =>
753
754 -- If Source is the empty string, then 0 is returned
755
756 (Length (Source) = 0
757 =>
758 Index'Result = 0,
759
760 -- If some slice of Source matches Pattern, then a valid index is
761 -- returned.
762
763 Length (Source) > 0
764 and then
765 (for some J in 1 .. Length (Source) - (Pattern'Length - 1) =>
766 Search.Match (To_String (Source), Pattern, Mapping, J))
767 =>
768 -- The result is in the considered range of Source
769
770 Index'Result in 1 .. Length (Source) - (Pattern'Length - 1)
771
772 -- The slice beginning at the returned index matches Pattern
773
774 and then Search.Match
775 (To_String (Source), Pattern, Mapping, Index'Result)
776
777 -- The result is the smallest or largest index which satisfies
778 -- the matching, respectively when Going = Forward and Going =
779 -- Backward.
780
781 and then
782 (for all J in 1 .. Length (Source) =>
783 (if (if Going = Forward
784 then J <= Index'Result - 1
785 else J - 1 in Index'Result
786 .. Length (Source) - Pattern'Length)
787 then not Search.Match
788 (To_String (Source), Pattern, Mapping, J))),
789
790 -- Otherwise, 0 is returned
791
792 others
793 =>
794 Index'Result = 0),
795 Global => null;
796
797 function Index
798 (Source : Bounded_String;
799 Pattern : String;
800 Going : Direction := Forward;
801 Mapping : Maps.Character_Mapping_Function) return Natural
802 with
803 Pre => Pattern'Length /= 0 and then Mapping /= null,
804 Post => Index'Result <= Length (Source),
805 Contract_Cases =>
806
807 -- If Source is the empty string, then 0 is returned
808
809 (Length (Source) = 0
810 =>
811 Index'Result = 0,
812
813 -- If some slice of Source matches Pattern, then a valid index is
814 -- returned.
815
816 Length (Source) > 0
817 and then
818 (for some J in 1 .. Length (Source) - (Pattern'Length - 1) =>
819 Search.Match (To_String (Source), Pattern, Mapping, J))
820 =>
821 -- The result is in the considered range of Source
822
823 Index'Result in 1 .. Length (Source) - (Pattern'Length - 1)
824
825 -- The slice beginning at the returned index matches Pattern
826
827 and then Search.Match
828 (To_String (Source), Pattern, Mapping, Index'Result)
829
830 -- The result is the smallest or largest index which satisfies
831 -- the matching, respectively when Going = Forward and Going =
832 -- Backward.
833
834 and then
835 (for all J in 1 .. Length (Source) =>
836 (if (if Going = Forward
837 then J <= Index'Result - 1
838 else J - 1 in Index'Result
839 .. Length (Source) - Pattern'Length)
840 then not Search.Match
841 (To_String (Source), Pattern, Mapping, J))),
842
843 -- Otherwise, 0 is returned
844
845 others
846 =>
847 Index'Result = 0),
848 Global => null;
849
850 function Index
851 (Source : Bounded_String;
852 Set : Maps.Character_Set;
853 Test : Membership := Inside;
854 Going : Direction := Forward) return Natural
855 with
856 Post => Index'Result <= Length (Source),
857 Contract_Cases =>
858
859 -- If no character of Source satisfies the property Test on Set,
860 -- then 0 is returned.
861
862 ((for all C of To_String (Source) =>
863 (Test = Inside) /= Maps.Is_In (C, Set))
864 =>
865 Index'Result = 0,
866
867 -- Otherwise, an index in the range of Source is returned
868
869 others
870 =>
871 -- The result is in the range of Source
872
873 Index'Result in 1 .. Length (Source)
874
875 -- The character at the returned index satisfies the property
876 -- Test on Set.
877
878 and then
879 (Test = Inside) =
880 Maps.Is_In (Element (Source, Index'Result), Set)
881
882 -- The result is the smallest or largest index which satisfies
883 -- the property, respectively when Going = Forward and Going =
884 -- Backward.
885
886 and then
887 (for all J in 1 .. Length (Source) =>
888 (if J /= Index'Result
889 and then (J < Index'Result) = (Going = Forward)
890 then (Test = Inside)
891 /= Maps.Is_In (Element (Source, J), Set)))),
892 Global => null;
893
894 function Index
895 (Source : Bounded_String;
896 Pattern : String;
897 From : Positive;
898 Going : Direction := Forward;
899 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
900 with
901 Pre =>
902 (if Length (Source) /= 0 then From <= Length (Source))
903 and then Pattern'Length /= 0,
904 Post => Index'Result <= Length (Source),
905 Contract_Cases =>
906
907 -- If Source is the empty string, then 0 is returned
908
909 (Length (Source) = 0
910 =>
911 Index'Result = 0,
912
913 -- If some slice of Source matches Pattern, then a valid index is
914 -- returned.
915
916 Length (Source) > 0
917 and then
918 (for some J in
919 (if Going = Forward then From else 1)
920 .. (if Going = Forward then Length (Source) else From)
921 - (Pattern'Length - 1) =>
922 Search.Match (To_String (Source), Pattern, Mapping, J))
923 =>
924 -- The result is in the considered range of Source
925
926 Index'Result in
927 (if Going = Forward then From else 1)
928 .. (if Going = Forward then Length (Source) else From)
929 - (Pattern'Length - 1)
930
931 -- The slice beginning at the returned index matches Pattern
932
933 and then Search.Match
934 (To_String (Source), Pattern, Mapping, Index'Result)
935
936 -- The result is the smallest or largest index which satisfies
937 -- the matching, respectively when Going = Forward and Going =
938 -- Backward.
939
940 and then
941 (for all J in 1 .. Length (Source) =>
942 (if (if Going = Forward
943 then J in From .. Index'Result - 1
944 else J - 1 in Index'Result
945 .. From - Pattern'Length)
946 then not Search.Match
947 (To_String (Source), Pattern, Mapping, J))),
948
949 -- Otherwise, 0 is returned
950
951 others
952 =>
953 Index'Result = 0),
954 Global => null;
955 pragma Ada_05 (Index);
956
957 function Index
958 (Source : Bounded_String;
959 Pattern : String;
960 From : Positive;
961 Going : Direction := Forward;
962 Mapping : Maps.Character_Mapping_Function) return Natural
963 with
964 Pre =>
965 (if Length (Source) /= 0 then From <= Length (Source))
966 and then Pattern'Length /= 0
967 and then Mapping /= null,
968 Post => Index'Result <= Length (Source),
969 Contract_Cases =>
970
971 -- If Source is the empty string, then 0 is returned
972
973 (Length (Source) = 0
974 =>
975 Index'Result = 0,
976
977 -- If some slice of Source matches Pattern, then a valid index is
978 -- returned.
979
980 Length (Source) > 0
981 and then
982 (for some J in
983 (if Going = Forward then From else 1)
984 .. (if Going = Forward then Length (Source) else From)
985 - (Pattern'Length - 1) =>
986 Search.Match (To_String (Source), Pattern, Mapping, J))
987 =>
988 -- The result is in the considered range of Source
989
990 Index'Result in
991 (if Going = Forward then From else 1)
992 .. (if Going = Forward then Length (Source) else From)
993 - (Pattern'Length - 1)
994
995 -- The slice beginning at the returned index matches Pattern
996
997 and then Search.Match
998 (To_String (Source), Pattern, Mapping, Index'Result)
999
1000 -- The result is the smallest or largest index which satisfies
1001 -- the matching, respectively when Going = Forward and Going =
1002 -- Backward.
1003
1004 and then
1005 (for all J in 1 .. Length (Source) =>
1006 (if (if Going = Forward
1007 then J in From .. Index'Result - 1
1008 else J - 1 in Index'Result
1009 .. From - Pattern'Length)
1010 then not Search.Match
1011 (To_String (Source), Pattern, Mapping, J))),
1012
1013 -- Otherwise, 0 is returned
1014
1015 others
1016 =>
1017 Index'Result = 0),
1018 Global => null;
1019 pragma Ada_05 (Index);
1020
1021 function Index
1022 (Source : Bounded_String;
1023 Set : Maps.Character_Set;
1024 From : Positive;
1025 Test : Membership := Inside;
1026 Going : Direction := Forward) return Natural
1027 with
1028 Pre =>
1029 (if Length (Source) /= 0 then From <= Length (Source)),
1030 Post => Index'Result <= Length (Source),
1031 Contract_Cases =>
1032
1033 -- If Source is the empty string, or no character of the considered
1034 -- slice of Source satisfies the property Test on Set, then 0 is
1035 -- returned.
1036
1037 (Length (Source) = 0
1038 or else
1039 (for all J in 1 .. Length (Source) =>
1040 (if J = From or else (J > From) = (Going = Forward) then
1041 (Test = Inside) /= Maps.Is_In (Element (Source, J), Set)))
1042 =>
1043 Index'Result = 0,
1044
1045 -- Otherwise, an index in the considered range of Source is
1046 -- returned.
1047
1048 others
1049 =>
1050 -- The result is in the considered range of Source
1051
1052 Index'Result in 1 .. Length (Source)
1053 and then
1054 (Index'Result = From
1055 or else (Index'Result > From) = (Going = Forward))
1056
1057 -- The character at the returned index satisfies the property
1058 -- Test on Set.
1059
1060 and then
1061 (Test = Inside) =
1062 Maps.Is_In (Element (Source, Index'Result), Set)
1063
1064 -- The result is the smallest or largest index which satisfies
1065 -- the property, respectively when Going = Forward and Going =
1066 -- Backward.
1067
1068 and then
1069 (for all J in 1 .. Length (Source) =>
1070 (if J /= Index'Result
1071 and then (J < Index'Result) = (Going = Forward)
1072 and then (J = From
1073 or else (J > From) = (Going = Forward))
1074 then (Test = Inside)
1075 /= Maps.Is_In (Element (Source, J), Set)))),
1076 Global => null;
1077 pragma Ada_05 (Index);
1078
1079 function Index_Non_Blank
1080 (Source : Bounded_String;
1081 Going : Direction := Forward) return Natural
1082 with
1083 Post => Index_Non_Blank'Result <= Length (Source),
1084 Contract_Cases =>
1085
1086 -- If all characters of Source are Space characters, then 0 is
1087 -- returned.
1088
1089 ((for all C of To_String (Source) => C = ' ')
1090 =>
1091 Index_Non_Blank'Result = 0,
1092
1093 -- Otherwise, an index in the range of Source is returned
1094
1095 others
1096 =>
1097 -- The result is in the range of Source
1098
1099 Index_Non_Blank'Result in 1 .. Length (Source)
1100
1101 -- The character at the returned index is not a Space character
1102
1103 and then Element (Source, Index_Non_Blank'Result) /= ' '
1104
1105 -- The result is the smallest or largest index which is not a
1106 -- Space character, respectively when Going = Forward and Going
1107 -- = Backward.
1108
1109 and then
1110 (for all J in 1 .. Length (Source) =>
1111 (if J /= Index_Non_Blank'Result
1112 and then
1113 (J < Index_Non_Blank'Result) = (Going = Forward)
1114 then Element (Source, J) = ' '))),
1115 Global => null;
1116
1117 function Index_Non_Blank
1118 (Source : Bounded_String;
1119 From : Positive;
1120 Going : Direction := Forward) return Natural
1121 with
1122 Pre =>
1123 (if Length (Source) /= 0 then From <= Length (Source)),
1124 Post => Index_Non_Blank'Result <= Length (Source),
1125 Contract_Cases =>
1126
1127 -- If Source is the empty string, or all characters of the
1128 -- considered slice of Source are Space characters, then 0
1129 -- is returned.
1130
1131 (Length (Source) = 0
1132 or else
1133 (for all J in 1 .. Length (Source) =>
1134 (if J = From or else (J > From) = (Going = Forward) then
1135 Element (Source, J) = ' '))
1136 =>
1137 Index_Non_Blank'Result = 0,
1138
1139 -- Otherwise, an index in the considered range of Source is
1140 -- returned.
1141
1142 others
1143 =>
1144 -- The result is in the considered range of Source
1145
1146 Index_Non_Blank'Result in 1 .. Length (Source)
1147 and then
1148 (Index_Non_Blank'Result = From
1149 or else
1150 (Index_Non_Blank'Result > From) = (Going = Forward))
1151
1152 -- The character at the returned index is not a Space character
1153
1154 and then Element (Source, Index_Non_Blank'Result) /= ' '
1155
1156 -- The result is the smallest or largest index which isn't a
1157 -- Space character, respectively when Going = Forward and Going
1158 -- = Backward.
1159
1160 and then
1161 (for all J in 1 .. Length (Source) =>
1162 (if J /= Index_Non_Blank'Result
1163 and then
1164 (J < Index_Non_Blank'Result) = (Going = Forward)
1165 and then (J = From
1166 or else (J > From) = (Going = Forward))
1167 then Element (Source, J) = ' '))),
1168 Global => null;
1169 pragma Ada_05 (Index_Non_Blank);
1170
1171 function Count
1172 (Source : Bounded_String;
1173 Pattern : String;
1174 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
1175 with
1176 Pre => Pattern'Length /= 0,
1177 Global => null;
1178
1179 function Count
1180 (Source : Bounded_String;
1181 Pattern : String;
1182 Mapping : Maps.Character_Mapping_Function) return Natural
1183 with
1184 Pre => Pattern'Length /= 0 and then Mapping /= null,
1185 Global => null;
1186
1187 function Count
1188 (Source : Bounded_String;
1189 Set : Maps.Character_Set) return Natural
1190 with
1191 Global => null;
1192
1193 procedure Find_Token
1194 (Source : Bounded_String;
1195 Set : Maps.Character_Set;
1196 From : Positive;
1197 Test : Membership;
1198 First : out Positive;
1199 Last : out Natural)
1200 with
1201 Pre =>
1202 (if Length (Source) /= 0 then From <= Length (Source)),
1203 Contract_Cases =>
1204
1205 -- If Source is the empty string, or if no character of the
1206 -- considered slice of Source satisfies the property Test on
1207 -- Set, then First is set to From and Last is set to 0.
1208
1209 (Length (Source) = 0
1210 or else
1211 (for all J in From .. Length (Source) =>
1212 (Test = Inside) /= Maps.Is_In (Element (Source, J), Set))
1213 =>
1214 First = From and then Last = 0,
1215
1216 -- Otherwise, First and Last are set to valid indexes
1217
1218 others
1219 =>
1220 -- First and Last are in the considered range of Source
1221
1222 First in From .. Length (Source)
1223 and then Last in First .. Length (Source)
1224
1225 -- No character between From and First satisfies the property
1226 -- Test on Set.
1227
1228 and then
1229 (for all J in From .. First - 1 =>
1230 (Test = Inside) /= Maps.Is_In (Element (Source, J), Set))
1231
1232 -- All characters between First and Last satisfy the property
1233 -- Test on Set.
1234
1235 and then
1236 (for all J in First .. Last =>
1237 (Test = Inside) = Maps.Is_In (Element (Source, J), Set))
1238
1239 -- If Last is not Source'Last, then the character at position
1240 -- Last + 1 does not satify the property Test on Set.
1241
1242 and then
1243 (if Last < Length (Source)
1244 then
1245 (Test = Inside)
1246 /= Maps.Is_In (Element (Source, Last + 1), Set))),
1247 Global => null;
1248 pragma Ada_2012 (Find_Token);
1249
1250 procedure Find_Token
1251 (Source : Bounded_String;
1252 Set : Maps.Character_Set;
1253 Test : Membership;
1254 First : out Positive;
1255 Last : out Natural)
1256 with
1257 Contract_Cases =>
1258
1259 -- If Source is the empty string, or if no character of the
1260 -- considered slice of Source satisfies the property Test on
1261 -- Set, then First is set to 1 and Last is set to 0.
1262
1263 (Length (Source) = 0
1264 or else
1265 (for all J in 1 .. Length (Source) =>
1266 (Test = Inside) /= Maps.Is_In (Element (Source, J), Set))
1267 =>
1268 First = 1 and then Last = 0,
1269
1270 -- Otherwise, First and Last are set to valid indexes
1271
1272 others
1273 =>
1274 -- First and Last are in the considered range of Source
1275
1276 First in 1 .. Length (Source)
1277 and then Last in First .. Length (Source)
1278
1279 -- No character between 1 and First satisfies the property Test
1280 -- on Set.
1281
1282 and then
1283 (for all J in 1 .. First - 1 =>
1284 (Test = Inside) /= Maps.Is_In (Element (Source, J), Set))
1285
1286 -- All characters between First and Last satisfy the property
1287 -- Test on Set.
1288
1289 and then
1290 (for all J in First .. Last =>
1291 (Test = Inside) = Maps.Is_In (Element (Source, J), Set))
1292
1293 -- If Last is not Source'Last, then the character at position
1294 -- Last + 1 does not satify the property Test on Set.
1295
1296 and then
1297 (if Last < Length (Source)
1298 then
1299 (Test = Inside)
1300 /= Maps.Is_In (Element (Source, Last + 1), Set))),
1301 Global => null;
1302
1303 ------------------------------------
1304 -- String Translation Subprograms --
1305 ------------------------------------
1306
1307 -- Each of the Translate subprograms, when applied to a Bounded_String,
1308 -- has an analogous effect to the corresponding subprogram in
1309 -- Strings.Fixed. For the Translate function, the translation is applied
1310 -- to the string represented by the Bounded_String parameter, and the
1311 -- result is converted (via To_Bounded_String) to a Bounded_String. For
1312 -- the Translate procedure, the string represented by the Bounded_String
1313 -- parameter after the translation is given by the Translate function
1314 -- for fixed-length strings applied to the string represented by the
1315 -- original value of the parameter.
1316
1317 function Translate
1318 (Source : Bounded_String;
1319 Mapping : Maps.Character_Mapping) return Bounded_String
1320 with
1321 Post => Length (Translate'Result) = Length (Source)
1322 and then
1323 (for all K in 1 .. Length (Source) =>
1324 Element (Translate'Result, K) =
1325 Ada.Strings.Maps.Value (Mapping, Element (Source, K))),
1326 Global => null;
1327
1328 procedure Translate
1329 (Source : in out Bounded_String;
1330 Mapping : Maps.Character_Mapping)
1331 with
1332 Post => Length (Source) = Length (Source'Old)
1333 and then
1334 (for all K in 1 .. Length (Source) =>
1335 Element (Source, K) =
1336 Ada.Strings.Maps.Value (Mapping, Element (Source'Old, K))),
1337 Global => null;
1338
1339 function Translate
1340 (Source : Bounded_String;
1341 Mapping : Maps.Character_Mapping_Function) return Bounded_String
1342 with
1343 Pre => Mapping /= null,
1344 Post => Length (Translate'Result) = Length (Source)
1345 and then
1346 (for all K in 1 .. Length (Source) =>
1347 Element (Translate'Result, K) = Mapping (Element (Source, K))),
1348 Global => null;
1349 pragma Annotate (GNATprove, False_Positive,
1350 "call via access-to-subprogram",
1351 "function Mapping must always terminate");
1352
1353 procedure Translate
1354 (Source : in out Bounded_String;
1355 Mapping : Maps.Character_Mapping_Function)
1356 with
1357 Pre => Mapping /= null,
1358 Post => Length (Source) = Length (Source'Old)
1359 and then
1360 (for all K in 1 .. Length (Source) =>
1361 Element (Source, K) = Mapping (Element (Source'Old, K))),
1362 Global => null;
1363 pragma Annotate (GNATprove, False_Positive,
1364 "call via access-to-subprogram",
1365 "function Mapping must always terminate");
1366
1367 ---------------------------------------
1368 -- String Transformation Subprograms --
1369 ---------------------------------------
1370
1371 -- Each of the transformation subprograms (Replace_Slice, Insert,
1372 -- Overwrite, Delete), selector subprograms (Trim, Head, Tail), and
1373 -- constructor functions ("*") has an effect based on its corresponding
1374 -- subprogram in Strings.Fixed, and Replicate is based on Fixed."*".
1375 -- In the case of a function, the corresponding fixed-length string
1376 -- subprogram is applied to the string represented by the Bounded_String
1377 -- parameter. To_Bounded_String is applied the result string, with Drop
1378 -- (or Error in the case of Generic_Bounded_Length."*") determining
1379 -- the effect when the string length exceeds Max_Length. In
1380 -- the case of a procedure, the corresponding function in
1381 -- Strings.Bounded.Generic_Bounded_Length is applied, with the
1382 -- result assigned into the Source parameter.
1383
1384 function Replace_Slice
1385 (Source : Bounded_String;
1386 Low : Positive;
1387 High : Natural;
1388 By : String;
1389 Drop : Truncation := Error) return Bounded_String
1390 with
1391 Pre =>
1392 Low - 1 <= Length (Source)
1393 and then
1394 (if Drop = Error
1395 then (if High >= Low
1396 then Low - 1
1397 <= Max_Length - By'Length
1398 - Integer'Max (Length (Source) - High, 0)
1399 else Length (Source) <= Max_Length - By'Length)),
1400 Contract_Cases =>
1401 (Low - 1 <= Max_Length - By'Length
1402 - Integer'Max (Length (Source) - Integer'Max (High, Low - 1), 0)
1403 =>
1404 -- Total length is lower than Max_Length: nothing is dropped
1405
1406 -- Note that if High < Low, the insertion is done before Low,
1407 -- so in all cases the starting position of the slice of Source
1408 -- remaining after the replaced Slice is Integer'Max (High + 1,
1409 -- Low).
1410
1411 Length (Replace_Slice'Result) = Low - 1 + By'Length
1412 + Integer'Max (Length (Source) - Integer'Max (High, Low - 1), 0)
1413 and then
1414 Slice (Replace_Slice'Result, 1, Low - 1) =
1415 Slice (Source, 1, Low - 1)
1416 and then
1417 Slice (Replace_Slice'Result, Low, Low - 1 + By'Length) = By
1418 and then
1419 (if Integer'Max (High, Low - 1) < Length (Source) then
1420 Slice (Replace_Slice'Result,
1421 Low + By'Length, Length (Replace_Slice'Result)) =
1422 Slice (Source,
1423 Integer'Max (High + 1, Low), Length (Source))),
1424
1425 Low - 1 > Max_Length - By'Length
1426 - Integer'Max (Length (Source) - Integer'Max (High, Low - 1), 0)
1427 and then Drop = Left
1428 =>
1429 -- Final_Slice is the length of the slice of Source remaining
1430 -- after the replaced part.
1431 (declare
1432 Final_Slice : constant Natural :=
1433 Integer'Max
1434 (Length (Source) - Integer'Max (High, Low - 1), 0);
1435 begin
1436 -- The result is of maximal length and ends by the last
1437 -- Final_Slice characters of Source.
1438
1439 Length (Replace_Slice'Result) = Max_Length
1440 and then
1441 (if Final_Slice > 0 then
1442 Slice (Replace_Slice'Result,
1443 Max_Length - Final_Slice + 1, Max_Length) =
1444 Slice (Source,
1445 Integer'Max (High + 1, Low), Length (Source)))
1446
1447 -- Depending on when we reach Max_Length, either the first
1448 -- part of Source is fully dropped and By is partly dropped,
1449 -- or By is fully added and the first part of Source is
1450 -- partly dropped.
1451
1452 and then
1453 (if Max_Length - Final_Slice - By'Length <= 0 then
1454
1455 -- The first (possibly zero) characters of By are
1456 -- dropped.
1457
1458 (if Final_Slice < Max_Length then
1459 Slice (Replace_Slice'Result,
1460 1, Max_Length - Final_Slice) =
1461 By (By'Last - Max_Length + Final_Slice + 1
1462 .. By'Last))
1463
1464 else -- By is added to the result
1465
1466 Slice (Replace_Slice'Result,
1467 Max_Length - Final_Slice - By'Length + 1,
1468 Max_Length - Final_Slice) =
1469 By
1470
1471 -- The first characters of Source (1 .. Low - 1) are
1472 -- dropped.
1473
1474 and then Slice (Replace_Slice'Result, 1,
1475 Max_Length - Final_Slice - By'Length) =
1476 Slice (Source,
1477 Low - Max_Length + Final_Slice + By'Length,
1478 Low - 1))),
1479
1480 others -- Drop = Right
1481 =>
1482 -- The result is of maximal length and starts by the first Low -
1483 -- 1 characters of Source.
1484
1485 Length (Replace_Slice'Result) = Max_Length
1486 and then
1487 Slice (Replace_Slice'Result, 1, Low - 1) =
1488 Slice (Source, 1, Low - 1)
1489
1490 -- Depending on when we reach Max_Length, either the last part
1491 -- of Source is fully dropped and By is partly dropped, or By
1492 -- is fully added and the last part of Source is partly
1493 -- dropped.
1494
1495 and then
1496 (if Low - 1 >= Max_Length - By'Length then
1497
1498 -- The last characters of By are dropped
1499
1500 Slice (Replace_Slice'Result, Low, Max_Length) =
1501 By (By'First .. Max_Length - Low + By'First)
1502
1503 else -- By is fully added
1504
1505 Slice (Replace_Slice'Result, Low, Low + By'Length - 1) = By
1506
1507 -- Then Source starting from Integer'Max (High + 1, Low)
1508 -- is added but the last characters are dropped.
1509
1510 and then Slice (Replace_Slice'Result,
1511 Low + By'Length, Max_Length) =
1512 Slice (Source, Integer'Max (High + 1, Low),
1513 Integer'Max (High + 1, Low) +
1514 (Max_Length - Low - By'Length))));
1515
1516 procedure Replace_Slice
1517 (Source : in out Bounded_String;
1518 Low : Positive;
1519 High : Natural;
1520 By : String;
1521 Drop : Truncation := Error)
1522 with
1523 Pre =>
1524 Low - 1 <= Length (Source)
1525 and then
1526 (if Drop = Error
1527 then (if High >= Low
1528 then Low - 1
1529 <= Max_Length - By'Length
1530 - Natural'Max (Length (Source) - High, 0)
1531 else Length (Source) <= Max_Length - By'Length)),
1532 Contract_Cases =>
1533 (Low - 1 <= Max_Length - By'Length
1534 - Integer'Max (Length (Source) - Integer'Max (High, Low - 1), 0)
1535 =>
1536 -- Total length is lower than Max_Length: nothing is dropped
1537
1538 -- Note that if High < Low, the insertion is done before Low,
1539 -- so in all cases the starting position of the slice of Source
1540 -- remaining after the replaced Slice is Integer'Max (High + 1,
1541 -- Low).
1542
1543 Length (Source) = Low - 1 + By'Length + Integer'Max
1544 (Length (Source'Old) - Integer'Max (High, Low - 1), 0)
1545 and then
1546 Slice (Source, 1, Low - 1) = Slice (Source'Old, 1, Low - 1)
1547 and then Slice (Source, Low, Low - 1 + By'Length) = By
1548 and then
1549 (if Integer'Max (High, Low - 1) < Length (Source'Old) then
1550 Slice (Source, Low + By'Length, Length (Source)) =
1551 Slice (Source'Old,
1552 Integer'Max (High + 1, Low), Length (Source'Old))),
1553
1554 Low - 1 > Max_Length - By'Length
1555 - Integer'Max (Length (Source) - Integer'Max (High, Low - 1), 0)
1556 and then Drop = Left
1557 =>
1558 -- Final_Slice is the length of the slice of Source remaining
1559 -- after the replaced part.
1560 (declare
1561 Final_Slice : constant Integer :=
1562 Integer'Max (0,
1563 Length (Source'Old) - Integer'Max (High, Low - 1));
1564 begin
1565 -- The result is of maximal length and ends by the last
1566 -- Final_Slice characters of Source.
1567
1568 Length (Source) = Max_Length
1569 and then
1570 (if Final_Slice > 0 then
1571 Slice (Source,
1572 Max_Length - Final_Slice + 1, Max_Length) =
1573 Slice (Source'Old,
1574 Integer'Max (High + 1, Low), Length (Source'Old)))
1575
1576 -- Depending on when we reach Max_Length, either the first
1577 -- part of Source is fully dropped and By is partly dropped,
1578 -- or By is fully added and the first part of Source is
1579 -- partly dropped.
1580
1581 and then
1582 (if Max_Length - Final_Slice - By'Length <= 0 then
1583
1584 -- The first characters of By are dropped
1585
1586 (if Final_Slice < Max_Length then
1587 Slice (Source, 1, Max_Length - Final_Slice) =
1588 By (By'Last - Max_Length + Final_Slice + 1
1589 .. By'Last))
1590
1591 else -- By is added to the result
1592
1593 Slice (Source,
1594 Max_Length - Final_Slice - By'Length + 1,
1595 Max_Length - Final_Slice) = By
1596
1597 -- The first characters of Source (1 .. Low - 1) are
1598 -- dropped.
1599
1600 and then Slice (Source, 1,
1601 Max_Length - Final_Slice - By'Length) =
1602 Slice (Source'Old,
1603 Low - Max_Length + Final_Slice + By'Length,
1604 Low - 1))),
1605
1606 others -- Drop = Right
1607 =>
1608 -- The result is of maximal length and starts by the first Low -
1609 -- 1 characters of Source.
1610
1611 Length (Source) = Max_Length
1612 and then
1613 Slice (Source, 1, Low - 1) = Slice (Source'Old, 1, Low - 1)
1614
1615 -- Depending on when we reach Max_Length, either the last part
1616 -- of Source is fully dropped and By is partly dropped, or By
1617 -- is fully added and the last part of Source is partly
1618 -- dropped.
1619
1620 and then
1621 (if Low - 1 >= Max_Length - By'Length then
1622
1623 -- The last characters of By are dropped
1624
1625 Slice (Source, Low, Max_Length) =
1626 By (By'First .. Max_Length - Low + By'First)
1627
1628 else -- By is fully added
1629
1630 Slice (Source, Low, Low + By'Length - 1) = By
1631
1632 -- Then Source starting from Natural'Max (High + 1, Low)
1633 -- is added but the last characters are dropped.
1634
1635 and then Slice (Source, Low + By'Length, Max_Length) =
1636 Slice (Source'Old, Integer'Max (High + 1, Low),
1637 Integer'Max (High + 1, Low) +
1638 (Max_Length - Low - By'Length))));
1639
1640 function Insert
1641 (Source : Bounded_String;
1642 Before : Positive;
1643 New_Item : String;
1644 Drop : Truncation := Error) return Bounded_String
1645 with
1646 Pre =>
1647 Before - 1 <= Length (Source)
1648 and then (if New_Item'Length > Max_Length - Length (Source)
1649 then Drop /= Error),
1650 Contract_Cases =>
1651 (Length (Source) <= Max_Length - New_Item'Length
1652 =>
1653 -- Total length is lower than Max_Length: nothing is dropped
1654
1655 Length (Insert'Result) = Length (Source) + New_Item'Length
1656 and then
1657 Slice (Insert'Result, 1, Before - 1) =
1658 Slice (Source, 1, Before - 1)
1659 and then
1660 Slice (Insert'Result, Before, Before - 1 + New_Item'Length) =
1661 New_Item
1662 and then
1663 (if Before <= Length (Source) then
1664 Slice (Insert'Result,
1665 Before + New_Item'Length, Length (Insert'Result)) =
1666 Slice (Source, Before, Length (Source))),
1667
1668 Length (Source) > Max_Length - New_Item'Length and then Drop = Left
1669 =>
1670 -- The result is of maximal length and ends by the last
1671 -- characters of Source.
1672
1673 Length (Insert'Result) = Max_Length
1674 and then
1675 (if Before <= Length (Source) then
1676 Slice (Insert'Result,
1677 Max_Length - Length (Source) + Before, Max_Length) =
1678 Slice (Source, Before, Length (Source)))
1679
1680 -- Depending on when we reach Max_Length, either the first part
1681 -- of Source is fully dropped and New_Item is partly dropped,
1682 -- or New_Item is fully added and the first part of Source is
1683 -- partly dropped.
1684
1685 and then
1686 (if Max_Length - Length (Source) - 1 + Before
1687 < New_Item'Length
1688 then
1689 -- The first characters of New_Item are dropped
1690
1691 (if Length (Source) - Before + 1 < Max_Length then
1692 Slice (Insert'Result,
1693 1, Max_Length - Length (Source) - 1 + Before) =
1694 New_Item
1695 (New_Item'Last - Max_Length + Length (Source)
1696 - Before + 2
1697 .. New_Item'Last))
1698
1699 else -- New_Item is added to the result
1700
1701 Slice (Insert'Result,
1702 Max_Length - Length (Source) - New_Item'Length + Before,
1703 Max_Length - Length (Source) - 1 + Before) = New_Item
1704
1705 -- The first characters of Source (1 .. Before - 1) are
1706 -- dropped.
1707
1708 and then Slice (Insert'Result,
1709 1, Max_Length - Length (Source) - New_Item'Length
1710 - 1 + Before) =
1711 Slice (Source,
1712 Length (Source) - Max_Length + New_Item'Length
1713 + 1,
1714 Before - 1)),
1715
1716 others -- Drop = Right
1717 =>
1718 -- The result is of maximal length and starts by the first
1719 -- characters of Source.
1720
1721 Length (Insert'Result) = Max_Length
1722 and then
1723 Slice (Insert'Result, 1, Before - 1) =
1724 Slice (Source, 1, Before - 1)
1725
1726 -- Depending on when we reach Max_Length, either the last part
1727 -- of Source is fully dropped and New_Item is partly dropped,
1728 -- or New_Item is fully added and the last part of Source is
1729 -- partly dropped.
1730
1731 and then
1732 (if Before - 1 >= Max_Length - New_Item'Length then
1733
1734 -- The last characters of New_Item are dropped
1735
1736 Slice (Insert'Result, Before, Max_Length) =
1737 New_Item (New_Item'First
1738 .. Max_Length - Before + New_Item'First)
1739
1740 else -- New_Item is fully added
1741
1742 Slice (Insert'Result,
1743 Before, Before + New_Item'Length - 1) =
1744 New_Item
1745
1746 -- Then Source starting from Before is added but the
1747 -- last characters are dropped.
1748
1749 and then Slice (Insert'Result,
1750 Before + New_Item'Length, Max_Length) =
1751 Slice (Source,
1752 Before, Max_Length - New_Item'Length)));
1753
1754 procedure Insert
1755 (Source : in out Bounded_String;
1756 Before : Positive;
1757 New_Item : String;
1758 Drop : Truncation := Error)
1759 with
1760 Pre =>
1761 Before - 1 <= Length (Source)
1762 and then (if New_Item'Length > Max_Length - Length (Source)
1763 then Drop /= Error),
1764 Contract_Cases =>
1765 (Length (Source) <= Max_Length - New_Item'Length
1766 =>
1767 -- Total length is lower than Max_Length: nothing is dropped
1768
1769 Length (Source) = Length (Source'Old) + New_Item'Length
1770 and then
1771 Slice (Source, 1, Before - 1) =
1772 Slice (Source'Old, 1, Before - 1)
1773 and then
1774 Slice (Source, Before, Before - 1 + New_Item'Length) =
1775 New_Item
1776 and then
1777 (if Before <= Length (Source'Old) then
1778 Slice (Source, Before + New_Item'Length, Length (Source)) =
1779 Slice (Source'Old, Before, Length (Source'Old))),
1780
1781 Length (Source) > Max_Length - New_Item'Length and then Drop = Left
1782 =>
1783 -- The result is of maximal length and ends by the last
1784 -- characters of Source.
1785
1786 Length (Source) = Max_Length
1787 and then
1788 (if Before <= Length (Source'Old) then
1789 Slice (Source,
1790 Max_Length - Length (Source'Old) + Before, Max_Length) =
1791 Slice (Source'Old, Before, Length (Source'Old)))
1792
1793 -- Depending on when we reach Max_Length, either the first part
1794 -- of Source is fully dropped and New_Item is partly dropped,
1795 -- or New_Item is fully added and the first part of Source is
1796 -- partly dropped.
1797
1798 and then
1799 (if Max_Length - Length (Source'Old) - 1 + Before
1800 < New_Item'Length
1801 then
1802 -- The first characters of New_Item are dropped
1803
1804 (if Length (Source'Old) - Before + 1 < Max_Length then
1805 Slice (Source,
1806 1, Max_Length - Length (Source'Old) - 1 + Before) =
1807 New_Item
1808 (New_Item'Last - Max_Length + Length (Source'Old)
1809 - Before + 2
1810 .. New_Item'Last))
1811
1812 else -- New_Item is added to the result
1813
1814 Slice (Source,
1815 Max_Length - Length (Source'Old) - New_Item'Length
1816 + Before,
1817 Max_Length - Length (Source'Old) - 1 + Before) = New_Item
1818
1819 -- The first characters of Source (1 .. Before - 1) are
1820 -- dropped.
1821
1822 and then Slice (Source, 1,
1823 Max_Length - Length (Source'Old) - New_Item'Length
1824 - 1 + Before) =
1825 Slice (Source'Old,
1826 Length (Source'Old)
1827 - Max_Length + New_Item'Length + 1,
1828 Before - 1)),
1829
1830 others -- Drop = Right
1831 =>
1832 -- The result is of maximal length and starts by the first
1833 -- characters of Source.
1834
1835 Length (Source) = Max_Length
1836 and then
1837 Slice (Source, 1, Before - 1) =
1838 Slice (Source'Old, 1, Before - 1)
1839
1840 -- Depending on when we reach Max_Length, either the last part
1841 -- of Source is fully dropped and New_Item is partly dropped,
1842 -- or New_Item is fully added and the last part of Source is
1843 -- partly dropped.
1844
1845 and then
1846 (if Before - 1 >= Max_Length - New_Item'Length then
1847
1848 -- The last characters of New_Item are dropped
1849
1850 Slice (Source, Before, Max_Length) =
1851 New_Item (New_Item'First
1852 .. Max_Length - Before + New_Item'First)
1853
1854 else -- New_Item is fully added
1855
1856 Slice (Source, Before, Before + New_Item'Length - 1) =
1857 New_Item
1858
1859 -- Then Source starting from Before is added but the
1860 -- last characters are dropped.
1861
1862 and then
1863 Slice (Source, Before + New_Item'Length, Max_Length) =
1864 Slice (Source'Old,
1865 Before, Max_Length - New_Item'Length)));
1866
1867 function Overwrite
1868 (Source : Bounded_String;
1869 Position : Positive;
1870 New_Item : String;
1871 Drop : Truncation := Error) return Bounded_String
1872 with
1873 Pre =>
1874 Position - 1 <= Length (Source)
1875 and then (if New_Item'Length > Max_Length - (Position - 1)
1876 then Drop /= Error),
1877 Contract_Cases =>
1878 (Position - 1 <= Max_Length - New_Item'Length
1879 =>
1880 -- The length is unchanged, unless New_Item overwrites further
1881 -- than the end of Source. In this contract case, we suppose
1882 -- New_Item doesn't overwrite further than Max_Length.
1883
1884 Length (Overwrite'Result) =
1885 Integer'Max (Length (Source), Position - 1 + New_Item'Length)
1886 and then
1887 Slice (Overwrite'Result, 1, Position - 1) =
1888 Slice (Source, 1, Position - 1)
1889 and then Slice (Overwrite'Result,
1890 Position, Position - 1 + New_Item'Length) =
1891 New_Item
1892 and then
1893 (if Position - 1 + New_Item'Length < Length (Source) then
1894
1895 -- There are some unchanged characters of Source remaining
1896 -- after New_Item.
1897
1898 Slice (Overwrite'Result,
1899 Position + New_Item'Length, Length (Source)) =
1900 Slice (Source,
1901 Position + New_Item'Length, Length (Source))),
1902
1903 Position - 1 > Max_Length - New_Item'Length and then Drop = Left
1904 =>
1905 Length (Overwrite'Result) = Max_Length
1906
1907 -- If a part of the result has to be dropped, it means New_Item
1908 -- is overwriting further than the end of Source. Thus the
1909 -- result is necessarily ending by New_Item. However, we don't
1910 -- know whether New_Item covers all Max_Length characters or
1911 -- some characters of Source are remaining at the left.
1912
1913 and then
1914 (if New_Item'Length >= Max_Length then
1915
1916 -- New_Item covers all Max_Length characters
1917
1918 To_String (Overwrite'Result) =
1919 New_Item
1920 (New_Item'Last - Max_Length + 1 .. New_Item'Last)
1921 else
1922 -- New_Item fully appears at the end
1923
1924 Slice (Overwrite'Result,
1925 Max_Length - New_Item'Length + 1, Max_Length) =
1926 New_Item
1927
1928 -- The left of Source is cut
1929
1930 and then
1931 Slice (Overwrite'Result,
1932 1, Max_Length - New_Item'Length) =
1933 Slice (Source,
1934 Position - Max_Length + New_Item'Length,
1935 Position - 1)),
1936
1937 others -- Drop = Right
1938 =>
1939 -- The result is of maximal length and starts by the first
1940 -- characters of Source.
1941
1942 Length (Overwrite'Result) = Max_Length
1943 and then
1944 Slice (Overwrite'Result, 1, Position - 1) =
1945 Slice (Source, 1, Position - 1)
1946
1947 -- Then New_Item is written until Max_Length
1948
1949 and then Slice (Overwrite'Result, Position, Max_Length) =
1950 New_Item
1951 (New_Item'First .. Max_Length - Position + New_Item'First));
1952
1953 procedure Overwrite
1954 (Source : in out Bounded_String;
1955 Position : Positive;
1956 New_Item : String;
1957 Drop : Truncation := Error)
1958 with
1959 Pre =>
1960 Position - 1 <= Length (Source)
1961 and then (if New_Item'Length > Max_Length - (Position - 1)
1962 then Drop /= Error),
1963 Contract_Cases =>
1964 (Position - 1 <= Max_Length - New_Item'Length
1965 =>
1966 -- The length of Source is unchanged, unless New_Item overwrites
1967 -- further than the end of Source. In this contract case, we
1968 -- suppose New_Item doesn't overwrite further than Max_Length.
1969
1970 Length (Source) = Integer'Max
1971 (Length (Source'Old), Position - 1 + New_Item'Length)
1972 and then
1973 Slice (Source, 1, Position - 1) =
1974 Slice (Source'Old, 1, Position - 1)
1975 and then Slice (Source,
1976 Position, Position - 1 + New_Item'Length) =
1977 New_Item
1978 and then
1979 (if Position - 1 + New_Item'Length < Length (Source'Old) then
1980
1981 -- There are some unchanged characters of Source remaining
1982 -- after New_Item.
1983
1984 Slice (Source,
1985 Position + New_Item'Length, Length (Source'Old)) =
1986 Slice (Source'Old,
1987 Position + New_Item'Length, Length (Source'Old))),
1988
1989 Position - 1 > Max_Length - New_Item'Length and then Drop = Left
1990 =>
1991 Length (Source) = Max_Length
1992
1993 -- If a part of the result has to be dropped, it means New_Item
1994 -- is overwriting further than the end of Source. Thus the
1995 -- result is necessarily ending by New_Item. However, we don't
1996 -- know whether New_Item covers all Max_Length characters or
1997 -- some characters of Source are remaining at the left.
1998
1999 and then
2000 (if New_Item'Length >= Max_Length then
2001
2002 -- New_Item covers all Max_Length characters
2003
2004 To_String (Source) =
2005 New_Item
2006 (New_Item'Last - Max_Length + 1 .. New_Item'Last)
2007 else
2008 -- New_Item fully appears at the end
2009
2010 Slice (Source,
2011 Max_Length - New_Item'Length + 1, Max_Length) =
2012 New_Item
2013
2014 -- The left of Source is cut
2015
2016 and then
2017 Slice (Source, 1, Max_Length - New_Item'Length) =
2018 Slice (Source'Old,
2019 Position - Max_Length + New_Item'Length,
2020 Position - 1)),
2021
2022 others -- Drop = Right
2023 =>
2024 -- The result is of maximal length and starts by the first
2025 -- characters of Source.
2026
2027 Length (Source) = Max_Length
2028 and then
2029 Slice (Source, 1, Position - 1) =
2030 Slice (Source'Old, 1, Position - 1)
2031
2032 -- New_Item is written until Max_Length
2033
2034 and then Slice (Source, Position, Max_Length) =
2035 New_Item
2036 (New_Item'First .. Max_Length - Position + New_Item'First));
2037
2038 function Delete
2039 (Source : Bounded_String;
2040 From : Positive;
2041 Through : Natural) return Bounded_String
2042 with
2043 Pre =>
2044 (if Through >= From then From - 1 <= Length (Source)),
2045 Contract_Cases =>
2046 (Through >= From =>
2047 Length (Delete'Result) =
2048 From - 1 + Natural'Max (Length (Source) - Through, 0)
2049 and then
2050 Slice (Delete'Result, 1, From - 1) =
2051 Slice (Source, 1, From - 1)
2052 and then
2053 (if Through < Length (Source) then
2054 Slice (Delete'Result, From, Length (Delete'Result)) =
2055 Slice (Source, Through + 1, Length (Source))),
2056 others =>
2057 Delete'Result = Source),
2058 Global => null;
2059
2060 procedure Delete
2061 (Source : in out Bounded_String;
2062 From : Positive;
2063 Through : Natural)
2064 with
2065 Pre =>
2066 (if Through >= From then From - 1 <= Length (Source)),
2067 Contract_Cases =>
2068 (Through >= From =>
2069 Length (Source) =
2070 From - 1 + Natural'Max (Length (Source'Old) - Through, 0)
2071 and then
2072 Slice (Source, 1, From - 1) = Slice (Source'Old, 1, From - 1)
2073 and then
2074 (if Through < Length (Source) then
2075 Slice (Source, From, Length (Source)) =
2076 Slice (Source'Old, Through + 1, Length (Source'Old))),
2077 others =>
2078 Source = Source'Old),
2079 Global => null;
2080
2081 ---------------------------------
2082 -- String Selector Subprograms --
2083 ---------------------------------
2084
2085 function Trim
2086 (Source : Bounded_String;
2087 Side : Trim_End) return Bounded_String
2088 with
2089 Contract_Cases =>
2090 -- If all characters in Source are Space, the returned string is
2091 -- empty.
2092
2093 ((for all C of To_String (Source) => C = ' ')
2094 =>
2095 Length (Trim'Result) = 0,
2096
2097 -- Otherwise, the returned string is a slice of Source
2098
2099 others
2100 =>
2101 (declare
2102 Low : constant Positive :=
2103 (if Side = Right then 1
2104 else Index_Non_Blank (Source, Forward));
2105 High : constant Positive :=
2106 (if Side = Left then Length (Source)
2107 else Index_Non_Blank (Source, Backward));
2108 begin
2109 To_String (Trim'Result) = Slice (Source, Low, High))),
2110 Global => null;
2111
2112 procedure Trim
2113 (Source : in out Bounded_String;
2114 Side : Trim_End)
2115 with
2116 Contract_Cases =>
2117 -- If all characters in Source are Space, the returned string is
2118 -- empty.
2119
2120 ((for all C of To_String (Source) => C = ' ')
2121 =>
2122 Length (Source) = 0,
2123
2124 -- Otherwise, the returned string is a slice of Source
2125
2126 others
2127 =>
2128 (declare
2129 Low : constant Positive :=
2130 (if Side = Right then 1
2131 else Index_Non_Blank (Source'Old, Forward));
2132 High : constant Positive :=
2133 (if Side = Left then Length (Source'Old)
2134 else Index_Non_Blank (Source'Old, Backward));
2135 begin
2136 To_String (Source) = Slice (Source'Old, Low, High))),
2137 Global => null;
2138
2139 function Trim
2140 (Source : Bounded_String;
2141 Left : Maps.Character_Set;
2142 Right : Maps.Character_Set) return Bounded_String
2143 with
2144 Contract_Cases =>
2145 -- If all characters in Source are contained in one of the sets Left
2146 -- or Right, then the returned string is empty.
2147
2148 ((for all C of To_String (Source) => Maps.Is_In (C, Left))
2149 or else
2150 (for all C of To_String (Source) => Maps.Is_In (C, Right))
2151 =>
2152 Length (Trim'Result) = 0,
2153
2154 -- Otherwise, the returned string is a slice of Source
2155
2156 others
2157 =>
2158 (declare
2159 Low : constant Positive :=
2160 Index (Source, Left, Outside, Forward);
2161 High : constant Positive :=
2162 Index (Source, Right, Outside, Backward);
2163 begin
2164 To_String (Trim'Result) = Slice (Source, Low, High))),
2165 Global => null;
2166
2167 procedure Trim
2168 (Source : in out Bounded_String;
2169 Left : Maps.Character_Set;
2170 Right : Maps.Character_Set)
2171 with
2172 Contract_Cases =>
2173 -- If all characters in Source are contained in one of the sets Left
2174 -- or Right, then the returned string is empty.
2175
2176 ((for all C of To_String (Source) => Maps.Is_In (C, Left))
2177 or else
2178 (for all C of To_String (Source) => Maps.Is_In (C, Right))
2179 =>
2180 Length (Source) = 0,
2181
2182 -- Otherwise, the returned string is a slice of Source
2183
2184 others
2185 =>
2186 (declare
2187 Low : constant Positive :=
2188 Index (Source'Old, Left, Outside, Forward);
2189 High : constant Positive :=
2190 Index (Source'Old, Right, Outside, Backward);
2191 begin
2192 To_String (Source) = Slice (Source'Old, Low, High))),
2193 Global => null;
2194
2195 function Head
2196 (Source : Bounded_String;
2197 Count : Natural;
2198 Pad : Character := Space;
2199 Drop : Truncation := Error) return Bounded_String
2200 with
2201 Pre => (if Count > Max_Length then Drop /= Error),
2202 Contract_Cases =>
2203 (Count <= Length (Source)
2204 =>
2205 -- Source is cut
2206
2207 To_String (Head'Result) = Slice (Source, 1, Count),
2208
2209 Count > Length (Source) and then Count <= Max_Length
2210 =>
2211 -- Source is followed by Pad characters
2212
2213 Length (Head'Result) = Count
2214 and then
2215 Slice (Head'Result, 1, Length (Source)) = To_String (Source)
2216 and then
2217 Slice (Head'Result, Length (Source) + 1, Count) =
2218 [1 .. Count - Length (Source) => Pad],
2219
2220 Count > Max_Length and then Drop = Right
2221 =>
2222 -- Source is followed by Pad characters
2223
2224 Length (Head'Result) = Max_Length
2225 and then
2226 Slice (Head'Result, 1, Length (Source)) = To_String (Source)
2227 and then
2228 Slice (Head'Result, Length (Source) + 1, Max_Length) =
2229 [1 .. Max_Length - Length (Source) => Pad],
2230
2231 Count - Length (Source) > Max_Length and then Drop = Left
2232 =>
2233 -- Source is fully dropped at the left
2234
2235 To_String (Head'Result) = [1 .. Max_Length => Pad],
2236
2237 others
2238 =>
2239 -- Source is partly dropped at the left
2240
2241 Length (Head'Result) = Max_Length
2242 and then
2243 Slice (Head'Result, 1, Max_Length - Count + Length (Source)) =
2244 Slice (Source, Count - Max_Length + 1, Length (Source))
2245 and then
2246 Slice (Head'Result,
2247 Max_Length - Count + Length (Source) + 1, Max_Length) =
2248 [1 .. Count - Length (Source) => Pad]);
2249
2250 procedure Head
2251 (Source : in out Bounded_String;
2252 Count : Natural;
2253 Pad : Character := Space;
2254 Drop : Truncation := Error)
2255 with
2256 Pre => (if Count > Max_Length then Drop /= Error),
2257 Contract_Cases =>
2258 (Count <= Length (Source)
2259 =>
2260 -- Source is cut
2261
2262 To_String (Source) = Slice (Source'Old, 1, Count),
2263
2264 Count > Length (Source) and then Count <= Max_Length
2265 =>
2266 -- Source is followed by Pad characters
2267
2268 Length (Source) = Count
2269 and then
2270 Slice (Source, 1, Length (Source'Old)) =
2271 To_String (Source'Old)
2272 and then
2273 Slice (Source, Length (Source'Old) + 1, Count) =
2274 [1 .. Count - Length (Source'Old) => Pad],
2275
2276 Count > Max_Length and then Drop = Right
2277 =>
2278 -- Source is followed by Pad characters
2279
2280 Length (Source) = Max_Length
2281 and then
2282 Slice (Source, 1, Length (Source'Old)) =
2283 To_String (Source'Old)
2284 and then
2285 Slice (Source, Length (Source'Old) + 1, Max_Length) =
2286 [1 .. Max_Length - Length (Source'Old) => Pad],
2287
2288 Count - Length (Source) > Max_Length and then Drop = Left
2289 =>
2290 -- Source is fully dropped on the left
2291
2292 To_String (Source) = [1 .. Max_Length => Pad],
2293
2294 others
2295 =>
2296 -- Source is partly dropped on the left
2297
2298 Length (Source) = Max_Length
2299 and then
2300 Slice (Source, 1, Max_Length - Count + Length (Source'Old)) =
2301 Slice (Source'Old,
2302 Count - Max_Length + 1, Length (Source'Old))
2303 and then
2304 Slice (Source,
2305 Max_Length - Count + Length (Source'Old) + 1, Max_Length) =
2306 [1 .. Count - Length (Source'Old) => Pad]);
2307
2308 function Tail
2309 (Source : Bounded_String;
2310 Count : Natural;
2311 Pad : Character := Space;
2312 Drop : Truncation := Error) return Bounded_String
2313 with
2314 Pre => (if Count > Max_Length then Drop /= Error),
2315 Contract_Cases =>
2316 (Count < Length (Source)
2317 =>
2318 -- Source is cut
2319
2320 (if Count > 0 then
2321 To_String (Tail'Result) =
2322 Slice (Source, Length (Source) - Count + 1, Length (Source))
2323 else Length (Tail'Result) = 0),
2324
2325 Count >= Length (Source) and then Count < Max_Length
2326 =>
2327 -- Source is preceded by Pad characters
2328
2329 Length (Tail'Result) = Count
2330 and then
2331 Slice (Tail'Result, 1, Count - Length (Source)) =
2332 [1 .. Count - Length (Source) => Pad]
2333 and then
2334 Slice (Tail'Result, Count - Length (Source) + 1, Count) =
2335 To_String (Source),
2336
2337 Count >= Max_Length and then Drop = Left
2338 =>
2339 -- Source is preceded by Pad characters
2340
2341 Length (Tail'Result) = Max_Length
2342 and then
2343 Slice (Tail'Result, 1, Max_Length - Length (Source)) =
2344 [1 .. Max_Length - Length (Source) => Pad]
2345 and then
2346 (if Length (Source) > 0 then
2347 Slice (Tail'Result,
2348 Max_Length - Length (Source) + 1, Max_Length) =
2349 To_String (Source)),
2350
2351 Count - Length (Source) >= Max_Length and then Drop /= Left
2352 =>
2353 -- Source is fully dropped on the right
2354
2355 To_String (Tail'Result) = [1 .. Max_Length => Pad],
2356
2357 others
2358 =>
2359 -- Source is partly dropped on the right
2360
2361 Length (Tail'Result) = Max_Length
2362 and then
2363 Slice (Tail'Result, 1, Count - Length (Source)) =
2364 [1 .. Count - Length (Source) => Pad]
2365 and then
2366 Slice (Tail'Result, Count - Length (Source) + 1, Max_Length) =
2367 Slice (Source, 1, Max_Length - Count + Length (Source)));
2368
2369 procedure Tail
2370 (Source : in out Bounded_String;
2371 Count : Natural;
2372 Pad : Character := Space;
2373 Drop : Truncation := Error)
2374 with
2375 Pre => (if Count > Max_Length then Drop /= Error),
2376 Contract_Cases =>
2377 (Count < Length (Source)
2378 =>
2379 -- Source is cut
2380
2381 (if Count > 0 then
2382 To_String (Source) =
2383 Slice (Source'Old,
2384 Length (Source'Old) - Count + 1, Length (Source'Old))
2385 else Length (Source) = 0),
2386
2387 Count >= Length (Source) and then Count < Max_Length
2388 =>
2389 -- Source is preceded by Pad characters
2390
2391 Length (Source) = Count
2392 and then
2393 Slice (Source, 1, Count - Length (Source'Old)) =
2394 [1 .. Count - Length (Source'Old) => Pad]
2395 and then
2396 Slice (Source, Count - Length (Source'Old) + 1, Count) =
2397 To_String (Source'Old),
2398
2399 Count >= Max_Length and then Drop = Left
2400 =>
2401 -- Source is preceded by Pad characters
2402
2403 Length (Source) = Max_Length
2404 and then
2405 Slice (Source, 1, Max_Length - Length (Source'Old)) =
2406 [1 .. Max_Length - Length (Source'Old) => Pad]
2407 and then
2408 (if Length (Source'Old) > 0 then
2409 Slice (Source,
2410 Max_Length - Length (Source'Old) + 1, Max_Length) =
2411 To_String (Source'Old)),
2412
2413 Count - Length (Source) >= Max_Length and then Drop /= Left
2414 =>
2415 -- Source is fully dropped at the right
2416
2417 To_String (Source) = [1 .. Max_Length => Pad],
2418
2419 others
2420 =>
2421 -- Source is partly dropped at the right
2422
2423 Length (Source) = Max_Length
2424 and then
2425 Slice (Source, 1, Count - Length (Source'Old)) =
2426 [1 .. Count - Length (Source'Old) => Pad]
2427 and then
2428 Slice (Source, Count - Length (Source'Old) + 1, Max_Length) =
2429 Slice (Source'Old,
2430 1, Max_Length - Count + Length (Source'Old)));
2431
2432 ------------------------------------
2433 -- String Constructor Subprograms --
2434 ------------------------------------
2435
2436 function "*"
2437 (Left : Natural;
2438 Right : Character) return Bounded_String
2439 with
2440 Pre => Left <= Max_Length,
2441 Post => To_String ("*"'Result) = [1 .. Left => Right];
2442
2443 function "*"
2444 (Left : Natural;
2445 Right : String) return Bounded_String
2446 with
2447 Pre => (if Left /= 0 then Right'Length <= Max_Length / Left),
2448 Post =>
2449 Length ("*"'Result) = Left * Right'Length
2450 and then
2451 (if Right'Length > 0 then
2452 (for all K in 1 .. Left * Right'Length =>
2453 Element ("*"'Result, K) =
2454 Right (Right'First + (K - 1) mod Right'Length)));
2455
2456 function "*"
2457 (Left : Natural;
2458 Right : Bounded_String) return Bounded_String
2459 with
2460 Pre => (if Left /= 0 then Length (Right) <= Max_Length / Left),
2461 Post =>
2462 Length ("*"'Result) = Left * Length (Right)
2463 and then
2464 (if Length (Right) > 0 then
2465 (for all K in 1 .. Left * Length (Right) =>
2466 Element ("*"'Result, K) =
2467 Element (Right, 1 + (K - 1) mod Length (Right))));
2468
2469 function Replicate
2470 (Count : Natural;
2471 Item : Character;
2472 Drop : Truncation := Error) return Bounded_String
2473 with
2474 Pre => (if Count > Max_Length then Drop /= Error),
2475 Post =>
2476 To_String (Replicate'Result) =
2477 [1 .. Natural'Min (Max_Length, Count) => Item];
2478
2479 function Replicate
2480 (Count : Natural;
2481 Item : String;
2482 Drop : Truncation := Error) return Bounded_String
2483 with
2484 Pre =>
2485 (if Count /= 0 and then Item'Length > Max_Length / Count
2486 then Drop /= Error),
2487 Contract_Cases =>
2488 (Count = 0 or else Item'Length <= Max_Length / Count
2489 =>
2490 Length (Replicate'Result) = Count * Item'Length
2491 and then
2492 (if Item'Length > 0 then
2493 (for all K in 1 .. Count * Item'Length =>
2494 Element (Replicate'Result, K) =
2495 Item (Item'First + (K - 1) mod Item'Length))),
2496 Count /= 0
2497 and then Item'Length > Max_Length / Count
2498 and then Drop = Right
2499 =>
2500 Length (Replicate'Result) = Max_Length
2501 and then
2502 (for all K in 1 .. Max_Length =>
2503 Element (Replicate'Result, K) =
2504 Item (Item'First + (K - 1) mod Item'Length)),
2505 others -- Drop = Left
2506 =>
2507 Length (Replicate'Result) = Max_Length
2508 and then
2509 (for all K in 1 .. Max_Length =>
2510 Element (Replicate'Result, K) =
2511 Item (Item'Last - (Max_Length - K) mod Item'Length)));
2512
2513 function Replicate
2514 (Count : Natural;
2515 Item : Bounded_String;
2516 Drop : Truncation := Error) return Bounded_String
2517 with
2518 Pre =>
2519 (if Count /= 0 and then Length (Item) > Max_Length / Count
2520 then Drop /= Error),
2521 Contract_Cases =>
2522 ((if Count /= 0 then Length (Item) <= Max_Length / Count)
2523 =>
2524 Length (Replicate'Result) = Count * Length (Item)
2525 and then
2526 (if Length (Item) > 0 then
2527 (for all K in 1 .. Count * Length (Item) =>
2528 Element (Replicate'Result, K) =
2529 Element (Item, 1 + (K - 1) mod Length (Item)))),
2530 Count /= 0
2531 and then Length (Item) > Max_Length / Count
2532 and then Drop = Right
2533 =>
2534 Length (Replicate'Result) = Max_Length
2535 and then
2536 (for all K in 1 .. Max_Length =>
2537 Element (Replicate'Result, K) =
2538 Element (Item, 1 + (K - 1) mod Length (Item))),
2539 others -- Drop = Left
2540 =>
2541 Length (Replicate'Result) = Max_Length
2542 and then
2543 (for all K in 1 .. Max_Length =>
2544 Element (Replicate'Result, K) =
2545 Element (Item,
2546 Length (Item) - (Max_Length - K) mod Length (Item))));
2547
2548 private
2549 -- Most of the implementation is in the separate non generic package
2550 -- Ada.Strings.Superbounded. Type Bounded_String is derived from type
2551 -- Superbounded.Super_String with the maximum length constraint. In
2552 -- almost all cases, the routines in Superbounded can be called with
2553 -- no requirement to pass the maximum length explicitly, since there
2554 -- is at least one Bounded_String argument from which the maximum
2555 -- length can be obtained. For all such routines, the implementation
2556 -- in this private part is simply a renaming of the corresponding
2557 -- routine in the superbounded package.
2558
2559 -- The five exceptions are the * and Replicate routines operating on
2560 -- character values. For these cases, we have a routine in the body
2561 -- that calls the superbounded routine passing the maximum length
2562 -- explicitly as an extra parameter.
2563
2564 type Bounded_String is new Superbounded.Super_String (Max_Length);
2565 -- Deriving Bounded_String from Superbounded.Super_String is the
2566 -- real trick, it ensures that the type Bounded_String declared in
2567 -- the generic instantiation is compatible with the Super_String
2568 -- type declared in the Superbounded package.
2569
2570 function From_String (Source : String) return Bounded_String
2571 with Pre => Source'Length <= Max_Length;
2572 -- Private routine used only by Stream_Convert
2573
2574 pragma Stream_Convert (Bounded_String, From_String, To_String);
2575 -- Provide stream routines without dragging in Ada.Streams
2576
2577 Null_Bounded_String : constant Bounded_String :=
2578 (Max_Length => Max_Length,
2579 Current_Length => 0,
2580 Data =>
2581 [1 .. Max_Length => ASCII.NUL]);
2582
2583 pragma Inline (To_Bounded_String);
2584
2585 procedure Set_Bounded_String
2586 (Target : out Bounded_String;
2587 Source : String;
2588 Drop : Truncation := Error)
2589 renames Set_Super_String;
2590
2591 function Length
2592 (Source : Bounded_String) return Length_Range
2593 renames Super_Length;
2594
2595 function To_String
2596 (Source : Bounded_String) return String
2597 renames Super_To_String;
2598
2599 function Append
2600 (Left : Bounded_String;
2601 Right : Bounded_String;
2602 Drop : Truncation := Error) return Bounded_String
2603 renames Super_Append;
2604
2605 function Append
2606 (Left : Bounded_String;
2607 Right : String;
2608 Drop : Truncation := Error) return Bounded_String
2609 renames Super_Append;
2610
2611 function Append
2612 (Left : String;
2613 Right : Bounded_String;
2614 Drop : Truncation := Error) return Bounded_String
2615 renames Super_Append;
2616
2617 function Append
2618 (Left : Bounded_String;
2619 Right : Character;
2620 Drop : Truncation := Error) return Bounded_String
2621 renames Super_Append;
2622
2623 function Append
2624 (Left : Character;
2625 Right : Bounded_String;
2626 Drop : Truncation := Error) return Bounded_String
2627 renames Super_Append;
2628
2629 procedure Append
2630 (Source : in out Bounded_String;
2631 New_Item : Bounded_String;
2632 Drop : Truncation := Error)
2633 renames Super_Append;
2634
2635 procedure Append
2636 (Source : in out Bounded_String;
2637 New_Item : String;
2638 Drop : Truncation := Error)
2639 renames Super_Append;
2640
2641 procedure Append
2642 (Source : in out Bounded_String;
2643 New_Item : Character;
2644 Drop : Truncation := Error)
2645 renames Super_Append;
2646
2647 function "&"
2648 (Left : Bounded_String;
2649 Right : Bounded_String) return Bounded_String
2650 renames Concat;
2651
2652 function "&"
2653 (Left : Bounded_String;
2654 Right : String) return Bounded_String
2655 renames Concat;
2656
2657 function "&"
2658 (Left : String;
2659 Right : Bounded_String) return Bounded_String
2660 renames Concat;
2661
2662 function "&"
2663 (Left : Bounded_String;
2664 Right : Character) return Bounded_String
2665 renames Concat;
2666
2667 function "&"
2668 (Left : Character;
2669 Right : Bounded_String) return Bounded_String
2670 renames Concat;
2671
2672 function Element
2673 (Source : Bounded_String;
2674 Index : Positive) return Character
2675 renames Super_Element;
2676
2677 procedure Replace_Element
2678 (Source : in out Bounded_String;
2679 Index : Positive;
2680 By : Character)
2681 renames Super_Replace_Element;
2682
2683 function Slice
2684 (Source : Bounded_String;
2685 Low : Positive;
2686 High : Natural) return String
2687 renames Super_Slice;
2688
2689 function Bounded_Slice
2690 (Source : Bounded_String;
2691 Low : Positive;
2692 High : Natural) return Bounded_String
2693 renames Super_Slice;
2694
2695 procedure Bounded_Slice
2696 (Source : Bounded_String;
2697 Target : out Bounded_String;
2698 Low : Positive;
2699 High : Natural)
2700 renames Super_Slice;
2701
2702 overriding function "="
2703 (Left : Bounded_String;
2704 Right : Bounded_String) return Boolean
2705 renames Equal;
2706
2707 function "="
2708 (Left : Bounded_String;
2709 Right : String) return Boolean
2710 renames Equal;
2711
2712 function "="
2713 (Left : String;
2714 Right : Bounded_String) return Boolean
2715 renames Equal;
2716
2717 function "<"
2718 (Left : Bounded_String;
2719 Right : Bounded_String) return Boolean
2720 renames Less;
2721
2722 function "<"
2723 (Left : Bounded_String;
2724 Right : String) return Boolean
2725 renames Less;
2726
2727 function "<"
2728 (Left : String;
2729 Right : Bounded_String) return Boolean
2730 renames Less;
2731
2732 function "<="
2733 (Left : Bounded_String;
2734 Right : Bounded_String) return Boolean
2735 renames Less_Or_Equal;
2736
2737 function "<="
2738 (Left : Bounded_String;
2739 Right : String) return Boolean
2740 renames Less_Or_Equal;
2741
2742 function "<="
2743 (Left : String;
2744 Right : Bounded_String) return Boolean
2745 renames Less_Or_Equal;
2746
2747 function ">"
2748 (Left : Bounded_String;
2749 Right : Bounded_String) return Boolean
2750 renames Greater;
2751
2752 function ">"
2753 (Left : Bounded_String;
2754 Right : String) return Boolean
2755 renames Greater;
2756
2757 function ">"
2758 (Left : String;
2759 Right : Bounded_String) return Boolean
2760 renames Greater;
2761
2762 function ">="
2763 (Left : Bounded_String;
2764 Right : Bounded_String) return Boolean
2765 renames Greater_Or_Equal;
2766
2767 function ">="
2768 (Left : Bounded_String;
2769 Right : String) return Boolean
2770 renames Greater_Or_Equal;
2771
2772 function ">="
2773 (Left : String;
2774 Right : Bounded_String) return Boolean
2775 renames Greater_Or_Equal;
2776
2777 function Index
2778 (Source : Bounded_String;
2779 Pattern : String;
2780 Going : Direction := Forward;
2781 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
2782 renames Super_Index;
2783
2784 function Index
2785 (Source : Bounded_String;
2786 Pattern : String;
2787 Going : Direction := Forward;
2788 Mapping : Maps.Character_Mapping_Function) return Natural
2789 renames Super_Index;
2790
2791 function Index
2792 (Source : Bounded_String;
2793 Set : Maps.Character_Set;
2794 Test : Membership := Inside;
2795 Going : Direction := Forward) return Natural
2796 renames Super_Index;
2797
2798 function Index
2799 (Source : Bounded_String;
2800 Pattern : String;
2801 From : Positive;
2802 Going : Direction := Forward;
2803 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
2804 renames Super_Index;
2805
2806 function Index
2807 (Source : Bounded_String;
2808 Pattern : String;
2809 From : Positive;
2810 Going : Direction := Forward;
2811 Mapping : Maps.Character_Mapping_Function) return Natural
2812 renames Super_Index;
2813
2814 function Index
2815 (Source : Bounded_String;
2816 Set : Maps.Character_Set;
2817 From : Positive;
2818 Test : Membership := Inside;
2819 Going : Direction := Forward) return Natural
2820 renames Super_Index;
2821
2822 function Index_Non_Blank
2823 (Source : Bounded_String;
2824 Going : Direction := Forward) return Natural
2825 renames Super_Index_Non_Blank;
2826
2827 function Index_Non_Blank
2828 (Source : Bounded_String;
2829 From : Positive;
2830 Going : Direction := Forward) return Natural
2831 renames Super_Index_Non_Blank;
2832
2833 function Count
2834 (Source : Bounded_String;
2835 Pattern : String;
2836 Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
2837 renames Super_Count;
2838
2839 function Count
2840 (Source : Bounded_String;
2841 Pattern : String;
2842 Mapping : Maps.Character_Mapping_Function) return Natural
2843 renames Super_Count;
2844
2845 function Count
2846 (Source : Bounded_String;
2847 Set : Maps.Character_Set) return Natural
2848 renames Super_Count;
2849
2850 procedure Find_Token
2851 (Source : Bounded_String;
2852 Set : Maps.Character_Set;
2853 From : Positive;
2854 Test : Membership;
2855 First : out Positive;
2856 Last : out Natural)
2857 renames Super_Find_Token;
2858
2859 procedure Find_Token
2860 (Source : Bounded_String;
2861 Set : Maps.Character_Set;
2862 Test : Membership;
2863 First : out Positive;
2864 Last : out Natural)
2865 renames Super_Find_Token;
2866
2867 function Translate
2868 (Source : Bounded_String;
2869 Mapping : Maps.Character_Mapping) return Bounded_String
2870 renames Super_Translate;
2871
2872 procedure Translate
2873 (Source : in out Bounded_String;
2874 Mapping : Maps.Character_Mapping)
2875 renames Super_Translate;
2876
2877 function Translate
2878 (Source : Bounded_String;
2879 Mapping : Maps.Character_Mapping_Function) return Bounded_String
2880 renames Super_Translate;
2881
2882 procedure Translate
2883 (Source : in out Bounded_String;
2884 Mapping : Maps.Character_Mapping_Function)
2885 renames Super_Translate;
2886
2887 function Replace_Slice
2888 (Source : Bounded_String;
2889 Low : Positive;
2890 High : Natural;
2891 By : String;
2892 Drop : Truncation := Error) return Bounded_String
2893 renames Super_Replace_Slice;
2894
2895 procedure Replace_Slice
2896 (Source : in out Bounded_String;
2897 Low : Positive;
2898 High : Natural;
2899 By : String;
2900 Drop : Truncation := Error)
2901 renames Super_Replace_Slice;
2902
2903 function Insert
2904 (Source : Bounded_String;
2905 Before : Positive;
2906 New_Item : String;
2907 Drop : Truncation := Error) return Bounded_String
2908 renames Super_Insert;
2909
2910 procedure Insert
2911 (Source : in out Bounded_String;
2912 Before : Positive;
2913 New_Item : String;
2914 Drop : Truncation := Error)
2915 renames Super_Insert;
2916
2917 function Overwrite
2918 (Source : Bounded_String;
2919 Position : Positive;
2920 New_Item : String;
2921 Drop : Truncation := Error) return Bounded_String
2922 renames Super_Overwrite;
2923
2924 procedure Overwrite
2925 (Source : in out Bounded_String;
2926 Position : Positive;
2927 New_Item : String;
2928 Drop : Truncation := Error)
2929 renames Super_Overwrite;
2930
2931 function Delete
2932 (Source : Bounded_String;
2933 From : Positive;
2934 Through : Natural) return Bounded_String
2935 renames Super_Delete;
2936
2937 procedure Delete
2938 (Source : in out Bounded_String;
2939 From : Positive;
2940 Through : Natural)
2941 renames Super_Delete;
2942
2943 function Trim
2944 (Source : Bounded_String;
2945 Side : Trim_End) return Bounded_String
2946 renames Super_Trim;
2947
2948 procedure Trim
2949 (Source : in out Bounded_String;
2950 Side : Trim_End)
2951 renames Super_Trim;
2952
2953 function Trim
2954 (Source : Bounded_String;
2955 Left : Maps.Character_Set;
2956 Right : Maps.Character_Set) return Bounded_String
2957 renames Super_Trim;
2958
2959 procedure Trim
2960 (Source : in out Bounded_String;
2961 Left : Maps.Character_Set;
2962 Right : Maps.Character_Set)
2963 renames Super_Trim;
2964
2965 function Head
2966 (Source : Bounded_String;
2967 Count : Natural;
2968 Pad : Character := Space;
2969 Drop : Truncation := Error) return Bounded_String
2970 renames Super_Head;
2971
2972 procedure Head
2973 (Source : in out Bounded_String;
2974 Count : Natural;
2975 Pad : Character := Space;
2976 Drop : Truncation := Error)
2977 renames Super_Head;
2978
2979 function Tail
2980 (Source : Bounded_String;
2981 Count : Natural;
2982 Pad : Character := Space;
2983 Drop : Truncation := Error) return Bounded_String
2984 renames Super_Tail;
2985
2986 procedure Tail
2987 (Source : in out Bounded_String;
2988 Count : Natural;
2989 Pad : Character := Space;
2990 Drop : Truncation := Error)
2991 renames Super_Tail;
2992
2993 function "*"
2994 (Left : Natural;
2995 Right : Bounded_String) return Bounded_String
2996 renames Times;
2997
2998 function Replicate
2999 (Count : Natural;
3000 Item : Bounded_String;
3001 Drop : Truncation := Error) return Bounded_String
3002 renames Super_Replicate;
3003
3004 end Generic_Bounded_Length;
3005
3006 end Ada.Strings.Bounded;