DEVELOPMENT EDITION · 769442725406
Library Reference

Package Ada.Strings.Wide_Bounded

Verada predefined library: Ada.Strings.Wide_Bounded (Ada RM A.4.4, A.4.7): strings of at most Max characters, with value semantics. Each operation is stated by its model, To_Wide_String, and Ada.Strings.Wide_Fixed's operation on it, so that a proof of one carries over. Where the RM truncates (a Drop parameter) or raises Length_Error, a precondition requires that the result fits, and Index_Error and Pattern_Error likewise. (Generated from tools/library/bounded.vads.in by tools/library/strings-widths.vb.)

generic
   Max : Positive;
package Generic_Bounded_Length is
   use type Wide_Maps.Wide_Character_Mapping_Function;

   Max_Length : constant Positive := Max;

   subtype Length_Range is Natural range 0 .. Max_Length;

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

   function Length (Source : Bounded_Wide_String) return Length_Range
     with Global => null;

   --  the model of a value: its characters, from 1
   function To_Wide_String (Source : Bounded_Wide_String) return Wide_String
     with Global => null,
          Post => To_Wide_String'Result'Length = Length (Source) and then To_Wide_String'Result'First = 1 and then To_Wide_String'Result'Last = Length (Source);

   function Null_Bounded_Wide_String return Bounded_Wide_String
     with Global => null,
          Post => Length (Null_Bounded_Wide_String'Result) = 0;

   function To_Bounded_Wide_String (Source : Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Source'Length <= Max_Length,
          Post => To_Wide_String (To_Bounded_Wide_String'Result) = Source;

   procedure Set_Bounded_Wide_String (Target : out Bounded_Wide_String; Source : Wide_String)
     with Global => null,
          Pre => Source'Length <= Max_Length,
          Post => To_Wide_String (Target) = Source;

   function Append (Left, Right : Bounded_Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Length (Right) <= Max_Length - Length (Left),
          Post => To_Wide_String (Append'Result) = To_Wide_String (Left) & To_Wide_String (Right);

   function Append (Left : Bounded_Wide_String; Right : Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Right'Length <= Max_Length - Length (Left),
          Post => To_Wide_String (Append'Result) = To_Wide_String (Left) & Right;

   function Append (Left : Wide_String; Right : Bounded_Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Left'Length <= Max_Length - Length (Right),
          Post => To_Wide_String (Append'Result) = Wide_Fixed.Joined (Left, To_Wide_String (Right), "");

   function Append (Left : Bounded_Wide_String; Right : Wide_Character) return Bounded_Wide_String
     with Global => null,
          Pre => Length (Left) < Max_Length,
          Post => To_Wide_String (Append'Result) = To_Wide_String (Left) & Right;

   function Append (Left : Wide_Character; Right : Bounded_Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Length (Right) < Max_Length,
          Post => To_Wide_String (Append'Result) = Left & To_Wide_String (Right);

   procedure Append (Source : in out Bounded_Wide_String; New_Item : Bounded_Wide_String)
     with Global => null,
          Pre => Length (New_Item) <= Max_Length - Length (Source),
          Post => To_Wide_String (Source) = To_Wide_String (Source)'Old & To_Wide_String (New_Item);

   procedure Append (Source : in out Bounded_Wide_String; New_Item : Wide_String)
     with Global => null,
          Pre => New_Item'Length <= Max_Length - Length (Source),
          Post => To_Wide_String (Source) = To_Wide_String (Source)'Old & New_Item;

   procedure Append (Source : in out Bounded_Wide_String; New_Item : Wide_Character)
     with Global => null,
          Pre => Length (Source) < Max_Length,
          Post => To_Wide_String (Source) = To_Wide_String (Source)'Old & New_Item;

   function "&" (Left, Right : Bounded_Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Length (Right) <= Max_Length - Length (Left),
          Post => To_Wide_String ("&"'Result) = To_Wide_String (Left) & To_Wide_String (Right);

   function "&" (Left : Bounded_Wide_String; Right : Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Right'Length <= Max_Length - Length (Left),
          Post => To_Wide_String ("&"'Result) = To_Wide_String (Left) & Right;

   function "&" (Left : Wide_String; Right : Bounded_Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Left'Length <= Max_Length - Length (Right),
          Post => To_Wide_String ("&"'Result) = Wide_Fixed.Joined (Left, To_Wide_String (Right), "");

   function "&" (Left : Bounded_Wide_String; Right : Wide_Character) return Bounded_Wide_String
     with Global => null,
          Pre => Length (Left) < Max_Length,
          Post => To_Wide_String ("&"'Result) = To_Wide_String (Left) & Right;

   function "&" (Left : Wide_Character; Right : Bounded_Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Length (Right) < Max_Length,
          Post => To_Wide_String ("&"'Result) = Left & To_Wide_String (Right);

   function Element (Source : Bounded_Wide_String; Index : Positive) return Wide_Character
     with Global => null,
          Pre => Index <= Length (Source),
          Post => Element'Result = To_Wide_String (Source) (Index);

   procedure Replace_Element (Source : in out Bounded_Wide_String; Index : Positive; By : Wide_Character)
     with Global => null,
          Pre => Index <= Length (Source),
          Post => To_Wide_String (Source) = Wide_Fixed.Overwrite (To_Wide_String (Source)'Old, Index, (1 => By));

   --  the characters at Low .. High, with those bounds
   function Slice (Source : Bounded_Wide_String; Low : Positive; High : Natural) return Wide_String
     with Global => null,
          Pre => Low <= Length (Source) + 1 and then High <= Length (Source),
          Post => Slice'Result = To_Wide_String (Source) (Low .. High);

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

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

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

   function "=" (Left : Bounded_Wide_String; Right : Wide_String) return Boolean
     with Global => null,
          Post => "="'Result = (To_Wide_String (Left) = Right);

   function "=" (Left : Wide_String; Right : Bounded_Wide_String) return Boolean
     with Global => null,
          Post => "="'Result = (Left = To_Wide_String (Right));

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

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

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

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

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

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

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

   function ">" (Left : Bounded_Wide_String; Right : Wide_String) return Boolean
     with Global => null,
          Post => ">"'Result = (To_Wide_String (Left) > Right);

   function ">" (Left : Wide_String; Right : Bounded_Wide_String) return Boolean
     with Global => null,
          Post => ">"'Result = (Left > To_Wide_String (Right));

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

   function ">=" (Left : Bounded_Wide_String; Right : Wide_String) return Boolean
     with Global => null,
          Post => ">="'Result = (To_Wide_String (Left) >= Right);

   function ">=" (Left : Wide_String; Right : Bounded_Wide_String) return Boolean
     with Global => null,
          Post => ">="'Result = (Left >= To_Wide_String (Right));

   function Index (Source : Bounded_Wide_String; Pattern : Wide_String; From : Positive; Going : Direction := Forward;
                   Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity) return Natural
     with Global => null,
          Pre => Pattern'Length > 0 and then From <= Length (Source),
          Post => Index'Result = Wide_Fixed.Index (To_Wide_String (Source), Pattern, From, Going, Mapping);

   function Index (Source : Bounded_Wide_String; Pattern : Wide_String; From : Positive; Going : Direction := Forward;
                   Mapping : Wide_Maps.Wide_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;

   function Index (Source : Bounded_Wide_String; Pattern : Wide_String; Going : Direction := Forward;
                   Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity) return Natural
     with Global => null,
          Pre => Pattern'Length > 0,
          Post => Index'Result = Wide_Fixed.Index (To_Wide_String (Source), Pattern, Going, Mapping);

   function Index (Source : Bounded_Wide_String; Pattern : Wide_String; Going : Direction := Forward;
                   Mapping : Wide_Maps.Wide_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;

   function Index (Source : Bounded_Wide_String; Set : Wide_Maps.Wide_Character_Set; From : Positive; Test : Membership := Inside;
                   Going : Direction := Forward) return Natural
     with Global => null,
          Pre => From <= Length (Source),
          Post => Index'Result = Wide_Fixed.Index (To_Wide_String (Source), Set, From, Test, Going);

   function Index (Source : Bounded_Wide_String; Set : Wide_Maps.Wide_Character_Set; Test : Membership := Inside; Going : Direction := Forward) return Natural
     with Global => null,
          Post => Index'Result = Wide_Fixed.Index (To_Wide_String (Source), Set, Test, Going);

   function Index_Non_Blank (Source : Bounded_Wide_String; From : Positive; Going : Direction := Forward) return Natural
     with Global => null,
          Pre => From <= Length (Source),
          Post => Index_Non_Blank'Result = Wide_Fixed.Index_Non_Blank (To_Wide_String (Source), From, Going);

   function Index_Non_Blank (Source : Bounded_Wide_String; Going : Direction := Forward) return Natural
     with Global => null,
          Post => Index_Non_Blank'Result = Wide_Fixed.Index_Non_Blank (To_Wide_String (Source), Going);

   function Count (Source : Bounded_Wide_String; Pattern : Wide_String; Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity) return Natural
     with Global => null,
          Pre => Pattern'Length > 0,
          Post => Count'Result = Wide_Fixed.Count (To_Wide_String (Source), Pattern, Mapping);

   function Count (Source : Bounded_Wide_String; Pattern : Wide_String; Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural
     with Global => null,
          Pre => Pattern'Length > 0 and then Mapping /= null,
          Post => Count'Result <= Length (Source);

   function Count (Source : Bounded_Wide_String; Set : Wide_Maps.Wide_Character_Set) return Natural
     with Global => null,
          Post => Count'Result = Wide_Fixed.Count (To_Wide_String (Source), Set);

   procedure Find_Token (Source : Bounded_Wide_String; Set : Wide_Maps.Wide_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) => Wide_Maps.Is_In (To_Wide_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 => Wide_Maps.Is_In (To_Wide_String (Source) (I), Set) /= (Test = Inside))
                        and then (for all I in First .. Last => Wide_Maps.Is_In (To_Wide_String (Source) (I), Set) = (Test = Inside))
                        and then (Last = Length (Source) or else Wide_Maps.Is_In (To_Wide_String (Source) (Last + 1), Set) /= (Test = Inside)));

   procedure Find_Token (Source : Bounded_Wide_String; Set : Wide_Maps.Wide_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) => Wide_Maps.Is_In (To_Wide_String (Source) (I), Set) /= (Test = Inside))
                   else First <= Last and then Last <= Length (Source)
                        and then (for all I in 1 .. First - 1 => Wide_Maps.Is_In (To_Wide_String (Source) (I), Set) /= (Test = Inside))
                        and then (for all I in First .. Last => Wide_Maps.Is_In (To_Wide_String (Source) (I), Set) = (Test = Inside))
                        and then (Last = Length (Source) or else Wide_Maps.Is_In (To_Wide_String (Source) (Last + 1), Set) /= (Test = Inside)));

   function Translate (Source : Bounded_Wide_String; Mapping : Wide_Maps.Wide_Character_Mapping) return Bounded_Wide_String
     with Global => null,
          Post => To_Wide_String (Translate'Result) = Wide_Fixed.Translate (To_Wide_String (Source), Mapping);

   procedure Translate (Source : in out Bounded_Wide_String; Mapping : Wide_Maps.Wide_Character_Mapping)
     with Global => null,
          Post => To_Wide_String (Source) = Wide_Fixed.Translate (To_Wide_String (Source)'Old, Mapping);

   function Translate (Source : Bounded_Wide_String; Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Bounded_Wide_String
     with Global => null,
          Pre => Mapping /= null,
          Post => Length (Translate'Result) = Length (Source);

   procedure Translate (Source : in out Bounded_Wide_String; Mapping : Wide_Maps.Wide_Character_Mapping_Function)
     with Global => null,
          Pre => Mapping /= null,
          Post => Length (Source) = Length (Source)'Old;

   function Replace_Slice (Source : Bounded_Wide_String; Low : Positive; High : Natural; By : Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Low <= Length (Source) + 1
                 and then Wide_Fixed.Replace_Slice (To_Wide_String (Source), Low, High, By)'Length <= Max_Length,
          Post => To_Wide_String (Replace_Slice'Result) = Wide_Fixed.Replace_Slice (To_Wide_String (Source), Low, High, By);

   procedure Replace_Slice (Source : in out Bounded_Wide_String; Low : Positive; High : Natural; By : Wide_String)
     with Global => null,
          Pre => Low <= Length (Source) + 1
                 and then Wide_Fixed.Replace_Slice (To_Wide_String (Source), Low, High, By)'Length <= Max_Length,
          Post => To_Wide_String (Source) = Wide_Fixed.Replace_Slice (To_Wide_String (Source)'Old, Low, High, By);

   function Insert (Source : Bounded_Wide_String; Before : Positive; New_Item : Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Before <= Length (Source) + 1 and then New_Item'Length <= Max_Length - Length (Source),
          Post => To_Wide_String (Insert'Result) = Wide_Fixed.Insert (To_Wide_String (Source), Before, New_Item);

   procedure Insert (Source : in out Bounded_Wide_String; Before : Positive; New_Item : Wide_String)
     with Global => null,
          Pre => Before <= Length (Source) + 1 and then New_Item'Length <= Max_Length - Length (Source),
          Post => To_Wide_String (Source) = Wide_Fixed.Insert (To_Wide_String (Source)'Old, Before, New_Item);

   function Overwrite (Source : Bounded_Wide_String; Position : Positive; New_Item : Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Position <= Length (Source) + 1 and then New_Item'Length <= Max_Length - (Position - 1),
          Post => To_Wide_String (Overwrite'Result) = Wide_Fixed.Overwrite (To_Wide_String (Source), Position, New_Item);

   procedure Overwrite (Source : in out Bounded_Wide_String; Position : Positive; New_Item : Wide_String)
     with Global => null,
          Pre => Position <= Length (Source) + 1 and then New_Item'Length <= Max_Length - (Position - 1),
          Post => To_Wide_String (Source) = Wide_Fixed.Overwrite (To_Wide_String (Source)'Old, Position, New_Item);

   function Delete (Source : Bounded_Wide_String; From : Positive; Through : Natural) return Bounded_Wide_String
     with Global => null,
          Pre => Through < From or else From <= Length (Source) + 1,
          Post => To_Wide_String (Delete'Result) = Wide_Fixed.Delete (To_Wide_String (Source), From, Through);

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

   function Trim (Source : Bounded_Wide_String; Side : Trim_End) return Bounded_Wide_String
     with Global => null,
          Post => To_Wide_String (Trim'Result) = Wide_Fixed.Trim (To_Wide_String (Source), Side);

   procedure Trim (Source : in out Bounded_Wide_String; Side : Trim_End)
     with Global => null,
          Post => To_Wide_String (Source) = Wide_Fixed.Trim (To_Wide_String (Source)'Old, Side);

   function Trim (Source : Bounded_Wide_String; Left, Right : Wide_Maps.Wide_Character_Set) return Bounded_Wide_String
     with Global => null,
          Post => To_Wide_String (Trim'Result) = Wide_Fixed.Trim (To_Wide_String (Source), Left, Right);

   procedure Trim (Source : in out Bounded_Wide_String; Left, Right : Wide_Maps.Wide_Character_Set)
     with Global => null,
          Post => To_Wide_String (Source) = Wide_Fixed.Trim (To_Wide_String (Source)'Old, Left, Right);

   function Head (Source : Bounded_Wide_String; Count : Natural; Pad : Wide_Character := Wide_Space) return Bounded_Wide_String
     with Global => null,
          Pre => Count <= Max_Length,
          Post => To_Wide_String (Head'Result) = Wide_Fixed.Head (To_Wide_String (Source), Count, Pad);

   procedure Head (Source : in out Bounded_Wide_String; Count : Natural; Pad : Wide_Character := Wide_Space)
     with Global => null,
          Pre => Count <= Max_Length,
          Post => To_Wide_String (Source) = Wide_Fixed.Head (To_Wide_String (Source)'Old, Count, Pad);

   function Tail (Source : Bounded_Wide_String; Count : Natural; Pad : Wide_Character := Wide_Space) return Bounded_Wide_String
     with Global => null,
          Pre => Count <= Max_Length,
          Post => To_Wide_String (Tail'Result) = Wide_Fixed.Tail (To_Wide_String (Source), Count, Pad);

   procedure Tail (Source : in out Bounded_Wide_String; Count : Natural; Pad : Wide_Character := Wide_Space)
     with Global => null,
          Pre => Count <= Max_Length,
          Post => To_Wide_String (Source) = Wide_Fixed.Tail (To_Wide_String (Source)'Old, Count, Pad);

   function "*" (Left : Natural; Right : Wide_Character) return Bounded_Wide_String
     with Global => null,
          Pre => Left <= Max_Length,
          Post => To_Wide_String ("*"'Result) = Wide_Fixed."*" (Left, Right);

   function "*" (Left : Natural; Right : Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Long_Long_Long_Integer (Left) * Long_Long_Long_Integer (Right'Length) <= Long_Long_Long_Integer (Max_Length),
          Post => To_Wide_String ("*"'Result) = Wide_Fixed."*" (Left, Right);

   function "*" (Left : Natural; Right : Bounded_Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Long_Long_Long_Integer (Left) * Long_Long_Long_Integer (Length (Right)) <= Long_Long_Long_Integer (Max_Length),
          Post => To_Wide_String ("*"'Result) = Wide_Fixed."*" (Left, To_Wide_String (Right));

   function Replicate (Count : Natural; Item : Wide_Character) return Bounded_Wide_String
     with Global => null,
          Pre => Count <= Max_Length,
          Post => To_Wide_String (Replicate'Result) = Wide_Fixed."*" (Count, Item);

   function Replicate (Count : Natural; Item : Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Long_Long_Long_Integer (Count) * Long_Long_Long_Integer (Item'Length) <= Long_Long_Long_Integer (Max_Length),
          Post => To_Wide_String (Replicate'Result) = Wide_Fixed."*" (Count, Item);

   function Replicate (Count : Natural; Item : Bounded_Wide_String) return Bounded_Wide_String
     with Global => null,
          Pre => Long_Long_Long_Integer (Count) * Long_Long_Long_Integer (Length (Item)) <= Long_Long_Long_Integer (Max_Length),
          Post => To_Wide_String (Replicate'Result) = Wide_Fixed."*" (Count, To_Wide_String (Item));
private
   type Bounded_Wide_String is record
      Length : Length_Range := 0;
      Data : Wide_String (1 .. Max_Length) := (others => Wide_Space);
   end record;

   function Length (Source : Bounded_Wide_String) return Length_Range is (Source.Length);

   function To_Wide_String (Source : Bounded_Wide_String) return Wide_String is (Source.Data (1 .. Source.Length));
end Generic_Bounded_Length;