Package: Util.Text

Dependencies

with Ada.Finalization;
with Ada.Streams;

with Ada.Strings.Maps;
with Ada.Strings.Unbounded;

Description

Copyright © 2001, 2002 by Thomas Wolf.
This piece of software is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This software is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License with this distribution, see file "GPL.txt". If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception from the GPL, if other files instantiate generics from this unit, or you link this unit with other files to produce an executable, this unit does not by itself cause the resulting executable to be covered by the GPL. This exception does not however invalidate any other reasons why the executable file might be covered by the GPL.

Version: 1.1

Author:
Thomas Wolf (TW) <twolf AT acm DOT org>
Purpose:
A complete replacement for Ada.Strings.Unbounded, with conversion routines. The problem with the standard unbounded strings package is that it lacks certain operations (such as I/O operations, or a way to append a slice of an Unbounded_String to another Unbounded_String without having an intermediary conversion to String).

This implementation is fully portable; it doesn't use any GNAT-specific pragmas like Stream_Convert. The price to pay is that this package cannot be preelaborated (since Null_Unbounded_String is a constant of a controlled type). I wonder how the language designers did envision that this be done...

Unbounded_Strings are streamable; however, the format is not compatible with the one used by GNAT's implementation of Ada.Strings.Unbounded.

The rules for new operations are as follows:

If there is a function that returns a String from an Unbounded_String, a new one returning an Unbounded_String is added (Slice).

For functions returning an Unbounded_String, add a procedural variant that has an "in out" parameter (To_Unbounded_String, Slice).

If there is a procedure that has a second parameter of type String, new ones using Unbounded_String or even a slice of an Unbounded_String are added (Append, Insert, Overwrite, Replace_Slice).

Add Operations on slices of unbounded strings where appropriate (Transform).

Operations involving character mappings cause new operations hard-wired not to use any mapping to be added. For such operations, no variants with a second parameter of type Unbounded_String is added, for that second parameter might be large anyway, and it is in such cases better to explicitly use Transform and then one of the "no mapping" operations.

As a result, this interface should allow efficient use of Unbounded_String without having to convert to and from standard String all the time.

The implementation takes into account that any Unbounded_String may be large. If necessary, it therefore re-implements algorithms rather than just call the corresponding operation from package Ada.Strings.Fixed to avoid unnecessary extra copies of the string data.

Tasking Semantics
Neither task- nor abortion-safe.
Storage Semantics
Dynamic storage allocation in the default pool.

Header

package Util.Text is
 
pragma Elaborate_Body;

Known child units

Util.Text.Internal(package)
Util.Text.IO(package)
Util.Text.Streams(package)

Type Summary

String_Access
Unbounded_String
Primitive Operations:  "&", "&", "&", "&", "&", "*", "*", "*", "<", "<", "<", "<=", "<=", "<=", "=", "=", "=", ">", ">", ">", ">=", ">=", ">=", Append, Append, Append, Append, Append, Count, Count, Count, Count, Count, Delete, Delete, Element, Find, Find, Find, Find, Find, Find, Find_Token, Find_Token, Find_Token, First_Index, First_Index, First_Index, First_Index, First_Index, First_Index, From_Standard, From_Standard, From_String, Head, Head, Index, Index, Index, Index, Index, Index, Index, Index, Index, Index, Index_Non_Blank, Index_Non_Blank, Insert, Insert, Insert, Insert, Insert, Insert, Is_Prefix, Is_Prefix, Is_Suffix, Is_Suffix, Last_Index, Last_Index, Last_Index, Last_Index, Last_Index, Last_Index, Length, Occurrences, Occurrences, Overwrite, Overwrite, Overwrite, Overwrite, Overwrite, Overwrite, Replace, Replace, Replace_Element, Replace_Slice, Replace_Slice, Replace_Slice, Replace_Slice, Replace_Slice, Replace_Slice, Set, Slice, Slice, Slice, Tail, Tail, To_Standard, To_Standard, To_String, To_Unbounded_String, To_Unbounded_String, To_Unbounded_String, Translate, Translate, Translate, Translate, Translate, Translate, Translate, Translate, Trim, Trim, Trim, Trim

Constants and Named Numbers

Null_Unbounded_String : constant Unbounded_String;
Represents a null Unbounded_String, i.e. To_String (Null_Unbounded_String) = "".

Other Items:

type Unbounded_String is private;

function To_Standard
  (S : in Unbounded_String)
  return Ada.Strings.Unbounded.Unbounded_String;
Convert a Util.Text.Unbounded_String to a standard Unbounded_String.

Warning: Needs an intermediary copy of the string data.


function From_Standard
  (S : in Ada.Strings.Unbounded.Unbounded_String)
  return Unbounded_String;
Convert a standard Unbounded_String to a Util.Text.Unbounded_String.

Warning: Needs an intermediary copy of the string data.


procedure To_Standard
  (Source : in     Unbounded_String;
   Target :    out Ada.Strings.Unbounded.Unbounded_String);
Equivalent to Target := To_Standard (Source).

procedure From_Standard
  (Source : in     Ada.Strings.Unbounded.Unbounded_String;
   Target :    out Unbounded_String);
Equivalent to Target := From_Standard (Source).

function To_String
  (S : in Unbounded_String)
  return String;
Returns the string data of S as a standard fixed string.

function From_String
  (S : in String)
  return Unbounded_String;
Returns an Unbounded_String containing the contents of S.

function To_Unbounded_String
  (S : in String)
  return Unbounded_String
  renames From_String;
A renaming for convenience.

function To_Unbounded_String
  (Length : in Natural)
  return Unbounded_String;
Returns an Unbounded_String of the given Length whose content is uninitialized.

function Length
  (Source : in Unbounded_String)
  return Natural;
Returns the length of Source's string data.

procedure Append
  (Source   : in out Unbounded_String;
   New_Item : in     Unbounded_String);
Equivalent to Source := Source & New_Item.

procedure Append
  (Source   : in out Unbounded_String;
   New_Item : in     String);
Equivalent to Source := Source & New_Item.

procedure Append
  (Source   : in out Unbounded_String;
   New_Item : in     Character);
Equivalent to Source := Source & New_Item.

function "&"
  (Left, Right : Unbounded_String)
  return Unbounded_String;
Concatenates Left and Right and returns the resulting Unbounded_String.

function "&"
  (Left  : in Unbounded_String;
   Right : in String)
  return Unbounded_String;
Concatenates Left and Right and returns the resulting Unbounded_String.

function "&"
  (Left  : in String;
   Right : in Unbounded_String)
  return Unbounded_String;
Concatenates Left and Right and returns the resulting Unbounded_String.

function "&"
  (Left  : in Unbounded_String;
   Right : in Character)
  return Unbounded_String;
Concatenates Left and Right and returns the resulting Unbounded_String.

function "&"
  (Left  : in Character;
   Right : in Unbounded_String)
  return Unbounded_String;
Concatenates Left and Right and returns the resulting Unbounded_String.

function Element
  (Source : in Unbounded_String;
   Index  : in Positive)
  return Character;
Equivalent to To_String (Source) (Index). Raises Ada.Strings.Index_Error if Index > Length (Source).

procedure Replace_Element
  (Source : in out Unbounded_String;
   Index  : in     Positive;
   By     : in     Character);
Equivalent to To_String (Source) (Index). Raises Ada.Strings.Index_Error if Index > Length (Source).

function Slice
  (Source : in Unbounded_String;
   Low    : in Positive;
   High   : in Natural)
  return String;
Equivalent to To_String (Source) (Low .. High). Raises Ada.Strings.Index_Error if High > Length (Source).

function "="
  (Left, Right : in Unbounded_String)
  return Boolean;
Equivalent to To_String (Left) = To_String (Right).

function "="
  (Left  : in Unbounded_String;
   Right : in String)
  return Boolean;
Equivalent to To_String (Left) = Right.

function "="
  (Left  : in String;
   Right : in Unbounded_String)
  return Boolean;
Equivalent to Left = To_String (Right).

function "<"
  (Left, Right : in Unbounded_String)
  return Boolean;
Equivalent to To_String (Left) < To_String (Right).

function "<"
  (Left  : in Unbounded_String;
   Right : in String)
  return  Boolean;
Equivalent to To_String (Left) < Right.

function "<"
  (Left  : in String;
   Right : in Unbounded_String)
  return  Boolean;
Equivalent to Left < To_String (Right).

function "<="
  (Left, Right : in Unbounded_String)
  return Boolean;
Equivalent to To_String (Left) <= To_String (Right).

function "<="
  (Left  : in Unbounded_String;
   Right : in String)
  return Boolean;
Equivalent to To_String (Left) <= Right.

function "<="
  (Left  : in String;
   Right : in Unbounded_String)
  return Boolean;
Equivalent to Left <= To_String (Right).

function ">"
  (Left, Right : in Unbounded_String)
  return Boolean;
Equivalent to To_String (Left) > To_String (Right).

function ">"
  (Left  : in Unbounded_String;
   Right : in String)
  return Boolean;
Equivalent to To_String (Left) > Right.

function ">"
  (Left  : in String;
   Right : in Unbounded_String)
  return Boolean;
Equivalent to Left > To_String (Right).

function ">="
  (Left, Right : in Unbounded_String)
  return Boolean;
Equivalent to To_String (Left) >= To_String (Right).

function ">="
  (Left  : in Unbounded_String;
   Right : in String)
  return Boolean;
Equivalent to To_String (Left) >= Right.

function ">="
  (Left  : in String;
   Right : in Unbounded_String)
  return Boolean;
Equivalent to Left >= To_String (Right).

function Index
  (Source  : in Unbounded_String;
   Pattern : in String;
   Going   : in Ada.Strings.Direction              := Ada.Strings.Forward;
   Mapping : in Ada.Strings.Maps.Character_Mapping :=
                  Ada.Strings.Maps.Identity)
  return Natural;
Equivalent to Ada.Strings.Unbounded.Index (To_Standard (Source), Pattern, Going, Mapping);

function Index
  (Source  : in Unbounded_String;
   Pattern : in String;
   Going   : in Ada.Strings.Direction := Ada.Strings.Forward;
   Mapping : in Ada.Strings.Maps.Character_Mapping_Function)
  return Natural;
Equivalent to Ada.Strings.Unbounded.Index (To_Standard (Source), Pattern, Going, Mapping);

function Index
  (Source : in Unbounded_String;
   Set    : in Ada.Strings.Maps.Character_Set;
   Test   : in Ada.Strings.Membership := Ada.Strings.Inside;
   Going  : in Ada.Strings.Direction  := Ada.Strings.Forward)
  return Natural;
Equivalent to Ada.Strings.Unbounded.Index (To_Standard (Source), Set, Test, Going);

function Index_Non_Blank
  (Source : in Unbounded_String;
   Going  : in Ada.Strings.Direction := Ada.Strings.Forward)
  return Natural;
Equivalent to Ada.Strings.Unbounded.Index_Non_Blank (To_Standard (Source), Going);

function Count
  (Source  : in Unbounded_String;
   Pattern : in String;
   Mapping : in Ada.Strings.Maps.Character_Mapping :=
                  Ada.Strings.Maps.Identity)
  return Natural;
Equivalent to Ada.Strings.Unbounded.Count (To_Standard (Source), Pattern, Mapping);

function Count
  (Source   : in Unbounded_String;
   Pattern  : in String;
   Mapping  : in Ada.Strings.Maps.Character_Mapping_Function)
  return Natural;
Equivalent to Ada.Strings.Unbounded.Count (To_Standard (Source), Pattern, Mapping);

function Count
  (Source : in Unbounded_String;
   Set    : in Ada.Strings.Maps.Character_Set)
  return Natural;
Equivalent to Ada.Strings.Unbounded.Count (To_Standard (Source), Set);

procedure Find_Token
  (Source : in     Unbounded_String;
   Set    : in     Ada.Strings.Maps.Character_Set;
   Test   : in     Ada.Strings.Membership;
   First  :    out Positive;
   Last   :    out Natural);
Equivalent to Ada.Strings.Unbounded.Find_Token (To_Standard (Source), Set, Test, First, Last);

function Translate
  (Source  : in Unbounded_String;
   Mapping : in Ada.Strings.Maps.Character_Mapping)
  return Unbounded_String;
Equivalent to From_Standard (Ada.Strings.Unbounded.Translate (To_Standard (Source), Mapping));

procedure Translate
  (Source  : in out Unbounded_String;
   Mapping : in     Ada.Strings.Maps.Character_Mapping);
Equivalent to Source := Translate (Source, Mapping);

function Translate
  (Source  : in Unbounded_String;
   From    : in Positive;
   Through : in Natural;
   Mapping : in Ada.Strings.Maps.Character_Mapping)
  return Unbounded_String;
Equivalent to Translate (Slice (Source, From, Through), Mapping);

procedure Translate
  (Source  : in out Unbounded_String;
   From    : in     Positive;
   Through : in     Natural;
   Mapping : in     Ada.Strings.Maps.Character_Mapping);
Equivalent to Translate (Slice (Source, From, Through), Mapping);

function Translate
  (Source  : in Unbounded_String;
   Mapping : in Ada.Strings.Maps.Character_Mapping_Function)
  return Unbounded_String;
Equivalent to From_Standard (Ada.Strings.Unbounded.Translate (To_Standard (Source), Mapping));

procedure Translate
  (Source  : in out Unbounded_String;
   Mapping : in     Ada.Strings.Maps.Character_Mapping_Function);
Equivalent to Source := Translate (Source, Mapping);

function Translate
  (Source  : in Unbounded_String;
   From    : in Positive;
   Through : in Natural;
   Mapping : in Ada.Strings.Maps.Character_Mapping_Function)
  return Unbounded_String;
Equivalent to Translate (Slice (Source, From, Through), Mapping);

procedure Translate
  (Source  : in out Unbounded_String;
   From    : in     Positive;
   Through : in     Natural;
   Mapping : in     Ada.Strings.Maps.Character_Mapping_Function);
Equivalent to Translate (Slice (Source, From, Through), Mapping);

function Replace_Slice
  (Source : in Unbounded_String;
   Low    : in Positive;
   High   : in Natural;
   By     : in String)
  return Unbounded_String;
Equivalent to From_Standard (Ada.Strings.Unbounded.Replace_Slice (To_Standard (Source), Low, High, By);

procedure Replace_Slice
  (Source : in out Unbounded_String;
   Low    : in     Positive;
   High   : in     Natural;
   By     : in     String);
Equivalent to Source := Replace_Slice (Source, Low, High, By);

function Insert
  (Source   : in Unbounded_String;
   Before   : in Positive;
   New_Item : in String)
  return Unbounded_String;
Equivalent to From_Standard (Ada.Strings.Unbounded.Insert (To_Standard (Source), Before, New_Item);

procedure Insert
  (Source   : in out Unbounded_String;
   Before   : in     Positive;
   New_Item : in     String);
Equivalent to Source := Insert (Source, Before, New_Item);

function Overwrite
  (Source   : in Unbounded_String;
   Position : in Positive;
   New_Item : in String)
  return Unbounded_String;
Equivalent to From_Standard (Ada.Strings.Unbounded.Overwrite (To_Standard (Source), Position, New_Item);

procedure Overwrite
  (Source   : in out Unbounded_String;
   Position : in     Positive;
   New_Item : in     String);
Equivalent to Source := Overwrite (Source, Position, New_Item);

function Delete
  (Source  : in Unbounded_String;
   From    : in Positive;
   Through : in Natural)
  return Unbounded_String;
Equivalent to From_Standard (Ada.Strings.Unbounded.Delete (To_Standard (Source), From, Through);

procedure Delete
  (Source  : in out Unbounded_String;
   From    : in     Positive;
   Through : in     Natural);
Equivalent to Source := Delete (Source, From, Through);

function Trim
  (Source : in Unbounded_String;
   Side   : in Ada.Strings.Trim_End)
  return Unbounded_String;
Equivalent to From_Standard (Ada.Strings.Unbounded.Trim (To_Standard (Source), Side);

procedure Trim
  (Source : in out Unbounded_String;
   Side   : in     Ada.Strings.Trim_End);
Equivalent to Source := Trim (Source, Side);

function Trim
  (Source : in Unbounded_String;
   Left   : in Ada.Strings.Maps.Character_Set;
   Right  : in Ada.Strings.Maps.Character_Set)
  return Unbounded_String;
Equivalent to From_Standard (Ada.Strings.Unbounded.Trim (To_Standard (Source), Left, Right);

procedure Trim
  (Source : in out Unbounded_String;
   Left   : in     Ada.Strings.Maps.Character_Set;
   Right  : in     Ada.Strings.Maps.Character_Set);
Equivalent to Source := Trim (Source, Left, Right);

function Head
  (Source : in Unbounded_String;
   Count  : in Natural;
   Pad    : in Character := Ada.Strings.Space)
  return Unbounded_String;
Equivalent to From_Standard (Ada.Strings.Unbounded.Head (To_Standard (Source), Count, Pad);

procedure Head
  (Source : in out Unbounded_String;
   Count  : in     Natural;
   Pad    : in     Character := Ada.Strings.Space);
Equivalent to Source := Head (Source, Count, Pad);

function Tail
  (Source : in Unbounded_String;
   Count  : in Natural;
   Pad    : in Character := Ada.Strings.Space)
  return Unbounded_String;
Equivalent to From_Standard (Ada.Strings.Unbounded.Tail (To_Standard (Source), Count, Pad);

procedure Tail
  (Source : in out Unbounded_String;
   Count  : in     Natural;
   Pad    : in     Character := Ada.Strings.Space);
Equivalent to Source := Tail (Source, Count, Pad);

function "*"
  (Left  : in Natural;
   Right : in Character)
  return Unbounded_String;
Returns an Unbounded_String of length Left with all characters set to Right.

function "*"
  (Left  : in Natural;
   Right : in String)
  return Unbounded_String;
Returns an Unbounded_String whose content is obtained by concatenating Right Left times.

function "*"
  (Left  : in Natural;
   Right : in Unbounded_String)
  return Unbounded_String;
Returns an Unbounded_String whose content is obtained by concatenating Right's string data Left times.

procedure Set
  (Target : in out Unbounded_String;
   Str    : in     String);
Equivalent to Target := To_Unbounded_String (Str);. However, Set may be more efficient than To_Unbounded_String because Target is passed by reference, and we thus can save some finalizations.

procedure To_Unbounded_String
  (Target : in out Unbounded_String;
   Str    : in     String)
  renames Set;

function Slice
  (Source : in Unbounded_String;
   Low    : in Positive;
   High   : in Natural)
  return Unbounded_String;
Equivalent to To_Unbounded_String (To_String (Source) (Low .. High)). Raises Ada.Strings.Index_Error if High > Length (Source).

procedure Slice
  (Target : in out Unbounded_String;
   Source : in     Unbounded_String;
   Low    : in     Positive;
   High   : in     Natural);
Equivalent to Target := Slice (Source, Low, High);.

function Find
  (Source  : in Unbounded_String;
   Pattern : in Character;
   Going   : in Ada.Strings.Direction := Ada.Strings.Forward)
  return Natural;
As Index, but not using any mappings. Equivalent to Index (Source, Pattern, Going);.

function Find
  (Source  : in Unbounded_String;
   Pattern : in String;
   Going   : in Ada.Strings.Direction := Ada.Strings.Forward)
  return Natural;
As Index, but not using any mappings. Equivalent to Index (Source, Pattern, Going);.

function Find
  (Source  : in Unbounded_String;
   Pattern : in Unbounded_String;
   Going   : in Ada.Strings.Direction := Ada.Strings.Forward)
  return Natural;
As Index, but not using any mappings. Equivalent to Index (Source, To_String (Pattern), Going);.

function Find
  (Source  : in Unbounded_String;
   Pattern : in Character;
   From    : in Positive;
   Going   : in Ada.Strings.Direction := Ada.Strings.Forward)
  return Natural;
As Index, but not using any mappings. If Going = Forward, equivalent to

Index (Slice (Source, From, Length (Source)), Pattern),

otherwise equivalent to

Index (Slice (Source, 1, From), Pattern, Backward)


function Find
  (Source  : in Unbounded_String;
   Pattern : in String;
   From    : in Positive;
   Going   : in Ada.Strings.Direction := Ada.Strings.Forward)
  return Natural;
As Index, but not using any mappings. If Going = Forward, equivalent to

Index (Slice (Source, From, Length (Source)), Pattern),

otherwise equivalent to

Index (Slice (Source, 1, From), Pattern, Backward)


function Find
  (Source  : in Unbounded_String;
   Pattern : in Unbounded_String;
   From    : in Positive;
   Going   : in Ada.Strings.Direction := Ada.Strings.Forward)
  return Natural;
Equivalent to Find (Source, To_String (Pattern), From, Going).

function First_Index
  (Source : in Unbounded_String;
   Ch     : in Character)
  return Natural;
Returns the index of the first occurrence of Ch in Source, or zero if Ch doesn't occur in Source.

function First_Index
  (Source : in Unbounded_String;
   Ch     : in Character;
   From   : in Positive)
  return Natural;
Returns the index of the first occurrence of Ch in Slice (Source, From, Length (Source)), or zero if Ch doesn't occur in this slice of Source.

function Last_Index
  (Source : in Unbounded_String;
   Ch     : in Character)
  return Natural;
Returns the index of the last occurrence of Ch in Source, or zero Ch doesn't occur in Source.

function Last_Index
  (Source : in Unbounded_String;
   Ch     : in Character;
   Limit  : in Positive)
  return Natural;
Equivalent to Last_Index (Slice (Source, 1, Limit), Ch).

function First_Index
  (Source  : in Unbounded_String;
   Pattern : in String)
  return Natural;
Equivalent to Ada.String.Fixed.Index (To_String (Source), Pattern);

function First_Index
  (Source  : in Unbounded_String;
   Pattern : in String;
   From    : in Positive)
  return Natural;
Equivalent to Ada.String.Fixed.Index (Slice (Source, From, Length (Source)), Pattern);

function Last_Index
  (Source  : in Unbounded_String;
   Pattern : in String)
  return Natural;
Equivalent to Ada.Strings.Fixed.Index (To_String (Source), Pattern, Backward);

function Last_Index
  (Source  : in Unbounded_String;
   Pattern : in String;
   Limit   : in Positive)
  return Natural;
Equivalent to Last_Index (Slice (Source, 1, Limit), Pattern);

function First_Index
  (Source  : in Unbounded_String;
   Pattern : in Unbounded_String)
  return Natural;
Equivalent to First_Index (Source, To_String (Pattern));

function First_Index
  (Source  : in Unbounded_String;
   Pattern : in Unbounded_String;
   From    : in Positive)
  return Natural;
Equivalent to First_Index (Source, To_String (Pattern), From);

function Last_Index
  (Source  : in Unbounded_String;
   Pattern : in Unbounded_String)
  return Natural;
Equivalent to Last_Index (Source, To_String (Pattern));

function Last_Index
  (Source  : in Unbounded_String;
   Pattern : in Unbounded_String;
   Limit   : in Positive)
  return Natural;
Equivalent to Last_Index (Source, To_String (Pattern), From);

function Index
  (Source  : in Unbounded_String;
   Pattern : in String;
   From    : in Positive;
   Going   : in Ada.Strings.Direction              := Ada.Strings.Forward;
   Mapping : in Ada.Strings.Maps.Character_Mapping :=
                  Ada.Strings.Maps.Identity)
  return Natural;
If Going = Forward, equivalent to

Index (Slice (Source, From, Length (Source), Pattern, Going, Mapping);

otherwise equivalent to

Index (Slice (Source, 1, From), Pattern, Going, Mapping);


function Index
  (Source  : in Unbounded_String;
   Pattern : in String;
   From    : in Positive;
   Going   : in Ada.Strings.Direction := Ada.Strings.Forward;
   Mapping : in Ada.Strings.Maps.Character_Mapping_Function)
  return Natural;
If Going = Forward, equivalent to

Index (Slice (Source, From, Length (Source), Pattern, Going, Mapping);

otherwise equivalent to

Index (Slice (Source, 1, From), Pattern, Going, Mapping);


function Index
  (Source : in Unbounded_String;
   From   : in Positive;
   Set    : in Ada.Strings.Maps.Character_Set;
   Test   : in Ada.Strings.Membership := Ada.Strings.Inside;
   Going  : in Ada.Strings.Direction  := Ada.Strings.Forward)
  return Natural;
If Going = Forward, equivalent to

Index (Slice (Source, From, Length (Source), Set, Test, Going);

otherwise equivalent to

Index (Slice (Source, 1, From), Set, Test, Going);


function Index
  (Source  : in Unbounded_String;
   Pattern : in Unbounded_String;
   Going   : in Ada.Strings.Direction              := Ada.Strings.Forward;
   Mapping : in Ada.Strings.Maps.Character_Mapping :=
                  Ada.Strings.Maps.Identity)
  return Natural;
Equivalent to Index (Source, To_String (Pattern), Going, Mapping);

function Index
  (Source  : in Unbounded_String;
   Pattern : in Unbounded_String;
   Going   : in Ada.Strings.Direction              := Ada.Strings.Forward;
   Mapping : in Ada.Strings.Maps.Character_Mapping_Function)
  return Natural;
Equivalent to Index (Source, To_String (Pattern), Going, Mapping);

function Index
  (Source  : in Unbounded_String;
   Pattern : in Unbounded_String;
   From    : in Positive;
   Going   : in Ada.Strings.Direction              := Ada.Strings.Forward;
   Mapping : in Ada.Strings.Maps.Character_Mapping :=
                  Ada.Strings.Maps.Identity)
  return Natural;
Equivalent to Index (Source, To_String (Pattern), From, Going, Mapping);

function Index
  (Source  : in Unbounded_String;
   Pattern : in Unbounded_String;
   From    : in Positive;
   Going   : in Ada.Strings.Direction              := Ada.Strings.Forward;
   Mapping : in Ada.Strings.Maps.Character_Mapping_Function)
  return Natural;
Equivalent to Index (Source, To_String (Pattern), From, Going, Mapping);

function Index_Non_Blank
  (Source : in Unbounded_String;
   From   : in Positive;
   Going  : in Ada.Strings.Direction := Ada.Strings.Forward)
  return Natural;
If Going = Forward, equivalent to

Index_Non_Blank (Slice (Source, From, Length (Source)), Going);

otherwise equivalent to

Index_Non_Blank (Slice (Source, 1, From), Going);


function Count
  (Source  : in Unbounded_String;
   Pattern : in Unbounded_String;
   Mapping : in Ada.Strings.Maps.Character_Mapping :=
                  Ada.Strings.Maps.Identity)
  return Natural;
Equivalent to Count (Source, To_String (Pattern), Mapping);

function Count
  (Source  : in Unbounded_String;
   Pattern : in Unbounded_String;
   Mapping : in Ada.Strings.Maps.Character_Mapping_Function)
  return Natural;
Equivalent to Count (Source, To_String (Pattern), Mapping);

function Occurrences
  (Source  : in Unbounded_String;
   Pattern : in String)
  return Natural;
Equivalent to Count (Source, Pattern), but hard-wired not to use any mapping.

function  Occurrences
  (Source  : in Unbounded_String;
   Pattern : in Unbounded_String)
  return Natural;
Equivalent to Occurrences (Source, To_String (Pattern));

procedure Find_Token
  (Source : in     Unbounded_String;
   From   : in     Positive;
   Set    : in     Ada.Strings.Maps.Character_Set;
   Test   : in     Ada.Strings.Membership;
   First  :    out Positive;
   Last   :    out Natural);
Equivalent to Find_Token (Slice (Source, From, Length (Source)), Set, Test, First, Last).

procedure Find_Token
  (Source : in     Unbounded_String;
   Low    : in     Positive;
   High   : in     Natural;
   Set    : in     Ada.Strings.Maps.Character_Set;
   Test   : in     Ada.Strings.Membership;
   First  :    out Positive;
   Last   :    out Natural);
Equivalent to Find_Token (Slice (Source, Low, High), Set, Test, First, Last).

function Is_Prefix
  (Source : in Unbounded_String;
   Prefix : in String)
  return Boolean;
Equivalent to Util.Strings.Is_Prefix (To_String (Source), Prefix);

function Is_Prefix
  (Source : in Unbounded_String;
   Prefix : in Unbounded_String)
  return Boolean;
Equivalent to Is_Prefix (Source, To_String (Prefix));.

function Is_Suffix
  (Source : in Unbounded_String;
   Suffix : in String)
  return Boolean;
Equivalent to Util.Strings.Is_Suffix (To_String (Source), Suffix);

function Is_Suffix
  (Source : in Unbounded_String;
   Suffix : in Unbounded_String)
  return Boolean;
Equivalent to Is_Suffix (Source, To_String (Suffix));.

procedure Replace
  (Source : in out Unbounded_String;
   What   : in     String;
   By     : in     String);
Equivalent to Util.Strings.Replace (To_String (Source), What, By);

procedure Replace
  (Source : in out Unbounded_String;
   What   : in     Unbounded_String;
   By     : in     Unbounded_String);
Equivalent to Replace (Source, To_String (What), To_String (By)).

function  Append
  (Source : in Unbounded_String;
   From   : in Unbounded_String;
   Low    : in Positive;
   High   : in Natural)
  return Unbounded_String;
Equivalent to Source & Slice (From, Low, High);

procedure Append
  (Source : in out Unbounded_String;
   From   : in     Unbounded_String;
   Low    : in     Positive;
   High   : in     Natural);
Equivalent to Append (Source, Slice (From, Low, High));

function  Replace_Slice
  (Source : in Unbounded_String;
   Low    : in Positive;
   High   : in Natural;
   By     : in Unbounded_String)
  return Unbounded_String;
Equivalent to Replace_Slice (Source, Low, High, To_String (By));

procedure Replace_Slice
  (Source : in out Unbounded_String;
   Low    : in     Positive;
   High   : in     Natural;
   By     : in     Unbounded_String);
Equivalent to Replace_Slice (Source, Low, High, To_String (By));

function  Replace_Slice
  (Source : in Unbounded_String;
   Low    : in Positive;
   High   : in Natural;
   By     : in Unbounded_String;
   From   : in Positive;
   To     : in Natural)
  return Unbounded_String;
Equivalent to Replace_Slice (Source, Low, High, Slice (By, From, To));

procedure Replace_Slice
  (Source : in out Unbounded_String;
   Low    : in     Positive;
   High   : in     Natural;
   By     : in     Unbounded_String;
   From   : in     Positive;
   To     : in     Natural);
Equivalent to Replace_Slice (Source, Low, High, Slice (By, From, To));

function Insert
  (Source   : in Unbounded_String;
   Before   : in Positive;
   New_Item : in Unbounded_String)
  return Unbounded_String;
Equivalent to Insert (Source, Before, To_String (New_Item));.

procedure Insert
  (Source   : in out Unbounded_String;
   Before   : in     Positive;
   New_Item : in     Unbounded_String);
Equivalent to Insert (Source, Before, To_String (New_Item));.

function Insert
  (Source   : in Unbounded_String;
   Before   : in Positive;
   New_Item : in Unbounded_String;
   Low      : in Positive;
   High     : in Natural)
  return Unbounded_String;
Equivalent to Insert (Source, Before, Slice (New_Item, Low, High));.

procedure Insert
  (Source   : in out Unbounded_String;
   Before   : in     Positive;
   New_Item : in     Unbounded_String;
   Low      : in     Positive;
   High     : in     Natural);
Equivalent to Insert (Source, Before, Slice (New_Item, Low, High));.

function Overwrite
  (Source   : in Unbounded_String;
   Position : in Positive;
   New_Item : in Unbounded_String)
  return Unbounded_String;
Equivalent to Overwrite (Source, Position, To_String (New_Item));.

procedure Overwrite
  (Source   : in out Unbounded_String;
   Position : in     Positive;
   New_Item : in     Unbounded_String);
Equivalent to Overwrite (Source, Position, To_String (New_Item));.

function Overwrite
  (Source   : in Unbounded_String;
   Position : in Positive;
   New_Item : in Unbounded_String;
   Low      : in Positive;
   High     : in Natural)
  return Unbounded_String;
Equivalent to Overwrite (Source, Position, Slice (New_Item, Low, High));.

procedure Overwrite
  (Source   : in out Unbounded_String;
   Position : in     Positive;
   New_Item : in     Unbounded_String;
   Low      : in     Positive;
   High     : in     Natural);
Equivalent to Overwrite (Source, Position, Slice (New_Item, Low, High));.

type String_Access is access all String;

procedure Free
  (Ptr : in out String_Access);

private

   --  Implementation-defined ...
end Util.Text;