|
1 " |
|
2 COPYRIGHT (c) 1996 by eXept Software AG |
|
3 All Rights Reserved |
|
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 |
|
15 FilteringStream subclass:#LineNumberReadStream |
|
16 instanceVariableNames:'lineNumber' |
|
17 classVariableNames:'' |
|
18 poolDictionaries:'' |
|
19 category:'Streams-Misc' |
|
20 ! |
|
21 |
|
22 !LineNumberReadStream class methodsFor:'documentation'! |
|
23 |
|
24 copyright |
|
25 " |
|
26 COPYRIGHT (c) 1996 by eXept Software AG |
|
27 All Rights Reserved |
|
28 |
|
29 This software is furnished under a license and may be used |
|
30 only in accordance with the terms of that license and with the |
|
31 inclusion of the above copyright notice. This software may not |
|
32 be provided or otherwise made available to, or used by, any |
|
33 other person. No title to or ownership of the software is |
|
34 hereby transferred. |
|
35 " |
|
36 |
|
37 |
|
38 ! |
|
39 |
|
40 documentation |
|
41 " |
|
42 This filter keeps track of the current line, while |
|
43 passing text from its inputStream to its outputStream. |
|
44 |
|
45 Can be placed in-between text processing and the texts |
|
46 input stream, and let it keep track of the lineNumber. |
|
47 |
|
48 [see also:] |
|
49 ReadStream WriteStream ExternalStream FileStream |
|
50 FilteringStream FilteringLineStream |
|
51 |
|
52 [author:] |
|
53 Claus Gittinger |
|
54 " |
|
55 ! |
|
56 |
|
57 examples |
|
58 " |
|
59 count lines in a Makefile: |
|
60 [exBegin] |
|
61 |in filter| |
|
62 |
|
63 in := 'Makefile' asFilename readStream. |
|
64 |
|
65 filter := LineNumberReadStream readingFrom:in. |
|
66 |
|
67 filter upToEnd. |
|
68 filter close. |
|
69 |
|
70 Transcript showCR:('Makefile has %1 lines' bindWith:(filter lineNumber - 1)). |
|
71 [exEnd] |
|
72 |
|
73 |
|
74 |
|
75 find a specific string and output its lineNr: |
|
76 [exBegin] |
|
77 |in filter| |
|
78 |
|
79 in := 'Makefile' asFilename readStream. |
|
80 |
|
81 filter := LineNumberReadStream readingFrom:in. |
|
82 |
|
83 filter skipThroughAll:'start of'. |
|
84 filter close. |
|
85 |
|
86 Transcript showCR:('found in line %1' bindWith:(filter lineNumber)). |
|
87 [exEnd] |
|
88 " |
|
89 |
|
90 |
|
91 ! ! |
|
92 |
|
93 !LineNumberReadStream methodsFor:'accessing'! |
|
94 |
|
95 lineNumber |
|
96 "return the current lineNumber" |
|
97 |
|
98 ^ lineNumber |
|
99 |
|
100 "Created: 11.1.1997 / 16:57:10 / cg" |
|
101 "Modified: 11.1.1997 / 16:57:19 / cg" |
|
102 ! |
|
103 |
|
104 lineNumber:something |
|
105 "set the current lineNumber" |
|
106 |
|
107 lineNumber := something. |
|
108 |
|
109 "Created: 11.1.1997 / 16:57:10 / cg" |
|
110 "Modified: 11.1.1997 / 16:57:22 / cg" |
|
111 ! ! |
|
112 |
|
113 !LineNumberReadStream methodsFor:'initialization'! |
|
114 |
|
115 initialize |
|
116 super initialize. |
|
117 |
|
118 lineNumber := 1. |
|
119 filter := [:char | |
|
120 |
|
121 char == Character cr ifTrue:[ |
|
122 lineNumber := lineNumber + 1. |
|
123 ]. |
|
124 char |
|
125 ]. |
|
126 |
|
127 "Modified: 11.1.1997 / 16:58:42 / cg" |
|
128 ! ! |
|
129 |
|
130 !LineNumberReadStream class methodsFor:'documentation'! |
|
131 |
|
132 version |
|
133 ^ '$Header: /cvs/stx/stx/libbasic2/LineNumberReadStream.st,v 1.1 1997-01-11 18:54:37 cg Exp $' |
|
134 ! ! |