
 
(************************************************************************)
(*                                                                      *)
(*       Requires MRI Modula2                                           *)
(*                                                                      *)
(*       Strlib:                                                        *)
(*               Library module to handle strings.  Included is         *)
(*               terminal I/O, string length, assignment, conc-         *)
(*               atention, insertion, deletion, alteration and          *)
(*               the ability to select portions of a string.            *)
(*                                                                      *)
(*       Verson :                                                       *)
(*               1.0 ; November 16, 83 ;   Namir C. Shammas             *)
(*               1.1 ; November 21, 84 ;   Walter Maner                 *)
(*                                                                      *)
(************************************************************************)
 
 
DEFINITION MODULE Strlib;
 
 EXPORT QUALIFIED Len,StringIs,ShowString,StringAdd,StringDelete,StringPos,
                  StringLeft,StringRight,StringMid,StringRemove,StringInsert,
                  StringReplace,StringChange,StringAlter,InputString,eos;
 
CONST
(*  End Of String  *)
    eos = 0C;
 
PROCEDURE Len(Str : ARRAY OF CHAR):CARDINAL;
(*    Obtain the number of characters in a string.  *)
 
PROCEDURE StringIs (VAR Str1 : ARRAY OF CHAR; Str2 : ARRAY OF CHAR);
(*    Assign an array of characters appended by an eos.  *)
 
PROCEDURE ShowString(Str : ARRAY OF CHAR );
(*    Display the string    *)
 
PROCEDURE StringAdd (VAR Str1 : ARRAY OF CHAR; Str2 : ARRAY OF CHAR );
(*    Concatenate string Str2 to Str1  *)
 
PROCEDURE StringDelete(VAR Str : ARRAY OF CHAR ; First,Last : CARDINAL);
(*    Delete a portion of a string STARTING at 'Fisrt' and ENDING at
      'Last' (included)  *)
 
PROCEDURE StringPos(Str1,Str2 : ARRAY OF CHAR ; Start : CARDINAL):CARDINAL;
(*    Function that returns the position of 'sub-string' Str2 in string 
      Str1. The search begins at position 'Start'.   *)
 
PROCEDURE StringLeft(VAR Str1 : ARRAY OF CHAR ;
                         Str2 : ARRAY OF CHAR; Count : CARDINAL);
(*    Pick the 'Count' leftmost characters of string Str2 and store it in
      string Str1.    *)
 
PROCEDURE StringRight(VAR Str1 : ARRAY OF CHAR ;
                          Str2 : ARRAY OF CHAR;  Count : CARDINAL);
(*    Pick the 'Count' rightmost characters of string Str2 and store it in
      string Str1.    *)
 
PROCEDURE StringMid(VAR Str1 : ARRAY OF CHAR ;
                        Str2 : ARRAY OF CHAR;  Start, Count : CARDINAL);
(*    Pick 'Count' characters starting at position 'Start' in string 
      Str2 and store it in string Str1.   *)
 
PROCEDURE StringRemove(VAR Str1 : ARRAY OF CHAR; Str2 : ARRAY OF CHAR);
(*    Remove ALL occurences of sub-string Str2 in string Str1 and update
      the latter string .   *)
 
PROCEDURE StringInsert(VAR Str1 : ARRAY OF CHAR; Str2 : ARRAY OF CHAR; 
                          Start : CARDINAL);
(*    Insert sub-string Str2 in string Str1 at position 'Start'.  The
      characters at position 'Start' and above are moved.   *) 
 
PROCEDURE StringReplace(VAR Str1 : ARRAY OF CHAR; Str2,Str3 : ARRAY OF CHAR);
(*    Replace ALL occurences of sub-string Str2 with sub-string Str3 in the
      string Str1.   *)
 
PROCEDURE StringChange(VAR Str1 : ARRAY OF CHAR; Str2,Str3 : ARRAY OF CHAR;
                           Start,Repeat:CARDINAL);
(*    Replace 'Repeat' times the occurence of sub-string Str2 by Str3 in
      string Str1.  The action taken starts at position 'Start'.   *)
 
PROCEDURE StringAlter(VAR Str1 : ARRAY OF CHAR; Str2 : ARRAY OF CHAR; 
                                Start : CARDINAL);
(*    This procedure overwrites the portions of string Str1 starting at
      position 'Start' and for the length of sub-string Str2.  *)
 
PROCEDURE InputString (VAR Str : ARRAY OF CHAR);
(*    Read string from ketboard.  *)
 
END Strlib.
