|
Class: LineNumberReadStream
Object
|
+--Stream
|
+--PeekableStream
|
+--FilteringStream
|
+--LineNumberReadStream
- Package:
- stx:libbasic2
- Category:
- Streams-Misc
- Version:
- rev:
1.19
date: 2022/01/27 09:00:22
- user: cg
- file: LineNumberReadStream.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
This filter keeps track of the current line, and optionally
the current line's start position (if the input stream is positionable).
while passing text from its inputStream to its outputStream.
Can be placed in-between text processing and the text's
input stream, and let it keep track of the lineNumber.
For example, this is useful if you have a parser which does not keep track of
line numbers, but want to present an error-line-number in a parse-error message.
copyrightCOPYRIGHT (c) 1996 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
accessing
-
lineNumber
-
return the current lineNumber
-
lineNumber: something
-
set the current lineNumber
-
lineStartPosition
-
return the current lines start position
converting
-
asLineNumberReadStream
-
initialization
-
initialize
-
(comment from inherited method)
just to ignore initialize to objects which do not need it
positioning
-
position: aPosition
-
this method fails if inputStream is not positionable
-
skip: numberToSkip
-
this method fails if inputStream is not positionable;
returns the receiver
queries
-
atEnd
-
return true, if the receiver stream is at the end
-
isLineNumberReadStream
-
-
isPositionable
-
(comment from inherited method)
return true, if the stream supports positioning (some do not).
Since this is an abstract class, false is returned here - just to make certain.
reading
-
contents
-
-
contentsAsString
-
-
upToAll_positionBefore: aCollection
-
read until a subcollection consisting of the elements in aCollection is encountered.
Return everything read excluding the elements in aCollection.
The position is left before the collection; i.e. the next
read operations will return those elements.
If no such subcollection is encountered, all elements up to the end
are read and returned.
See also #throughAll: which also reads up to some objects
but positions behind it and DOES include it in the returned
collection.
This is a copy from PositionableStream>>#upToAll_positionBefore:.
It fails if inputStream is not positionable
count lines in a Makefile:
|in filter|
in := 'Makefile' asFilename readStream.
filter := LineNumberReadStream readingFrom:in.
filter upToEnd.
filter close.
Transcript showCR:('Makefile has %1 lines' bindWith:(filter lineNumber - 1)).
|
find a specific string and output its lineNr:
|in filter|
in := 'Makefile' asFilename readStream.
filter := LineNumberReadStream readingFrom:in.
filter skipThroughAll:'start of'.
filter close.
Transcript showCR:('found in line %1' bindWith:(filter lineNumber)).
|
|