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-- |
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 | 3 |
" |
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 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
14 |
||
15 |
||
16 |
||
17 |
FilteringStream subclass:#LineNumberReadStream |
|
18 |
instanceVariableNames:'lineNumber' |
|
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 |
" |
|
44 |
This filter keeps track of the current line, while |
|
45 |
passing text from its inputStream to its outputStream. |
|
46 |
||
47 |
Can be placed in-between text processing and the texts |
|
48 |
input stream, and let it keep track of the lineNumber. |
|
49 |
||
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 | 53 |
|
54 |
[author:] |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
478
diff
changeset
|
55 |
Claus Gittinger |
478 | 56 |
" |
57 |
! |
|
58 |
||
59 |
examples |
|
60 |
" |
|
61 |
count lines in a Makefile: |
|
885
c31412b26306
package-definitions fixed/updated
Claus Gittinger <cg@exept.de>
parents:
478
diff
changeset
|
62 |
[exBegin] |
478 | 63 |
|in filter| |
64 |
||
65 |
in := 'Makefile' asFilename readStream. |
|
66 |
||
67 |
filter := LineNumberReadStream readingFrom:in. |
|
68 |
||
69 |
filter upToEnd. |
|
70 |
filter close. |
|
71 |
||
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 | 74 |
|
75 |
||
76 |
||
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 | 79 |
|in filter| |
80 |
||
81 |
in := 'Makefile' asFilename readStream. |
|
82 |
||
83 |
filter := LineNumberReadStream readingFrom:in. |
|
84 |
||
85 |
filter skipThroughAll:'start of'. |
|
86 |
filter close. |
|
87 |
||
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 | 90 |
" |
91 |
||
92 |
||
93 |
! ! |
|
94 |
||
95 |
!LineNumberReadStream methodsFor:'accessing'! |
|
96 |
||
97 |
lineNumber |
|
98 |
"return the current lineNumber" |
|
99 |
||
100 |
^ lineNumber |
|
101 |
||
102 |
"Created: 11.1.1997 / 16:57:10 / cg" |
|
103 |
"Modified: 11.1.1997 / 16:57:19 / cg" |
|
104 |
! |
|
105 |
||
106 |
lineNumber:something |
|
107 |
"set the current lineNumber" |
|
108 |
||
109 |
lineNumber := something. |
|
110 |
||
111 |
"Created: 11.1.1997 / 16:57:10 / cg" |
|
112 |
"Modified: 11.1.1997 / 16:57:22 / cg" |
|
113 |
! ! |
|
114 |
||
115 |
!LineNumberReadStream methodsFor:'initialization'! |
|
116 |
||
117 |
initialize |
|
118 |
super initialize. |
|
119 |
||
120 |
lineNumber := 1. |
|
121 |
filter := [:char | |
|
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 | 128 |
|
129 |
"Modified: 11.1.1997 / 16:58:42 / cg" |
|
130 |
! ! |
|
131 |
||
132 |
!LineNumberReadStream class methodsFor:'documentation'! |
|
133 |
||
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 | 136 |
! ! |