Path: utzoo!attcan!uunet!mcvax!cernvax!ethz!aplusl From: aplusl@ethz.UUCP (Albert Meier) Newsgroups: comp.lang.modula2 Subject: Module String for ISO Summary: Proposal for Standard Module Strings to be standardized by ISO; Message-ID: <457@ethz.UUCP> Date: 31 May 88 08:24:37 GMT Organization: ETH Zuerich Lines: 75 Expires: Sender: Reply-To: aplusl@bernina.UUCP (Albert Meier) Followup-To: Distribution: comp.lang.modula2 Organization: ETH Zuerich, Switzerland Keywords: Modula-2, Library, Strings Proposal of the Standard Strings Module --------------------------------------- Module Strings provides several procedures for string manipulation. DEFINITION MODULE String; CONST first = 0; last = -1; PROCEDURE Length (VAR str : ARRAY OF CHAR): INTEGER; PROCEDURE Pos (VAR str : ARRAY OF CHAR; from : INTEGER; token : ARRAY OF CHAR; caseSens : BOOLEAN): INTEGER; PROCEDURE Insert (VAR str : ARRAY OF CHAR; at : INTEGER; token : ARRAY OF CHAR); PROCEDURE Delete (VAR str : ARRAY OF CHAR; start, length : INTEGER); PROCEDURE Copy (VAR str : ARRAY OF CHAR; source : ARRAY OF CHAR; start, length : INTEGER); PROCEDURE Diff (VAR str : ARRAY OF CHAR; start, length : INTEGER; token : ARRAY OF CHAR; CaseSens : BOOLEAN): INTEGER; PROCEDURE Append (VAR front : ARRAY OF CHAR; tail : ARRAY OF CHAR); END String. Function Length returns the number of characters in str. A terminating null character is not counted. Function Occurs searches for the occurrence of token in str, starting with the character at position from. The resulting value corresponds to the position of the first matched character, or to last if token does not occur in str. If parameter caseSens is true, upper and lower case characters are considered as not identical, otherwise they are considered as identical. Exception to this are all characters with an ordinal value greater than 127. Procedure Insert inserts string token into string str to the left of the character at position at. If the resulting string is too long to be stored, it will be truncated accordingly. If at > Length(str), the appropriate number of spaces will first be appended to string str. If at = last, token will be appended to str. Delete deletes length characters from str starting at from. The subsequent characters close up to fill the gap. Copy copies a substring from source to str. The substring starts at start and is length characters long. Characters in excess of the last character in source are ignored. If there is not enough space, Copy truncates the target string in the same way as Insert. Compare compares a substring of str starting at start and of length length with the string in token. If the result is negative, token is less than the substring, if it is zero they are identical, and if it is positive token is greater than the substring. The absolute value of the result gives the character position at which the strings differ, with the first character having the value one. NB: Parameter str in Length, Occurs and Compare is a variable parameter for reasons of efficiency. The string is not altered. There is no point in using these functions with string constants, since the results are already known. SSS N N V V SNV SWISS STANDARDIZATION BODY S NN N V V 149/UK2 Programming Languages SSS N N N V V Chairman Albert Meier, CH-8906 Bonstetten S N NN V V . Tel +41/1/700 30 37 SSS N N V . E-mail aplusl@komsys.ifi.ethz.ch.UUCP