-- StringDefs.Mesa  Last edited by Sandman on June 30, 1980  11:02 AM
-- Copyright  Xerox Corporation 1979, 1980

DIRECTORY
  AltoDefs USING [charlength, CharsPerPage, CharsPerWord, LogCharsPerPage];

StringDefs: DEFINITIONS =
  BEGIN

  StringHeaderSize: CARDINAL = 2;

  CharsPerWord: CARDINAL = AltoDefs.CharsPerWord;
  charlength: CARDINAL = AltoDefs.charlength;
  CharsPerPage: CARDINAL = AltoDefs.CharsPerPage;
  LogCharsPerPage: CARDINAL = AltoDefs.LogCharsPerPage;

  SubStringDescriptor: TYPE = RECORD [base: STRING, offset, length: CARDINAL];

  SubString: TYPE = POINTER TO SubStringDescriptor;

  Overflow: SIGNAL;
  InvalidNumber: SIGNAL;
  StringBoundsFault: SIGNAL [s: STRING] RETURNS [ns: STRING];

  WordsForString: PROCEDURE [nchars: CARDINAL] RETURNS [CARDINAL];

  AppendChar: PROCEDURE [s: STRING, c: CHARACTER];
  AppendString: PROCEDURE [to: STRING, from: STRING];
  EqualString, EquivalentString: PROCEDURE [s1, s2: STRING] RETURNS [BOOLEAN];
  EqualStrings, EquivalentStrings: PROCEDURE [s1, s2: STRING] RETURNS [BOOLEAN];
  CompareStrings: PROCEDURE [s1, s2: STRING, ignoreCase: BOOLEAN ← TRUE]
    RETURNS [INTEGER]; --  -1 => less, 0 => equal, 1 => greater


  AppendSubString: PROCEDURE [to: STRING, from: SubString];
  EqualSubStrings, EquivalentSubStrings: PROCEDURE [s1, s2: SubString]
    RETURNS [BOOLEAN];
  EqualSubString, EquivalentSubString: PROCEDURE [s1, s2: SubString]
    RETURNS [BOOLEAN];
  DeleteSubString: PROCEDURE [s: SubString];

  UpperCase, LowerCase: PROCEDURE [c: CHARACTER] RETURNS [CHARACTER];

  -- routines for converting between strings and numbers


  StringToNumber: PROCEDURE [s: STRING, radix: CARDINAL] RETURNS [UNSPECIFIED];
  StringToDecimal: PROCEDURE [s: STRING] RETURNS [INTEGER] = INLINE
    BEGIN RETURN[StringToNumber[s, 10]] END;

  StringToOctal: PROCEDURE [s: STRING] RETURNS [UNSPECIFIED] = INLINE
    BEGIN RETURN[StringToNumber[s, 8]]; END;

  StringToLongNumber: PROCEDURE [s: STRING, radix: CARDINAL]
    RETURNS [LONG UNSPECIFIED];
  AppendNumber: PROCEDURE [s: STRING, n: CARDINAL, radix: CARDINAL];
  AppendDecimal: PROCEDURE [s: STRING, n: INTEGER];
  AppendOctal: PROCEDURE [s: STRING, n: UNSPECIFIED];
  AppendLongNumber: PROCEDURE [s: STRING, n: LONG UNSPECIFIED, radix: CARDINAL];
  AppendLongDecimal: PROCEDURE [s: STRING, n: LONG INTEGER];

  -- routines for bcpl strings

  BcplStringHeaderSize: CARDINAL = 1;
  BcplMaxLength: CARDINAL = 255;

  BcplSTRING: TYPE = MACHINE DEPENDENT RECORD [
    SELECT OVERLAID * FROM
      length => [length: [0..BcplMaxLength], body: CHARACTER],
      characters => [char: PACKED ARRAY [-1..BcplMaxLength) OF CHARACTER],
      ENDCASE];

  BcplStringOverflow, MesaStringOverflow: SIGNAL;
  WordsForBcplString: PROCEDURE [nchars: CARDINAL] RETURNS [CARDINAL] = INLINE
    BEGIN RETURN[BcplStringHeaderSize + nchars/CharsPerWord] END;

  MesaToBcplString: PROCEDURE [s: STRING, t: POINTER TO BcplSTRING];
  BcplToMesaString: PROCEDURE [t: POINTER TO BcplSTRING, s: STRING];

  END.