with Text_Io;
use Text_Io;
package Dyn is

    -----------------------------------------------------------------
    -- This is a package of several string manipulation functions
    -- based on a built-in dynamic string type DYN_STRING.  It is
    -- an adaptation and extension of the package proposed by
    -- Sylvan Rubin of Ford Aerospace and Communications
    -- Corporation in the Nov/Dec 1984 issue of the Journal of
    -- Pascal, Ada and Modula-2.  Some new functions have been
    -- added, the SUBSTRING function has been modified to permit
    -- it to return the right part of a string if the third parameter
    -- is permitted to default, and much of the body code has
    -- been rewritten.
    ------------------------------------------------------------------
    -- R.G. Cleaveland 07 December 1984:
    -- Implementation initially with the Telesoft Ada version
    -- This required definition of the DYN_STRING type without use of
    -- a discriminant; an arbitrary maximum string length was chosen.
    -- This should be changed when an improved compiler is available.
    ------------------------------------------------------------------
    -- Richard Powers 03 January 1985:
    -- changed to be used with a real compiler.
    -- Some of the routines removed by my whim.
    ------------------------------------------------------------------
    -- Richard Powers 26 January 1985:
    -- Added UPPER_CASE function
    ------------------------------------------------------------------

    type Dyn_String is private;

    String_Too_Short : exception;

    function D_String (Char : Character) return Dyn_String;
    -- Creates a one-byte dynamic string of contents CHAR.

    function D_String (Str : String) return Dyn_String;
    -- Creates a dynamic string of contents STR.

    -- The following four functions convert from
    -- dynamic strings to the desired representation:
    function Char (Dstr : Dyn_String) return Character;
    function Str (Dstr : Dyn_String) return String;
    function Int (Dstr : Dyn_String) return Integer;
    function Flt (Dstr : Dyn_String) return Float;

    function Length (Dstr : Dyn_String) return Natural;
    function "<" (Ds1, Ds2 : Dyn_String) return Boolean;
    function "&" (Ds1, Ds2 : Dyn_String) return Dyn_String;

    function Substring
                (Dstr : Dyn_String;         -- Returns a subpart of this string
                 Start : Natural;         -- starting at this position
                 Length : Natural := 0) -- and of this length.
                return Dyn_String;
    -- if LENGTH is zero or not specified, the remainder of the
    -- string is returned (eg the "RIGHT" function).

    function Index
                (Source_String,                 --If this string contains
                 Pattern_String :
                    Dyn_String;    --this string starting at or AFTER
                 Start_Pos : Integer)         --this position, the position of
                return Integer;             --such start is returned.
    -- If the string lengths prohibit the search -1 is returned.
    -- If no match was found, 0 is returned.
    -- (This is like the INSTR function of BASIC).

    function Rindex
                (Source_String,                --If this string contains
                 Pattern_String :
                    Dyn_String;    --this string starting at or BEFORE
                 Start_Pos : Integer)         --this position, the position of
                return Integer;             --such start is returned.
    -- If the string lengths prohibit the search -1 is returned.
    -- If no match was found, 0 is returned.

    function Upper_Case (Strg : in Dyn.Dyn_String) return String;
    -- Return the input string in upper case

private

    type String_Contents (Size : Natural := 0) is
        record
            Data : String (1 .. Size);
        end record;

    type Dyn_String is access String_Contents;

end Dyn;

-----------------------------------------------------------------