as is
without express or implied warranty. Export of this
software outside of the United States of America may require an
export license.
$Id: TextReader.i3.html,v 1.3 2010-04-29 17:17:55 wagner Exp $
INTERFACEThink ``strtok''. ATextReader ; IMPORT TextList, Rd; IMPORT Thread;
TextReader.T
is initialized with
txtRd := NEW(TextReader.T).init(string);Tokens may be parsed out by passing in a delimiter, as follows:
VAR txt : TEXT; BEGIN WHILE txtRd.next(" ,.", txt) DO ( parse txt ) END ENDTo get the rest of the line, pass ``'' as the delims. It is a checked run-time error to pass NIL as the delims or as line.
EXCEPTION NoMore; TYPE T <: Public;All the methods of a
TextReader.T
leave the reader in a state
to parse further untouched tokens.
Public = OBJECT METHODS next(delims : TEXT; VAR chunk : TEXT; skipNulls := FALSE) : BOOLEAN;
get next word beforedelims
from reader. IfskipNulls
isTRUE
, zero-length strings are never returned. Return value isTRUE
if call succeeded. If nothing was left, call fails, and returnsFALSE
.
nextS(READONLY delims : SET OF CHAR; VAR chunk : TEXT; skipNulls := FALSE) : BOOLEAN;
next
actually callsnextS
.
nextE(delims : TEXT; skipNulls := FALSE) : TEXT RAISES { NoMore };
same as next
, except failure is signalled thru an exception
init(line : TEXT) : T;
initialize a new TextReader.T
initFromRd(rd : Rd.T) : T RAISES { Rd.Failure, Thread.Alerted };
initialize from anRd.T
.rd
must eventually end (to allow in-memory implementations)
isEmpty() : BOOLEAN;
probe a TextReader.T
shatter(listDelims : TEXT; endDelims : TEXT; skipNulls := FALSE) : TextList.T;
tokenize a line intoTEXT
tokens until EOT or an endDelim. It is a checked runtime error for there to be an overlap betweenlistDelims
andendDelims
pushBack(t: TEXT);
insertt
before remaining unreadTEXT
.t
must end in delimiter(s) if the next call tonext
is not to run past the end oft
. Current implementation may or may not insert an extra invisible delimiter aftert
in some cases. This will not be seen ifskipNulls
is alwaysTRUE
andt
always ends in a delimiter anyway.
END; END TextReader.