LineNumberReadStream.st
author Stefan Vogel <sv@exept.de>
Wed, 21 Nov 2007 18:24:07 +0100
changeset 1917 61c602336f3d
parent 1291 6c7d5dcf979c
child 2084 2d87edb46adc
permissions -rw-r--r--
Clean up code and document differences between #add: and #addLast:
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
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
1239
fcb74307748c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    15
"{ Package: 'stx:goodies' }"
fcb74307748c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 885
diff changeset
    16
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
FilteringStream subclass:#LineNumberReadStream
1283
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
    18
	instanceVariableNames:'lineNumber lineStartPosition'
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	classVariableNames:''
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	poolDictionaries:''
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	category:'Streams-Misc'
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!LineNumberReadStream class methodsFor:'documentation'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
copyright
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 COPYRIGHT (c) 1996 by eXept Software AG
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    29
	      All Rights Reserved
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 This software is furnished under a license and may be used
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 only in accordance with the terms of that license and with the
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 inclusion of the above copyright notice.   This software may not
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 be provided or otherwise made available to, or used by, any
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 other person.  No title to or ownership of the software is
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 hereby transferred.
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
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
documentation
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
"
1283
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
    44
    This filter keeps track of the current line, and optionally
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
    45
    the current lines start position (if the input stream is positionable).
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
    46
    while passing text from its inputStream to its outputStream.
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    Can be placed in-between text processing and the texts
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
    input stream, and let it keep track of the lineNumber.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    [see also:]
1283
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
    52
        ReadStream WriteStream ExternalStream FileStream
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
    53
        FilteringStream FilteringLineStream
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    [author:]
1283
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
    56
        Claus Gittinger
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
examples
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
  count lines in a Makefile:
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    63
									[exBegin]
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    |in filter|
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    in := 'Makefile' asFilename readStream.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    filter := LineNumberReadStream readingFrom:in.
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 upToEnd.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
    filter close.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    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
    74
									[exEnd]
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
  find a specific string and output its lineNr:
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    79
									[exBegin]
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
    |in filter|
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    in := 'Makefile' asFilename readStream.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    filter := LineNumberReadStream readingFrom:in.
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 skipThroughAll:'start of'.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    filter close.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    Transcript showCR:('found in line %1' bindWith:(filter lineNumber)).
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    90
									[exEnd]
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
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
!LineNumberReadStream methodsFor:'accessing'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
lineNumber
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    "return the current lineNumber"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
    ^ 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
    "Created: 11.1.1997 / 16:57:10 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    "Modified: 11.1.1997 / 16:57:19 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
lineNumber:something
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
    "set the current lineNumber"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    lineNumber := something.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
    "Created: 11.1.1997 / 16:57:10 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    "Modified: 11.1.1997 / 16:57:22 / cg"
1283
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   114
!
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   115
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   116
lineStartPosition
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   117
    "return the current lines start position"
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   118
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   119
    ^ lineStartPosition
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
! !
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
!LineNumberReadStream methodsFor:'initialization'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
initialize
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
    super initialize.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    lineNumber := 1.
1291
6c7d5dcf979c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1283
diff changeset
   128
    (inputStream isPositionable) ifTrue:[
1283
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   129
        lineStartPosition := inputStream position.
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   130
    ].
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
    filter := [:char |
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
1283
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   133
                char == Character cr ifTrue:[
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   134
                    lineNumber := lineNumber + 1.
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   135
                    inputStream isPositionable ifTrue:[
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   136
                        lineStartPosition := inputStream position.
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   137
                    ].
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   138
                ].
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   139
                char
974c05685dc6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1239
diff changeset
   140
              ].
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    "Modified: 11.1.1997 / 16:58:42 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
! !
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
!LineNumberReadStream class methodsFor:'documentation'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
version
1291
6c7d5dcf979c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1283
diff changeset
   148
    ^ '$Header: /cvs/stx/stx/libbasic2/LineNumberReadStream.st,v 1.5 2003-08-12 20:01:42 cg Exp $'
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
! !