eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'LineNumberReadStream':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: LineNumberReadStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--PeekableStream
         |
         +--FilteringStream
            |
            +--LineNumberReadStream

Package:
stx:libbasic2
Category:
Streams-Misc
Version:
rev: 1.16 date: 2018/01/10 20:25:24
user: stefan
file: LineNumberReadStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


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.


Related information:

    ReadStream
    WriteStream
    ExternalStream
    FileStream
    FilteringStream
    FilteringLineStream

Instance protocol:

accessing
o  lineNumber
return the current lineNumber

o  lineNumber: something
set the current lineNumber

o  lineStartPosition
return the current lines start position

converting
o  asLineNumberReadStream

initialization
o  initialize
(comment from inherited method)
just to ignore initialize to objects which do not need it

positioning
o  position: aPosition
this method fails if inputStream is not positionable

o  skip: numberToSkip
this method fails if inputStream is not positionable

queries
o  atEnd
return true, if the receiver stream is at the end

o  isLineNumberReadStream

o  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
o  contents

o  contentsAsString

o  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


Examples:


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)).


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Sat, 20 Apr 2024 20:21:06 GMT