(* Copyright (C) 1990, Digital Equipment Corporation. *) (* All rights reserved. *) (* See the file COPYRIGHT for a full description. *) (* Last modified on Mon Jan 29 03:32:58 1990 by muller *) INTERFACE Text; (* Contrary to what the "Modula-3 report (revised)" says, Text accepts and returns NIL for the empty string *) TYPE T = TEXT; (* A sequence of characters. The index of the first is 0. *) PROCEDURE Cat (t, u: T): T; (* Return the concatenation of t and u. *) PROCEDURE Equal (t, u: T): BOOLEAN; (* Return TRUE if t and u have the same length and the same (case-sensitive) contents. *) PROCEDURE GetChar (t: T; i: CARDINAL): CHAR; (* Return character i of t. A checked error if i >= Length(t). *) PROCEDURE Length (t: T): CARDINAL; (* Return the number of characters in t. *) PROCEDURE Empty (t: T): BOOLEAN; (* Equivalent to Length(t) = 0 *) PROCEDURE Sub (t: T; start, length: CARDINAL): T; (* Returns a sub-sequence of t. The result will be empty if start >= Length(t); otherwise the range of indexes of the subsequence is [start .. MIN(start+length, Length(t))-1]. *) PROCEDURE SetChars (VAR a: ARRAY OF CHAR; t: T); (* For each i in [0 .. MIN(HIGH(a), Length(t) - 1)], set a[i] to GetChar(t, i). *) PROCEDURE FromChar (c: CHAR): T; (* Return a text containing the character c *) PROCEDURE FromChars (READONLY a: ARRAY OF CHAR): T; (* Return a text containing the characters of a. *) (* OBSOLETE *) PROCEDURE PutStr (VAR a: ARRAY OF CHAR; t: T); (* = SetChars *) (* OBSOLETE *) PROCEDURE FromStr (READONLY a: ARRAY OF CHAR): T; (* = FromChars *) (* OBSOLETE *) PROCEDURE IsEmpty (t: T): BOOLEAN; (* = Empty *) (*--- Extension --- *) PROCEDURE FindChar (t: T; c: CHAR; start := 0): INTEGER; (* If c is one of t[i] for i IN [start .. Length(t)-1], returns the smallest such i; otherwise, returns -1 *) PROCEDURE FindCharR (t: T; c: CHAR; start := LAST (INTEGER)): INTEGER; (* If c is one of t[i] for i IN [0 .. MIN (start, Length (t)-1)], returns the largest such i; otherwise, returns -1 *) PROCEDURE Compare (t1, t2: T): [-1..1]; (* Returns -1 if t1 is less than t2, 0 if t1=t2, +1 if t1 is greater than t2; comparaison are made using the lexigraphic ordering *) END Text.