Page Numbers: Yes First Page: 76 X: 527 Y: 10.5"
Margins: Binding: 13
Odd Heading: Not-on-first-page
Alto/Mesa String Package
Even Heading:
Alto/Mesa String Package
Alto/Mesa String Package
October 1980
This section describes procedures that implement various string operations. The necessary TYPE and PROCEDURE declarations appear in StringDefs. The interface String is approximately the same as StringDefs, and is also exported by the system. (Constants defining word size, character size, etc. are in AltoDefs.) Specific language features concerning STRINGs are described in more detail in the Mesa Language Manual (see the index).
SubStringDescriptor: TYPE = RECORD [
base:
STRING,
offset, length:
CARDINAL];
SubString: POINTER TO SubStringDescriptor;
A SubStringDescriptor describes a region within a string. The first character is base[offset] and the last character is base[offset+length-1].
WordsForString: PROCEDURE [nchars: CARDINAL] RETURNS [CARDINAL];
Calculates the number of words of storage needed to hold a string of length nchars. The value returned includes any system overhead for string storage.
LowerCase: PROCEDURE [CHARACTER] RETURNS [CHARACTER];
Changes upper case characters into lower case ones. This is a noop if the character is not a letter.
UpperCase: PROCEDURE [CHARACTER] RETURNS [CHARACTER];
Changes lower case characters into upper case ones. This is a noop if the character is not a letter.
String Construction
AppendChar: PROCEDURE [s: STRING, c: CHARACTER];
Appends the character c to the end of the string s; s.length is updated; s.maxlength is unchanged.
AppendString: PROCEDURE [to, from: STRING];
Appends the string from to the end of the string to; to.length is updated; to.maxlength is unchanged.
AppendSubString: PROCEDURE [to: STRING, from: SubString];
Appends the substring in from to the end of the string in to; to.length is updated; to.maxlength is unchanged.
StringBoundsFault: SIGNAL [s: STRING] RETURNS [ns: STRING];
An attempt was made to increase the length of s to be larger than s.maxlength. The catch phrase should return a string ns with more room.
DeleteSubString: PROCEDURE [s: SubString];
Deletes the substring described by s from the string s.base; s.base.length is updated; s.base.maxlength is unchanged.
String Comparison
EqualString, EqualStrings: PROCEDURE [s1, s2: STRING] RETURNS [BOOLEAN];
Returns TRUE if s1 and s2 contain exactly the same characters.
EquivalentString, EquivalentStrings: PROCEDURE [s1, s2: STRING] RETURNS [BOOLEAN];
Returns TRUE if s1 and s2 contain the same characters except for case shifts. Note: strings containing control characters may not be compared correctly.
EqualSubString, EqualSubStrings: PROCEDURE [s1, s2: SubString] RETURNS [BOOLEAN];
Analogous to EqualString and EqualStrings.
EquivalentSubString, EquivalentSubStrings: PROCEDURE [s1, s2: SubString]
RETURNS [BOOLEAN];
Analogous to EquivalentString and EquivalentStrings.
CompareStrings: PROCEDURE [s1, s2: STRING, ignoreCase: BOOLEAN ← TRUE]
RETURNS [INTEGER];
Lexically compares two strings and returns -1, 0, 1 if the first is less than, equal to, or greater than the second; an optional parameter may be supplied to ignore case differences.
String to Binary Conversion
StringToNumber: PROCEDURE [s: STRING, radix: CARDINAL] RETURNS [UNSPECIFIED];
The characters of s are interpreted as a number whose value is returned. radix is used in the conversion unless the "B" ("b") or "D" ("d") notation is used to force octal or decimal. Values of radix other than 8 or 10 are not supported.
StringToDecimal: PROCEDURE [s: STRING] RETURNS [INTEGER];
Calls StringToNumber[s, 10].
StringToOctal: PROCEDURE [s: STRING] RETURNS [UNSPECIFIED];
Calls StringToNumber[s, 8].
StringToLongNumber: PROCEDURE [s: STRING, radix: CARDINAL] RETURNS [LONG INTEGER];
The characters of s are interpreted as a LONG INTEGER whose value is returned. radix is used in the conversion unless the "B" or "D" notation is used to force octal or decimal. Values of radix other than 8 or 10 are not supported.
InvalidNumber: SIGNAL;
A string is not a valid number if it is empty or contains characters other than digits (a leading ’- and trailing ’B or ’D with scale factor are allowed).
Binary to String Conversion
AppendNumber: PROCEDURE [s: STRING, n, radix: CARDINAL];
The value of n is converted to text using radix and appended to s; radix should be in the interval [2..36].
AppendDecimal: PROCEDURE [s: STRING, n: INTEGER];
IF n < 0 THEN AppendChar[s, ’-]; AppendNumber[s, ABS[n], 10].
AppendOctal: PROCEDURE [s: STRING, n: UNSPECIFIED];
AppendNumber[s, n, 8]; AppendChar[s, ’B].
AppendLongDecimal: PROCEDURE [s: STRING, n: LONG INTEGER];
IF n < 0 THEN AppendChar[s, ’-]; AppendLongNumber[s, ABS[n], 10].
Fine Point:
AppendDecimal and AppendLongDecimal deal properly with FIRST[INTEGER] and FIRST[LONG INTEGER], even though their descriptions would imply otherwise.
AppendLongNumber: PROCEDURE [s: STRING, n: LONG UNSPECIFIED, radix: CARDINAL];
The value of n is converted to text using radix and appended to s; radix should be in the interval [2..36].