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.19 date: 2022/01/27 09:00:22
user: cg
file: LineNumberReadStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

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.

copyright

COPYRIGHT (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.

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;
returns the receiver

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.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 22 Dec 2024 03:00:43 GMT