diff -r ee3de5b5742d -r 82462d153a7d Stream.st --- a/Stream.st Wed May 15 17:33:59 1996 +0200 +++ b/Stream.st Wed May 15 17:51:12 1996 +0200 @@ -140,25 +140,35 @@ contents "return the entire contents of the stream - - we do not know here how to do it, it must be redefined in subclass" + - we do not know here how to do it, it must be redefined in subclasses." ^ self subclassResponsibility + + "Modified: 15.5.1996 / 17:36:29 / cg" ! signalAtEnd - "return signalAtEnd" + "return the signalAtEnd flag setting. If true, reading past the end + will raise an EndOfStream exception. If false, no exception is + raised and nil is returned from all reading messages. + The default is (currently) to NOT raise a signal." ^ signalAtEnd "Created: 5.2.1996 / 18:24:53 / stefan" + "Modified: 15.5.1996 / 17:35:55 / cg" ! -signalAtEnd:something - "set signalAtEnd" +signalAtEnd:aBoolean + "set the signalAtEnd flag setting. If true, reading past the end + will raise an EndOfStream exception. If false, no exception is + raised and nil is returned from all reading messages. + The default is (currently) to NOT raise a signal." - signalAtEnd := something. + signalAtEnd := aBoolean. "Created: 5.2.1996 / 18:24:53 / stefan" + "Modified: 15.5.1996 / 17:36:12 / cg" ! ! !Stream methodsFor:'closing'! @@ -263,13 +273,67 @@ !Stream methodsFor:'misc'! binary - "switch to binary mode. ignored here, but added to make - internalStreams protocol compatible with externStreams." + "switch to binary mode. In binary mode, reading of text streams + returns byte-valued integers instead of characters; writing expects + byte-valued integers respectively. + Ignored here, but added to make internalStreams protocol compatible + with externalStreams." + "Modified: 15.5.1996 / 17:38:36 / cg" ! ! !Stream methodsFor:'non homogenous reading'! +nextAlphaNumericWord + "read the next word (i.e. up to non letter-or-digit). + Return a string containing those characters. + Any leading whitespace is skipped. + This method does not advance over any non-alphanumeric characters; + i.e. it will stick and continue to continue to return nil in + this case. Only call for it in a loop, AFTER you have checked for + the next character to really be alphanumeric (using #peek)" + + |s c| + + [self atEnd not + and:[(c := self peek) isSeparator]] whileTrue:[ + self next + ]. + + self atEnd ifTrue:[^ nil]. + + s := ''. + + [self atEnd not + and:[(c := self peek) isLetterOrDigit]] whileTrue:[ + s := s copyWith:c. + self next + ]. + + s size == 0 ifTrue:[^ nil]. + ^ s. + + " + |s| + + s := 'hello world 1234 foo1 foo2' readStream. + [s atEnd] whileFalse:[ + Transcript showCr:(s nextAlphaNumericWord). + ]. + + + notice: streams end never reached this way (sticking at the '+'-character: + |s| + + s := 'hello world 1234 foo1+foo2' readStream. + 10 timesRepeat:[ + Transcript showCr:(s nextAlphaNumericWord). + ]. + " + + "Modified: 15.5.1996 / 17:50:32 / cg" +! + nextLine "return the characters upTo (but excluding) the next cr character. Added for protocol compatibility with externalStreams." @@ -455,7 +519,13 @@ ! nextWord + "return the next characters which form an alphanumeric word + (i.e. everything upTo (but excluding) the next non alphanumeric + element)" + ^ self nextAlphaNumericWord + + "Modified: 15.5.1996 / 17:39:32 / cg" ! ! !Stream methodsFor:'non homogenous writing'! @@ -1106,6 +1176,6 @@ !Stream class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.39 1996-05-15 15:33:59 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.40 1996-05-15 15:51:12 cg Exp $' ! ! Stream initialize!