LineNumberReadStream.st
author Claus Gittinger <cg@exept.de>
Thu, 02 Mar 2000 15:15:13 +0100
changeset 885 c31412b26306
parent 478 778953b40429
child 1239 fcb74307748c
permissions -rw-r--r--
package-definitions fixed/updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
     1
"{ Package: 'stx:goodies' }"
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
     2
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 1996 by eXept Software AG
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
     5
	      All Rights Reserved
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
FilteringStream subclass:#LineNumberReadStream
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	instanceVariableNames:'lineNumber'
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
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    This filter keeps track of the current line, while
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    passing text from its inputStream to its outputStream.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    Can be placed in-between text processing and the texts
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    input stream, and let it keep track of the lineNumber.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    [see also:]
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    51
	ReadStream WriteStream ExternalStream FileStream
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    52
	FilteringStream FilteringLineStream
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    [author:]
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    55
	Claus Gittinger
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
!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
examples
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
  count lines in a Makefile:
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    62
									[exBegin]
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    |in filter|
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    in := 'Makefile' asFilename readStream.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
    filter := LineNumberReadStream readingFrom:in.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    filter upToEnd.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    filter close.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    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
    73
									[exEnd]
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
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
  find a specific string and output its lineNr:
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    78
									[exBegin]
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    |in filter|
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    in := 'Makefile' asFilename readStream.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    filter := LineNumberReadStream readingFrom:in.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    filter skipThroughAll:'start of'.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    filter close.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    Transcript showCR:('found in line %1' bindWith:(filter lineNumber)).
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
    89
									[exEnd]
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
"
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
!LineNumberReadStream methodsFor:'accessing'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
lineNumber
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    "return the current lineNumber"
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
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    "Created: 11.1.1997 / 16:57:10 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    "Modified: 11.1.1997 / 16:57:19 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
lineNumber:something
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    "set the current lineNumber"
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
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    "Created: 11.1.1997 / 16:57:10 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
    "Modified: 11.1.1997 / 16:57:22 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
! !
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
!LineNumberReadStream methodsFor:'initialization'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
initialize
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
    super initialize.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
    lineNumber := 1.
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    filter := [:char |
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
   123
		char == Character cr ifTrue:[
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
   124
		    lineNumber := lineNumber + 1.
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
   125
		].
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
   126
		char
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
   127
	      ].
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    "Modified: 11.1.1997 / 16:58:42 / cg"
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
! !
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
!LineNumberReadStream class methodsFor:'documentation'!
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
version
885
c31412b26306 package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents: 478
diff changeset
   135
    ^ '$Header: /cvs/stx/stx/libbasic2/LineNumberReadStream.st,v 1.2 2000-03-02 14:14:53 cg Exp $'
478
778953b40429 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
! !