[net.sources] OSSI: SIStrings

biagioni@unc.UUCP (Edoardo Biagioni) (11/06/86)

(***************************************************************************)
(***                                                                     ***)
(***                                                                     ***)
(***                        O  S  S  I                                   ***)
(***                        ==========                                   ***)
(***                                                                     ***)
(**)               DEFINITION MODULE SIStrings;                          (**)
(***               ===========================                           ***)
(***                                                                     ***)
(***   This module defines string functions for Modula-2 programs        ***)
(***                                                                     ***)
(***---------------------------------------------------------------------***)
(***                                                                     ***)
(***   Hardware:             independent                                 ***)
(***   Operating System:     independent                                 ***)
(***   Compiler:             independent                                 ***)
(***                                                                     ***)
(***   Version:      3.0                                                 ***)
(***   Implemented:  see copyright                                       ***)
(***   Date:         1986-03-12                                          ***)
(***                                                                     ***)
(***---------------------------------------------------------------------***)
(***                                                                     ***)
(***   Copyright 1984, 1985, 1986 by                                     ***)
(***      E. S. Biagioni                                                 ***)
(***      G. Heiser                                                      ***)
(***      K. Hinrichs                                                    ***)
(***      C. Muller                                                      ***)
(***                                                                     ***)
(***   Institut fuer Informatik                                          ***)
(***   ETH Zuerich                                                       ***)
(***   CH 8092 Zuerich                                                   ***)
(***   Switzerland                                                       ***)
(***                                                                     ***)
(***   Department of Computer Science                                    ***)
(***   University of North Carolina                                      ***)
(***   Chapel Hill, North Carolina 27514                                 ***)
(***   U.S.A.                                                            ***)
(***                                                                     ***)
(*** Permission to copy without fee all of this material is granted      ***)
(*** provided that the copies are not made or distributed for direct     ***)
(*** commercial advantage, that this OSSI copyright notice is            ***)
(*** included in the copy, that the module is not modified in any way    ***)
(*** except where necessary for compilation on a particular system,      ***)
(*** and that the module is always distributed in its original form.     ***)
(*** Distribution of this module in a modified form without including    ***)
(*** the original version is a violation of this copyright notice.       ***)
(***                                                                     ***)
(***---------------------------------------------------------------------***)
(***                                                                     ***)
(***   Updates:                                                          ***)
(***                                                                     ***)
(***                                                                     ***)
(***************************************************************************)

FROM SISystem IMPORT
  Relation;


EXPORT QUALIFIED
  StringLength,               (*  PROCEDUREs and functions  *)
  StripBlanks,
  StringCompare,
  CopyString,
  InsertSubstring,
  OverwriteWithSubstring,
  DeleteSubstring,
  ExtractSubstring,
  LocateSubstring,
  LocateChar;


PROCEDURE StringLength (string: ARRAY OF CHAR): CARDINAL;
(* returns the number of characters in the string, up to but excluding
   any EOS (imported from the module Standard) *)

PROCEDURE StripBlanks (VAR string: ARRAY OF CHAR);
(* returns the string with all blank sequences reduced to a single blank,
   and no blanks at the beginning and at the end *)

PROCEDURE StringCompare (string1, string2: ARRAY OF CHAR;
                         caseSensitive: BOOLEAN): Relation;
(* returns less, equal or greater depending on the lexical
   order of the strings, e. g.
   StringCompare ("aa", "ab", TRUE) = less.
   If caseSensitive = TRUE, the comparison is strictly according
   to the collating sequence of the machine, otherwise the
   comparisons are preceded by a possibly implicit Cap operation. *)

PROCEDURE CopyString (fromString: ARRAY OF CHAR;
                      VAR toString: ARRAY OF CHAR);
(* Copies the string "fromString" to the string "toString". The string
   is truncated if necessary *)

PROCEDURE InsertSubstring (VAR baseString: ARRAY OF CHAR;
                           subString: ARRAY OF CHAR; start: CARDINAL); 
(* Inserts "subString" into "baseString": inserting starts after
   "start" characters of "BaseString" are skipped; the rest of "baseString"
   is shifted up and truncated as necessary.
   If start > StringLength (baseString) the result is undefined *)

PROCEDURE OverwriteWithSubstring (VAR baseString: ARRAY OF CHAR;
                                  subString: ARRAY OF CHAR; shift: CARDINAL);
(* Like insert, but does not shift up part of "baseString": "baseString" is
   lengthened and "subString" truncated as necessary *)

PROCEDURE DeleteSubstring (VAR baseString: ARRAY OF CHAR;
                           fromPosition: CARDINAL; length: CARDINAL);
(* Deletes "length" characters in "baseString" starting at "fromPosition";
   it shifts down any characters of "baseString" following the deletion*)

PROCEDURE ExtractSubstring (VAR subString: ARRAY OF CHAR;
                            baseString: ARRAY OF CHAR;
                            fromPosition, length: CARDINAL);
(* returns in subString the characters (truncated as necessary) of
   "baseString" from "fromPosition" through "fromPosition" + "length" - 1 *)

PROCEDURE LocateSubstring (baseString, subString: ARRAY OF CHAR;
                           VAR start, end: CARDINAL; VAR found: BOOLEAN);
(* Searches for "subString" in positions "start" through "end" of
   "baseString". If sucessful, found will be TRUE and start, end
   will point to the first occurence of "subString", otherwise found
   will be FALSE and start, end will be undefined. *)

PROCEDURE LocateChar (string: ARRAY OF CHAR; c: CHAR;
                      VAR start, end: CARDINAL; VAR found: BOOLEAN);
(* Searches for "c" in positions "start" through "end" of string.
   If sucessful, found will return TRUE and start, end will point to the
   first occurence of "c", otherwise found will return FALSE
   and start, end will be undefined. *)
 
END SIStrings.