LineNumberReadStream.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 4556 861d607dc91f
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1996 by eXept Software AG
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
     3
	      All Rights Reserved
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
2376
267edc0847fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2084
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
1239
fcb74307748c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    13
3540
9ee4ac3d4fc8 class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3329
diff changeset
    14
"{ NameSpace: Smalltalk }"
9ee4ac3d4fc8 class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3329
diff changeset
    15
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
FilteringStream subclass:#LineNumberReadStream
1283
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
    17
	instanceVariableNames:'lineNumber lineStartPosition'
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'Streams-Misc'
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!LineNumberReadStream class methodsFor:'documentation'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 1996 by eXept Software AG
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    28
	      All Rights Reserved
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
1283
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
    43
    This filter keeps track of the current line, and optionally
2538
8e34a8db4002 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
    44
    the current line's start position (if the input stream is positionable).
1283
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
    45
    while passing text from its inputStream to its outputStream.
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
2538
8e34a8db4002 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
    47
    Can be placed in-between text processing and the text's
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    input stream, and let it keep track of the lineNumber.
4456
b35c1ba864e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
    49
    
b35c1ba864e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
    50
    For example, this is useful if you have a parser which does not keep track of 
b35c1ba864e9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
    51
    line numbers, but want to present an error-line-number in a parse-error message.
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    [see also:]
2538
8e34a8db4002 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
    54
        ReadStream WriteStream ExternalStream FileStream
8e34a8db4002 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
    55
        FilteringStream FilteringLineStream
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    [author:]
2538
8e34a8db4002 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
    58
        Claus Gittinger
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
examples
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
  count lines in a Makefile:
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    65
									[exBegin]
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    |in filter|
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    in := 'Makefile' asFilename readStream.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    filter := LineNumberReadStream readingFrom:in.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    filter upToEnd.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    filter close.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    Transcript showCR:('Makefile has %1 lines' bindWith:(filter lineNumber - 1)).
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    76
									[exEnd]
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
  find a specific string and output its lineNr:
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    81
									[exBegin]
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    |in filter|
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    in := 'Makefile' asFilename readStream.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    filter := LineNumberReadStream readingFrom:in.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    filter skipThroughAll:'start of'.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    filter close.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
    Transcript showCR:('found in line %1' bindWith:(filter lineNumber)).
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    92
									[exEnd]
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
! !
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
!LineNumberReadStream methodsFor:'accessing'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
lineNumber
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
    "return the current lineNumber"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    ^ lineNumber
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    "Created: 11.1.1997 / 16:57:10 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    "Modified: 11.1.1997 / 16:57:19 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
lineNumber:something
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    "set the current lineNumber"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
    lineNumber := something.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    "Created: 11.1.1997 / 16:57:10 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    "Modified: 11.1.1997 / 16:57:22 / cg"
1283
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   116
!
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   117
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   118
lineStartPosition
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   119
    "return the current lines start position"
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   120
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   121
    ^ lineStartPosition
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
! !
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
3180
7c7ce3f9483e class: Stream
Claus Gittinger <cg@exept.de>
parents: 2827
diff changeset
   124
!LineNumberReadStream methodsFor:'converting'!
7c7ce3f9483e class: Stream
Claus Gittinger <cg@exept.de>
parents: 2827
diff changeset
   125
7c7ce3f9483e class: Stream
Claus Gittinger <cg@exept.de>
parents: 2827
diff changeset
   126
asLineNumberReadStream
7c7ce3f9483e class: Stream
Claus Gittinger <cg@exept.de>
parents: 2827
diff changeset
   127
    ^ self
7c7ce3f9483e class: Stream
Claus Gittinger <cg@exept.de>
parents: 2827
diff changeset
   128
! !
7c7ce3f9483e class: Stream
Claus Gittinger <cg@exept.de>
parents: 2827
diff changeset
   129
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
!LineNumberReadStream methodsFor:'initialization'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
initialize
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
    super initialize.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
    lineNumber := 1.
1291
6c7d5dcf979c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1283
diff changeset
   136
    (inputStream isPositionable) ifTrue:[
3329
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   137
        lineStartPosition := inputStream position.
1283
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   138
    ].
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
    filter := [:char |
3329
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   140
                char == Character cr ifTrue:[
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   141
                    lineNumber := lineNumber + 1.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   142
                    lineStartPosition notNil ifTrue:[
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   143
                        lineStartPosition := inputStream position.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   144
                    ].
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   145
                ].
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   146
                char
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   147
              ].
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    "Modified: 11.1.1997 / 16:58:42 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
! !
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
3329
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   152
!LineNumberReadStream methodsFor:'positioning'!
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   153
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   154
position:aPosition
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   155
    "this method fails if inputStream is not positionable"
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   156
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   157
    readAhead := nil.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   158
    inputStream position:aPosition.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   159
    (lineStartPosition notNil and:[aPosition < lineStartPosition]) ifTrue:[
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   160
        "we detect backPosition over a single line, but not over multiple lines and 
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   161
         no forward positioning!!"
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   162
        lineNumber := lineNumber - 1.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   163
        lineStartPosition := aPosition.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   164
    ].
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   165
!
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   166
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   167
skip:numberToSkip
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   168
    "this method fails if inputStream is not positionable"
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   169
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   170
    readAhead := nil.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   171
    inputStream skip:numberToSkip.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   172
    (lineStartPosition notNil and:[numberToSkip < lineStartPosition negated]) ifTrue:[
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   173
        "we detect backPosition over a single line, but not over multiple lines and 
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   174
         no forward positioning!!"
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   175
        lineNumber := lineNumber - 1.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   176
        lineStartPosition := lineStartPosition + numberToSkip.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   177
    ].
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   178
! !
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   179
2084
2d87edb46adc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1291
diff changeset
   180
!LineNumberReadStream methodsFor:'queries'!
2d87edb46adc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1291
diff changeset
   181
2d87edb46adc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1291
diff changeset
   182
atEnd
2d87edb46adc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1291
diff changeset
   183
    "return true, if the receiver stream is at the end"
2d87edb46adc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1291
diff changeset
   184
2d87edb46adc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1291
diff changeset
   185
    readAhead notNil ifTrue:[^ false].
2d87edb46adc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1291
diff changeset
   186
    ^ inputStream atEnd
2d87edb46adc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1291
diff changeset
   187
!
2d87edb46adc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1291
diff changeset
   188
3180
7c7ce3f9483e class: Stream
Claus Gittinger <cg@exept.de>
parents: 2827
diff changeset
   189
isLineNumberReadStream
7c7ce3f9483e class: Stream
Claus Gittinger <cg@exept.de>
parents: 2827
diff changeset
   190
    ^ true
4455
54e6571c7f8a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4201
diff changeset
   191
!
54e6571c7f8a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4201
diff changeset
   192
54e6571c7f8a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4201
diff changeset
   193
isPositionable
54e6571c7f8a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4201
diff changeset
   194
    ^ inputStream isPositionable
54e6571c7f8a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4201
diff changeset
   195
54e6571c7f8a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4201
diff changeset
   196
    "Created: / 13-07-2017 / 12:23:21 / cg"
3329
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   197
! !
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   198
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   199
!LineNumberReadStream methodsFor:'reading'!
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   200
4201
e29dfac90a57 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3540
diff changeset
   201
contents
e29dfac90a57 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3540
diff changeset
   202
    ^ inputStream contents
e29dfac90a57 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3540
diff changeset
   203
!
e29dfac90a57 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3540
diff changeset
   204
e29dfac90a57 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3540
diff changeset
   205
contentsAsString
e29dfac90a57 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3540
diff changeset
   206
    ^ inputStream contentsAsString
e29dfac90a57 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3540
diff changeset
   207
!
e29dfac90a57 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3540
diff changeset
   208
3329
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   209
upToAll_positionBefore:aCollection
3540
9ee4ac3d4fc8 class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3329
diff changeset
   210
    "read until a subcollection consisting of the elements in aCollection is encountered.
3329
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   211
     Return everything read excluding the elements in aCollection.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   212
     The position is left before the collection; i.e. the next
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   213
     read operations will return those elements.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   214
     If no such subcollection is encountered, all elements up to the end 
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   215
     are read and returned.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   216
     See also #throughAll: which also reads up to some objects
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   217
     but positions behind it and DOES include it in the returned
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   218
     collection.
3180
7c7ce3f9483e class: Stream
Claus Gittinger <cg@exept.de>
parents: 2827
diff changeset
   219
3329
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   220
     This is a copy from PositionableStream>>#upToAll_positionBefore:.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   221
     It fails if inputStream is not positionable"
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   222
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   223
    |answerStream element last|
2084
2d87edb46adc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1291
diff changeset
   224
3329
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   225
    last := aCollection last.
4556
861d607dc91f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4456
diff changeset
   226
    answerStream := self contentsSpecies writeStream:100.
3329
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   227
    [(element := self nextOrNil) notNil] whileTrue:[
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   228
        answerStream nextPut:element.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   229
        (element = last and:[answerStream endsBeforePositionWith:aCollection]) ifTrue:[
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   230
            |backStep|
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   231
            backStep := aCollection size negated.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   232
            self skip:backStep.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   233
            answerStream skip:backStep.
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   234
            ^ answerStream contents
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   235
        ].
2084
2d87edb46adc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1291
diff changeset
   236
    ].
3329
170f49ba6c9a class: LineNumberReadStream
Stefan Vogel <sv@exept.de>
parents: 3180
diff changeset
   237
    ^ answerStream contents
4556
861d607dc91f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4456
diff changeset
   238
861d607dc91f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4456
diff changeset
   239
    "Modified: / 10-01-2018 / 18:34:30 / stefan"
2084
2d87edb46adc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1291
diff changeset
   240
! !
2d87edb46adc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1291
diff changeset
   241
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
!LineNumberReadStream class methodsFor:'documentation'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
version
4201
e29dfac90a57 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3540
diff changeset
   245
    ^ '$Header$'
2376
267edc0847fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2084
diff changeset
   246
!
267edc0847fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2084
diff changeset
   247
267edc0847fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2084
diff changeset
   248
version_CVS
4201
e29dfac90a57 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3540
diff changeset
   249
    ^ '$Header$'
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
! !
3180
7c7ce3f9483e class: Stream
Claus Gittinger <cg@exept.de>
parents: 2827
diff changeset
   251