DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Ada.Strings.Unbounded

Strings of any length, copied by assignment (RM A.4.5).

Read the family guide for representation, selection and resource rules. The complete declaration page retains exact signatures/contracts; the source specification is the implementation baseline.

Availability and ownership

All of RM A.4.5. The value holds a Verada.Strings.Texts.Text, shared by copies and freed by its last holder; each operation's contract states its result over To_String. Index_Error and Pattern_Error are preconditions; String_Access is pool-specific.

A client proof uses these contracts without proving the body again (see library assurance). Global => null excludes package-global effects, not changes made through an in out argument.

Import and instantiate

with Ada.Strings.Unbounded;
import Ada.Strings.Unbounded;

A Vibe module imports this unit's names with from Ada.Strings.Unbounded import Name; see library use across syntaxes. In Varc, keep each name's declared spelling and write & on arguments the call changes.

Contract and lifecycle reading

A Pre condition is the caller's obligation; a Post is what a normal return guarantees. What a postcondition does not state, a client cannot assume. Ghost functions are for contracts and ghost code. The family guide describes copying, lifetime, order and cost.

API 001

Unbounded_String (declaration) — A string of any length, copied by assignment; a default one is empty. Its characters are a shared Text, freed by the last holder.

Declared interface:

type Unbounded_String is private
  with Default_Initial_Condition => Length (Unbounded_String) = 0;

API 002

Length (declaration) — The number of characters.

Declared interface:

function Length (Source : Unbounded_String) return Natural
  with Global => null,
       Post => Length'Result < Verada.Storage.Length_Bound;

API 003

To_String (declaration) — The model: the characters as a String from 1.

Declared interface:

function To_String (Source : Unbounded_String) return String
  with Global => null,
       Post => To_String'Result'Length = Length (Source)
               and then (To_String'Result'Length = 0 or else To_String'Result'First = 1);

API 004

Null_Unbounded_String (declaration) — The empty string.

Declared interface:

Null_Unbounded_String : constant Unbounded_String;

API 005

String_Access (declaration) — An access to a String, pool-specific so that Free may release what it designates.

Declared interface:

type String_Access is access String;

API 006

Free (declaration) — Deallocates what X designates and sets X to null.

Declared interface:

procedure Free (X : in out String_Access)
  with Global => null,
       Post => X = null;

API 007

Occurs_After (declaration) — Ghost: whether Pattern occurs, each character of Source mapped, after Source's first Done characters.

Declared interface:

function Occurs_After (Source, Pattern : String; Done : Natural; Mapping : Maps.Character_Mapping) return Boolean is
  (Done <= Source'Length - Pattern'Length
   and then (for all K in 0 .. Pattern'Length - 1 =>
               Maps.Value (Mapping, Source (Source'First + Done + K)) = Pattern (Pattern'First + K)))
  with Ghost, Global => null;

API 008

Count_After (declaration) — Ghost: how many non-overlapping occurrences of Pattern follow Source's first Done characters, each found from the left.

Declared interface:

function Count_After (Source, Pattern : String; Done : Natural; Mapping : Maps.Character_Mapping) return Natural is
  (if Done > Source'Length - Pattern'Length then 0
   elsif Occurs_After (Source, Pattern, Done, Mapping) then 1 + Count_After (Source, Pattern, Done + Pattern'Length, Mapping)
   else Count_After (Source, Pattern, Done + 1, Mapping))
  with Ghost, Global => null,
       Pre => Pattern'Length > 0 and then Done <= Source'Length,
       Post => Count_After'Result <= Source'Length - Done,
       Subprogram_Variant => (Decreases => Source'Length - Done);

API 009

Count_In (declaration) — Ghost: how many characters after Source's first Done characters pass Test for Set.

Declared interface:

function Count_In (Source : String; Set : Maps.Character_Set; Test : Membership; Done : Natural) return Natural is
  (if Done >= Source'Length then 0
   else (if Maps.Is_In (Source (Source'First + Done), Set) = (Test = Inside) then 1 else 0)
        + Count_In (Source, Set, Test, Done + 1))
  with Ghost, Global => null,
       Pre => Done <= Source'Length,
       Post => Count_In'Result <= Source'Length - Done,
       Subprogram_Variant => (Decreases => Source'Length - Done);

API 010

Joined (declaration) — A, B and C joined, indexed from 1: the result Replace_Slice, Insert, Overwrite and the & of a String or Character on the left state.

Declared interface:

function Joined (A, B, C : String) return String is
  (String'(for I in 1 .. A'Length + B'Length + C'Length =>
             (if I <= A'Length then A (A'First + (I - 1))
              elsif I <= A'Length + B'Length then B (B'First + (I - 1 - A'Length))
              else C (C'First + (I - 1 - A'Length - B'Length)))))
  with Global => null,
       Pre => Long_Long_Long_Integer (A'Length) + Long_Long_Long_Integer (B'Length) + Long_Long_Long_Integer (C'Length)
              < Verada.Storage.Length_Bound,
       Post => Joined'Result'Length = A'Length + B'Length + C'Length
               and then (Joined'Result'Length = 0 or else Joined'Result'First = 1);

API 011

To_Unbounded_String (declaration) — The string of Source's characters.

Declared interface:

function To_Unbounded_String (Source : String) return Unbounded_String
  with Global => null,
       Post => To_String (To_Unbounded_String'Result) = Source;

API 012

To_Unbounded_String (declaration) — A string of Length spaces.

Declared interface:

function To_Unbounded_String (Length : Natural) return Unbounded_String
  with Global => null,
       Post => Unbounded.Length (To_Unbounded_String'Result) = Length;

API 013

Set_Unbounded_String (declaration) — Target takes Source's characters.

Declared interface:

procedure Set_Unbounded_String (Target : out Unbounded_String; Source : String)
  with Global => null,
       Post => To_String (Target) = Source;

API 014

Append (declaration) — Joins New_Item's characters to Source's end.

Declared interface:

procedure Append (Source : in out Unbounded_String; New_Item : Unbounded_String)
  with Global => null,
       Post => To_String (Source) = To_String (Source)'Old & To_String (New_Item);

API 015

Append (declaration) — Joins the String New_Item to Source's end.

Declared interface:

procedure Append (Source : in out Unbounded_String; New_Item : String)
  with Global => null,
       Post => To_String (Source) = To_String (Source)'Old & New_Item;

API 016

Append (declaration) — Joins one character to Source's end.

Declared interface:

procedure Append (Source : in out Unbounded_String; New_Item : Character)
  with Global => null,
       Post => To_String (Source) = To_String (Source)'Old & New_Item;

API 017

"&" (declaration) — The two strings joined.

Declared interface:

function "&" (Left, Right : Unbounded_String) return Unbounded_String
  with Global => null,
       Post => To_String ("&"'Result) = To_String (Left) & To_String (Right);

API 018

"&" (declaration) — Left joined with the String Right.

Declared interface:

function "&" (Left : Unbounded_String; Right : String) return Unbounded_String
  with Global => null,
       Post => To_String ("&"'Result) = To_String (Left) & Right;

API 019

"&" (declaration) — The String Left joined with Right.

Declared interface:

function "&" (Left : String; Right : Unbounded_String) return Unbounded_String
  with Global => null,
       Post => To_String ("&"'Result) = Joined (Left, To_String (Right), "");

API 020

"&" (declaration) — Left joined with one character.

Declared interface:

function "&" (Left : Unbounded_String; Right : Character) return Unbounded_String
  with Global => null,
       Post => To_String ("&"'Result) = To_String (Left) & Right;

API 021

"&" (declaration) — One character joined with Right.

Declared interface:

function "&" (Left : Character; Right : Unbounded_String) return Unbounded_String
  with Global => null,
       Post => To_String ("&"'Result) = Joined (String'(1 => Left), To_String (Right), "");

API 022

Element (declaration) — The character at Index, which must be a position of Source.

Declared interface:

function Element (Source : Unbounded_String; Index : Positive) return Character
  with Global => null,
       Pre => Index <= Length (Source),
       Post => Element'Result = To_String (Source) (Index);

API 023

Replace_Element (declaration) — The character at Index replaced by By; the others kept.

Declared interface:

procedure Replace_Element (Source : in out Unbounded_String; Index : Positive; By : Character)
  with Global => null,
       Pre => Index <= Length (Source),
       Post => To_String (Source) = To_String (Source)'Old (1 .. Index - 1) & By & To_String (Source)'Old (Index + 1 .. Length (Source)'Old);

API 024

Slice (declaration) — The characters at Low .. High, as a String with those bounds.

Declared interface:

function Slice (Source : Unbounded_String; Low : Positive; High : Natural) return String
  with Global => null,
       Pre => Low <= Length (Source) + 1 and then High <= Length (Source),
       Post => Slice'Result'First = Low and then Slice'Result'Last = High
               and then Slice'Result = To_String (Source) (Low .. High);

API 025

Unbounded_Slice (declaration) — The characters at Low .. High, as an Unbounded_String.

Declared interface:

function Unbounded_Slice (Source : Unbounded_String; Low : Positive; High : Natural) return Unbounded_String
  with Global => null,
       Pre => Low <= Length (Source) + 1 and then High <= Length (Source),
       Post => To_String (Unbounded_Slice'Result) = To_String (Source) (Low .. High);

API 026

Unbounded_Slice (declaration) — Target takes the characters at Low .. High.

Declared interface:

procedure Unbounded_Slice (Source : Unbounded_String; Target : out Unbounded_String; Low : Positive; High : Natural)
  with Global => null,
       Pre => Low <= Length (Source) + 1 and then High <= Length (Source),
       Post => To_String (Target) = To_String (Source) (Low .. High);

API 027

"=" (declaration) — Whether the characters are equal.

Declared interface:

function "=" (Left, Right : Unbounded_String) return Boolean
  with Global => null,
       Post => "="'Result = (To_String (Left) = To_String (Right));

API 028

"=" (declaration) — Whether the characters equal the String's.

Declared interface:

function "=" (Left : Unbounded_String; Right : String) return Boolean
  with Global => null,
       Post => "="'Result = (To_String (Left) = Right);

API 029

"=" (declaration) — Whether the String's characters equal Right's.

Declared interface:

function "=" (Left : String; Right : Unbounded_String) return Boolean
  with Global => null,
       Post => "="'Result = (Left = To_String (Right));

API 030

"<" (declaration) — Ada's String ordering of the characters.

Declared interface:

function "<" (Left, Right : Unbounded_String) return Boolean
  with Global => null,
       Post => "<"'Result = (To_String (Left) < To_String (Right));

API 031

"<" (declaration) — Ada's String ordering of the characters.

Declared interface:

function "<" (Left : Unbounded_String; Right : String) return Boolean
  with Global => null,
       Post => "<"'Result = (To_String (Left) < Right);

API 032

"<" (declaration) — Ada's String ordering of the characters.

Declared interface:

function "<" (Left : String; Right : Unbounded_String) return Boolean
  with Global => null,
       Post => "<"'Result = (Left < To_String (Right));

API 033

"<=" (declaration) — Ada's String ordering of the characters.

Declared interface:

function "<=" (Left, Right : Unbounded_String) return Boolean
  with Global => null,
       Post => "<="'Result = (To_String (Left) <= To_String (Right));

API 034

"<=" (declaration) — Ada's String ordering of the characters.

Declared interface:

function "<=" (Left : Unbounded_String; Right : String) return Boolean
  with Global => null,
       Post => "<="'Result = (To_String (Left) <= Right);

API 035

"<=" (declaration) — Ada's String ordering of the characters.

Declared interface:

function "<=" (Left : String; Right : Unbounded_String) return Boolean
  with Global => null,
       Post => "<="'Result = (Left <= To_String (Right));

API 036

">" (declaration) — Ada's String ordering of the characters.

Declared interface:

function ">" (Left, Right : Unbounded_String) return Boolean
  with Global => null,
       Post => ">"'Result = (To_String (Left) > To_String (Right));

API 037

">" (declaration) — Ada's String ordering of the characters.

Declared interface:

function ">" (Left : Unbounded_String; Right : String) return Boolean
  with Global => null,
       Post => ">"'Result = (To_String (Left) > Right);

API 038

">" (declaration) — Ada's String ordering of the characters.

Declared interface:

function ">" (Left : String; Right : Unbounded_String) return Boolean
  with Global => null,
       Post => ">"'Result = (Left > To_String (Right));

API 039

">=" (declaration) — Ada's String ordering of the characters.

Declared interface:

function ">=" (Left, Right : Unbounded_String) return Boolean
  with Global => null,
       Post => ">="'Result = (To_String (Left) >= To_String (Right));

API 040

">=" (declaration) — Ada's String ordering of the characters.

Declared interface:

function ">=" (Left : Unbounded_String; Right : String) return Boolean
  with Global => null,
       Post => ">="'Result = (To_String (Left) >= Right);

API 041

">=" (declaration) — Ada's String ordering of the characters.

Declared interface:

function ">=" (Left : String; Right : Unbounded_String) return Boolean
  with Global => null,
       Post => ">="'Result = (Left >= To_String (Right));

API 042

Index (declaration) — The first (Forward) or last (Backward) place where a nonempty Pattern occurs, each character mapped, or 0; the postcondition says no earlier (or later) place matches.

Declared interface:

function Index (Source : Unbounded_String; Pattern : String; Going : Direction := Forward;
                Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
  with Global => null,
       Pre => Pattern'Length > 0,
       Post => (if Index'Result = 0
                then (for all D in 0 .. Length (Source) - Pattern'Length => not Occurs_After (To_String (Source), Pattern, D, Mapping))
                else Index'Result <= Length (Source) - Pattern'Length + 1
                     and then Occurs_After (To_String (Source), Pattern, Index'Result - 1, Mapping)
                     and then (if Going = Forward
                               then (for all D in 0 .. Index'Result - 2 => not Occurs_After (To_String (Source), Pattern, D, Mapping))
                               else (for all D in Index'Result .. Length (Source) - Pattern'Length => not Occurs_After (To_String (Source), Pattern, D, Mapping))));

API 043

Index (declaration) — As Index with a mapping, the mapping a function; the result is 0 or a place where Pattern fits.

Declared interface:

function Index (Source : Unbounded_String; Pattern : String; Going : Direction := Forward;
                Mapping : Maps.Character_Mapping_Function) return Natural
  with Global => null,
       Pre => Pattern'Length > 0 and then Mapping /= null,
       Post => Index'Result = 0 or else Index'Result <= Length (Source) - Pattern'Length + 1;

API 044

Index (declaration) — As Index, searching from From on (Forward) or up to From (Backward).

Declared interface:

function Index (Source : Unbounded_String; Pattern : String; From : Positive; Going : Direction := Forward;
                Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
  with Global => null,
       Pre => Pattern'Length > 0 and then From <= Length (Source),
       Post => (if Going = Forward
                then (if Index'Result = 0
                      then (for all D in From - 1 .. Length (Source) - Pattern'Length => not Occurs_After (To_String (Source), Pattern, D, Mapping))
                      else Index'Result >= From and then Index'Result <= Length (Source) - Pattern'Length + 1
                           and then Occurs_After (To_String (Source), Pattern, Index'Result - 1, Mapping)
                           and then (for all D in From - 1 .. Index'Result - 2 => not Occurs_After (To_String (Source), Pattern, D, Mapping)))
                else (if Index'Result = 0
                      then (for all D in 0 .. From - Pattern'Length => not Occurs_After (To_String (Source), Pattern, D, Mapping))
                      else Index'Result <= From - Pattern'Length + 1
                           and then Occurs_After (To_String (Source), Pattern, Index'Result - 1, Mapping)
                           and then (for all D in Index'Result .. From - Pattern'Length => not Occurs_After (To_String (Source), Pattern, D, Mapping))));

API 045

Index (declaration) — As Index from From, the mapping a function.

Declared interface:

function Index (Source : Unbounded_String; Pattern : String; From : Positive; Going : Direction := Forward;
                Mapping : Maps.Character_Mapping_Function) return Natural
  with Global => null,
       Pre => Pattern'Length > 0 and then Mapping /= null and then From <= Length (Source),
       Post => Index'Result = 0 or else Index'Result <= Length (Source) - Pattern'Length + 1;

API 046

Index (declaration) — The first (or last) character that is in Set (Test Inside) or not (Outside), or 0.

Declared interface:

function Index (Source : Unbounded_String; Set : Maps.Character_Set; Test : Membership := Inside;
                Going : Direction := Forward) return Natural
  with Global => null,
       Post => (if Index'Result = 0
                then (for all I in 1 .. Length (Source) => Maps.Is_In (To_String (Source) (I), Set) /= (Test = Inside))
                else Index'Result <= Length (Source)
                     and then Maps.Is_In (To_String (Source) (Index'Result), Set) = (Test = Inside)
                     and then (if Going = Forward
                               then (for all I in 1 .. Index'Result - 1 => Maps.Is_In (To_String (Source) (I), Set) /= (Test = Inside))
                               else (for all I in Index'Result + 1 .. Length (Source) => Maps.Is_In (To_String (Source) (I), Set) /= (Test = Inside))));

API 047

Index (declaration) — As Index of a set, from From on (Forward) or up to From (Backward).

Declared interface:

function Index (Source : Unbounded_String; Set : Maps.Character_Set; From : Positive; Test : Membership := Inside;
                Going : Direction := Forward) return Natural
  with Global => null,
       Pre => From <= Length (Source),
       Post => (if Going = Forward
                then (if Index'Result = 0
                      then (for all I in From .. Length (Source) => Maps.Is_In (To_String (Source) (I), Set) /= (Test = Inside))
                      else Index'Result in From .. Length (Source)
                           and then Maps.Is_In (To_String (Source) (Index'Result), Set) = (Test = Inside)
                           and then (for all I in From .. Index'Result - 1 => Maps.Is_In (To_String (Source) (I), Set) /= (Test = Inside)))
                else (if Index'Result = 0
                      then (for all I in 1 .. From => Maps.Is_In (To_String (Source) (I), Set) /= (Test = Inside))
                      else Index'Result <= From
                           and then Maps.Is_In (To_String (Source) (Index'Result), Set) = (Test = Inside)
                           and then (for all I in Index'Result + 1 .. From => Maps.Is_In (To_String (Source) (I), Set) /= (Test = Inside))));

API 048

Index_Non_Blank (declaration) — The first (or last) character that is not a space, or 0.

Declared interface:

function Index_Non_Blank (Source : Unbounded_String; Going : Direction := Forward) return Natural
  with Global => null,
       Post => (if Index_Non_Blank'Result = 0
                then (for all I in 1 .. Length (Source) => To_String (Source) (I) = Space)
                else Index_Non_Blank'Result <= Length (Source)
                     and then To_String (Source) (Index_Non_Blank'Result) /= Space
                     and then (if Going = Forward
                               then (for all I in 1 .. Index_Non_Blank'Result - 1 => To_String (Source) (I) = Space)
                               else (for all I in Index_Non_Blank'Result + 1 .. Length (Source) => To_String (Source) (I) = Space)));

API 049

Index_Non_Blank (declaration) — As Index_Non_Blank, from From on or up to From.

Declared interface:

function Index_Non_Blank (Source : Unbounded_String; From : Positive; Going : Direction := Forward) return Natural
  with Global => null,
       Pre => From <= Length (Source),
       Post => (if Going = Forward
                then (if Index_Non_Blank'Result = 0
                      then (for all I in From .. Length (Source) => To_String (Source) (I) = Space)
                      else Index_Non_Blank'Result in From .. Length (Source)
                           and then To_String (Source) (Index_Non_Blank'Result) /= Space
                           and then (for all I in From .. Index_Non_Blank'Result - 1 => To_String (Source) (I) = Space))
                else (if Index_Non_Blank'Result = 0
                      then (for all I in 1 .. From => To_String (Source) (I) = Space)
                      else Index_Non_Blank'Result <= From
                           and then To_String (Source) (Index_Non_Blank'Result) /= Space
                           and then (for all I in Index_Non_Blank'Result + 1 .. From => To_String (Source) (I) = Space)));

API 050

Count (declaration) — How many non-overlapping occurrences of a nonempty Pattern, each character mapped, found from the left: Count_After's.

Declared interface:

function Count (Source : Unbounded_String; Pattern : String; Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
  with Global => null,
       Pre => Pattern'Length > 0,
       Post => Count'Result = Count_After (To_String (Source), Pattern, 0, Mapping);

API 051

Count (declaration) — As Count with a mapping function; at most the length.

Declared interface:

function Count (Source : Unbounded_String; Pattern : String; Mapping : Maps.Character_Mapping_Function) return Natural
  with Global => null,
       Pre => Pattern'Length > 0 and then Mapping /= null,
       Post => Count'Result <= Length (Source);

API 052

Count (declaration) — How many characters are in Set: Count_In's.

Declared interface:

function Count (Source : Unbounded_String; Set : Maps.Character_Set) return Natural
  with Global => null,
       Post => Count'Result = Count_In (To_String (Source), Set, Inside, 0);

API 053

Find_Token (declaration) — The first run of characters from From on that all pass Test for Set, as long as it goes: First .. Last; First = From and Last = 0 when there is none.

Declared interface:

procedure Find_Token (Source : Unbounded_String; Set : Maps.Character_Set; From : Positive; Test : Membership;
                      First : out Positive; Last : out Natural)
  with Global => null,
       Pre => From <= Length (Source),
       Post => (if Last = 0
                then First = From
                     and then (for all I in From .. Length (Source) => Maps.Is_In (To_String (Source) (I), Set) /= (Test = Inside))
                else First in From .. Last and then Last <= Length (Source)
                     and then (for all I in From .. First - 1 => Maps.Is_In (To_String (Source) (I), Set) /= (Test = Inside))
                     and then (for all I in First .. Last => Maps.Is_In (To_String (Source) (I), Set) = (Test = Inside))
                     and then (Last = Length (Source) or else Maps.Is_In (To_String (Source) (Last + 1), Set) /= (Test = Inside)));

API 054

Find_Token (declaration) — As Find_Token from the first character.

Declared interface:

procedure Find_Token (Source : Unbounded_String; Set : Maps.Character_Set; Test : Membership;
                      First : out Positive; Last : out Natural)
  with Global => null,
       Post => (if Last = 0
                then First = 1
                     and then (for all I in 1 .. Length (Source) => Maps.Is_In (To_String (Source) (I), Set) /= (Test = Inside))
                else First <= Last and then Last <= Length (Source)
                     and then (for all I in 1 .. First - 1 => Maps.Is_In (To_String (Source) (I), Set) /= (Test = Inside))
                     and then (for all I in First .. Last => Maps.Is_In (To_String (Source) (I), Set) = (Test = Inside))
                     and then (Last = Length (Source) or else Maps.Is_In (To_String (Source) (Last + 1), Set) /= (Test = Inside)));

API 055

Translate (declaration) — Each character mapped.

Declared interface:

function Translate (Source : Unbounded_String; Mapping : Maps.Character_Mapping) return Unbounded_String
  with Global => null,
       Post => Length (Translate'Result) = Length (Source)
               and then (for all I in 1 .. Length (Source) => To_String (Translate'Result) (I) = Maps.Value (Mapping, To_String (Source) (I)));

API 056

Translate (declaration) — Source's characters mapped in place.

Declared interface:

procedure Translate (Source : in out Unbounded_String; Mapping : Maps.Character_Mapping)
  with Global => null,
       Post => To_String (Source) = To_String (Translate (Source'Old, Mapping));

API 057

Translate (declaration) — Each character mapped by a function (the length kept).

Declared interface:

function Translate (Source : Unbounded_String; Mapping : Maps.Character_Mapping_Function) return Unbounded_String
  with Global => null,
       Pre => Mapping /= null,
       Post => Length (Translate'Result) = Length (Source);

API 058

Translate (declaration) — Source's characters mapped in place by a function.

Declared interface:

procedure Translate (Source : in out Unbounded_String; Mapping : Maps.Character_Mapping_Function)
  with Global => null,
       Pre => Mapping /= null,
       Post => Length (Source) = Length (Source)'Old;

API 059

Replace_Slice (declaration) — The characters Low .. High replaced by By; By inserted before Low when High < Low.

Declared interface:

function Replace_Slice (Source : Unbounded_String; Low : Positive; High : Natural; By : String) return Unbounded_String
  with Global => null,
       Pre => Low <= Length (Source) + 1,
       Post => To_String (Replace_Slice'Result)
               = Joined (To_String (Source) (1 .. Low - 1), By, To_String (Source) (Integer'Max (Integer'Min (High, Length (Source)) + 1, Low) .. Length (Source)));

API 060

Replace_Slice (declaration) — Source changed to Replace_Slice's result.

Declared interface:

procedure Replace_Slice (Source : in out Unbounded_String; Low : Positive; High : Natural; By : String)
  with Global => null,
       Pre => Low <= Length (Source) + 1,
       Post => To_String (Source) = To_String (Replace_Slice (Source'Old, Low, High, By));

API 061

Insert (declaration) — New_Item inserted before position Before.

Declared interface:

function Insert (Source : Unbounded_String; Before : Positive; New_Item : String) return Unbounded_String
  with Global => null,
       Pre => Before <= Length (Source) + 1,
       Post => To_String (Insert'Result)
               = Joined (To_String (Source) (1 .. Before - 1), New_Item, To_String (Source) (Before .. Length (Source)));

API 062

Insert (declaration) — Source changed to Insert's result.

Declared interface:

procedure Insert (Source : in out Unbounded_String; Before : Positive; New_Item : String)
  with Global => null,
       Pre => Before <= Length (Source) + 1,
       Post => To_String (Source) = To_String (Insert (Source'Old, Before, New_Item));

API 063

Overwrite (declaration) — New_Item written over the characters from Position on, the string extended where it runs past the end.

Declared interface:

function Overwrite (Source : Unbounded_String; Position : Positive; New_Item : String) return Unbounded_String
  with Global => null,
       Pre => Position <= Length (Source) + 1,
       Post => To_String (Overwrite'Result)
               = Joined (To_String (Source) (1 .. Position - 1), New_Item,
                         To_String (Source) ((if New_Item'Length > Length (Source) - Position then Length (Source) + 1 else Position + New_Item'Length) .. Length (Source)));

API 064

Overwrite (declaration) — Source changed to Overwrite's result.

Declared interface:

procedure Overwrite (Source : in out Unbounded_String; Position : Positive; New_Item : String)
  with Global => null,
       Pre => Position <= Length (Source) + 1,
       Post => To_String (Source) = To_String (Overwrite (Source'Old, Position, New_Item));

API 065

Delete (declaration) — The characters From .. Through removed; none when Through < From.

Declared interface:

function Delete (Source : Unbounded_String; From : Positive; Through : Natural) return Unbounded_String
  with Global => null,
       Pre => Through < From or else From <= Length (Source) + 1,
       Post => To_String (Delete'Result)
               = (if Through < From then To_String (Source)
                  else To_String (Source) (1 .. From - 1) & To_String (Source) (Integer'Max (Integer'Min (Through, Length (Source)) + 1, From) .. Length (Source)));

API 066

Delete (declaration) — Source changed to Delete's result.

Declared interface:

procedure Delete (Source : in out Unbounded_String; From : Positive; Through : Natural)
  with Global => null,
       Pre => Through < From or else From <= Length (Source) + 1,
       Post => To_String (Source) = To_String (Delete (Source'Old, From, Through));

API 067

Trim (declaration) — Without leading spaces (Left), trailing ones (Right) or both.

Declared interface:

function Trim (Source : Unbounded_String; Side : Trim_End) return Unbounded_String
  with Global => null,
       Post => (if Index_Non_Blank (Source) = 0 then Length (Trim'Result) = 0
                else To_String (Trim'Result)
                     = To_String (Source) ((if Side = Right then 1 else Index_Non_Blank (Source))
                                           .. (if Side = Left then Length (Source) else Index_Non_Blank (Source, Backward))));

API 068

Trim (declaration) — Source changed to Trim's result.

Declared interface:

procedure Trim (Source : in out Unbounded_String; Side : Trim_End)
  with Global => null,
       Post => To_String (Source) = To_String (Trim (Source'Old, Side));

API 069

Trim (declaration) — Without the leading characters in Left and the trailing ones in Right.

Declared interface:

function Trim (Source : Unbounded_String; Left, Right : Maps.Character_Set) return Unbounded_String
  with Global => null,
       Post => (if Index (Source, Left, Outside) = 0 or else Index (Source, Right, Outside, Backward) < Index (Source, Left, Outside)
                then Length (Trim'Result) = 0
                else To_String (Trim'Result) = To_String (Source) (Index (Source, Left, Outside) .. Index (Source, Right, Outside, Backward)));

API 070

Trim (declaration) — Source changed to that Trim's result.

Declared interface:

procedure Trim (Source : in out Unbounded_String; Left, Right : Maps.Character_Set)
  with Global => null,
       Post => To_String (Source) = To_String (Trim (Source'Old, Left, Right));

API 071

Head (declaration) — The first Count characters, padded on the right with Pad.

Declared interface:

function Head (Source : Unbounded_String; Count : Natural; Pad : Character := Space) return Unbounded_String
  with Global => null,
       Post => Length (Head'Result) = Count
               and then (for all I in 1 .. Count => To_String (Head'Result) (I) = (if I <= Length (Source) then To_String (Source) (I) else Pad));

API 072

Head (declaration) — Source changed to Head's result.

Declared interface:

procedure Head (Source : in out Unbounded_String; Count : Natural; Pad : Character := Space)
  with Global => null,
       Post => To_String (Source) = To_String (Head (Source'Old, Count, Pad));

API 073

Tail (declaration) — The last Count characters, padded on the left with Pad.

Declared interface:

function Tail (Source : Unbounded_String; Count : Natural; Pad : Character := Space) return Unbounded_String
  with Global => null,
       Post => Length (Tail'Result) = Count
               and then (for all I in 1 .. Count =>
                           To_String (Tail'Result) (I) = (if I > Count - Length (Source) then To_String (Source) (I - (Count - Length (Source))) else Pad));

API 074

Tail (declaration) — Source changed to Tail's result.

Declared interface:

procedure Tail (Source : in out Unbounded_String; Count : Natural; Pad : Character := Space)
  with Global => null,
       Post => To_String (Source) = To_String (Tail (Source'Old, Count, Pad));

API 075

"*" (declaration) — Left copies of a character.

Declared interface:

function "*" (Left : Natural; Right : Character) return Unbounded_String
  with Global => null,
       Post => Length ("*"'Result) = Left and then (for all I in 1 .. Left => To_String ("*"'Result) (I) = Right);

API 076

"*" (declaration) — Left copies of a String.

Declared interface:

function "*" (Left : Natural; Right : String) return Unbounded_String
  with Global => null,
       Post => Long_Long_Long_Integer (Length ("*"'Result)) = Long_Long_Long_Integer (Left) * Long_Long_Long_Integer (Right'Length)
               and then (for all I in 1 .. Length ("*"'Result) => To_String ("*"'Result) (I) = Right (Right'First + (I - 1) mod Right'Length));

API 077

"*" (declaration) — Left copies of an Unbounded_String.

Declared interface:

function "*" (Left : Natural; Right : Unbounded_String) return Unbounded_String
  with Global => null,
       Post => Long_Long_Long_Integer (Length ("*"'Result)) = Long_Long_Long_Integer (Left) * Long_Long_Long_Integer (Length (Right))
               and then (for all I in 1 .. Length ("*"'Result) => To_String ("*"'Result) (I) = To_String (Right) ((I - 1) mod Length (Right) + 1));