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-- |
478 | 1 |
" |
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 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
||
14 |
||
1239 | 15 |
"{ Package: 'stx:goodies' }" |
16 |
||
478 | 17 |
FilteringStream subclass:#LineNumberReadStream |
1283 | 18 |
instanceVariableNames:'lineNumber lineStartPosition' |
478 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
21 |
category:'Streams-Misc' |
|
22 |
! |
|
23 |
||
24 |
!LineNumberReadStream class methodsFor:'documentation'! |
|
25 |
||
26 |
copyright |
|
27 |
" |
|
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 | 30 |
|
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
||
39 |
||
40 |
! |
|
41 |
||
42 |
documentation |
|
43 |
" |
|
1283 | 44 |
This filter keeps track of the current line, and optionally |
45 |
the current lines start position (if the input stream is positionable). |
|
46 |
while passing text from its inputStream to its outputStream. |
|
478 | 47 |
|
48 |
Can be placed in-between text processing and the texts |
|
49 |
input stream, and let it keep track of the lineNumber. |
|
50 |
||
51 |
[see also:] |
|
1283 | 52 |
ReadStream WriteStream ExternalStream FileStream |
53 |
FilteringStream FilteringLineStream |
|
478 | 54 |
|
55 |
[author:] |
|
1283 | 56 |
Claus Gittinger |
478 | 57 |
" |
58 |
! |
|
59 |
||
60 |
examples |
|
61 |
" |
|
62 |
count lines in a Makefile: |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
478
diff
changeset
|
63 |
[exBegin] |
478 | 64 |
|in filter| |
65 |
||
66 |
in := 'Makefile' asFilename readStream. |
|
67 |
||
68 |
filter := LineNumberReadStream readingFrom:in. |
|
69 |
||
70 |
filter upToEnd. |
|
71 |
filter close. |
|
72 |
||
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 | 75 |
|
76 |
||
77 |
||
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 | 80 |
|in filter| |
81 |
||
82 |
in := 'Makefile' asFilename readStream. |
|
83 |
||
84 |
filter := LineNumberReadStream readingFrom:in. |
|
85 |
||
86 |
filter skipThroughAll:'start of'. |
|
87 |
filter close. |
|
88 |
||
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 | 91 |
" |
92 |
||
93 |
||
94 |
! ! |
|
95 |
||
96 |
!LineNumberReadStream methodsFor:'accessing'! |
|
97 |
||
98 |
lineNumber |
|
99 |
"return the current lineNumber" |
|
100 |
||
101 |
^ lineNumber |
|
102 |
||
103 |
"Created: 11.1.1997 / 16:57:10 / cg" |
|
104 |
"Modified: 11.1.1997 / 16:57:19 / cg" |
|
105 |
! |
|
106 |
||
107 |
lineNumber:something |
|
108 |
"set the current lineNumber" |
|
109 |
||
110 |
lineNumber := something. |
|
111 |
||
112 |
"Created: 11.1.1997 / 16:57:10 / cg" |
|
113 |
"Modified: 11.1.1997 / 16:57:22 / cg" |
|
1283 | 114 |
! |
115 |
||
116 |
lineStartPosition |
|
117 |
"return the current lines start position" |
|
118 |
||
119 |
^ lineStartPosition |
|
478 | 120 |
! ! |
121 |
||
122 |
!LineNumberReadStream methodsFor:'initialization'! |
|
123 |
||
124 |
initialize |
|
125 |
super initialize. |
|
126 |
||
127 |
lineNumber := 1. |
|
1291 | 128 |
(inputStream isPositionable) ifTrue:[ |
1283 | 129 |
lineStartPosition := inputStream position. |
130 |
]. |
|
478 | 131 |
filter := [:char | |
132 |
||
1283 | 133 |
char == Character cr ifTrue:[ |
134 |
lineNumber := lineNumber + 1. |
|
135 |
inputStream isPositionable ifTrue:[ |
|
136 |
lineStartPosition := inputStream position. |
|
137 |
]. |
|
138 |
]. |
|
139 |
char |
|
140 |
]. |
|
478 | 141 |
|
142 |
"Modified: 11.1.1997 / 16:58:42 / cg" |
|
143 |
! ! |
|
144 |
||
145 |
!LineNumberReadStream class methodsFor:'documentation'! |
|
146 |
||
147 |
version |
|
1291 | 148 |
^ '$Header: /cvs/stx/stx/libbasic2/LineNumberReadStream.st,v 1.5 2003-08-12 20:01:42 cg Exp $' |
478 | 149 |
! ! |