author | fm |
Mon, 21 Sep 2009 18:48:48 +0200 | |
changeset 11992 | 1d7a1c1c1ccc |
parent 11947 | 18ce463920de |
child 12610 | cfbb45980e28 |
permissions | -rw-r--r-- |
8148 | 1 |
" |
2 |
COPYRIGHT (c) 2004 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 |
" |
|
8047 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
8447
9bdea3431846
EncodedStream inherts from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8444
diff
changeset
|
14 |
PeekableStream subclass:#EncodedStream |
8047 | 15 |
instanceVariableNames:'encoder stream' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Collections-Text-Encodings' |
|
19 |
! |
|
20 |
||
8148 | 21 |
!EncodedStream class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! ! |
|
8047 | 36 |
|
37 |
!EncodedStream class methodsFor:'instance creation'! |
|
38 |
||
39 |
stream:streamArg encoder:encoder |
|
40 |
^ (self basicNew) stream:streamArg; encoder:encoder |
|
41 |
! ! |
|
42 |
||
43 |
!EncodedStream methodsFor:'accessing'! |
|
44 |
||
11992 | 45 |
contentsSpecies |
46 |
||
47 |
"Not sure if this is ok" |
|
48 |
||
49 |
^ stream contentsSpecies. |
|
50 |
||
51 |
"/ ^UnicodeString |
|
52 |
||
53 |
"Created: / 14-06-2005 / 17:11:01 / janfrog" |
|
54 |
! |
|
55 |
||
8047 | 56 |
encoder |
57 |
^ encoder |
|
58 |
! |
|
59 |
||
60 |
encoder:something |
|
61 |
encoder := something. |
|
62 |
! |
|
63 |
||
11766 | 64 |
readStream |
65 |
^ self |
|
66 |
! |
|
67 |
||
8047 | 68 |
stream |
69 |
^ stream |
|
70 |
! |
|
71 |
||
72 |
stream:something |
|
73 |
stream := something. |
|
74 |
! ! |
|
75 |
||
76 |
!EncodedStream methodsFor:'stream protocol'! |
|
77 |
||
8175 | 78 |
atEnd |
79 |
^ stream atEnd |
|
80 |
! |
|
81 |
||
8165 | 82 |
close |
83 |
stream close |
|
84 |
! |
|
85 |
||
8213 | 86 |
cr |
8459 | 87 |
self nextPutAll:(Character cr asString) |
8213 | 88 |
! |
89 |
||
11992 | 90 |
emphasis:anObject |
91 |
||
92 |
stream emphasis:anObject |
|
93 |
||
94 |
"Created: / 15-06-2005 / 11:16:33 / janfrog" |
|
95 |
! |
|
96 |
||
11946 | 97 |
isOpen |
98 |
^ stream isOpen |
|
99 |
! |
|
100 |
||
11766 | 101 |
next |
11992 | 102 |
|
103 |
^encoder readNextCharacterFrom:stream |
|
104 |
||
105 |
"Created: / 14-06-2005 / 17:01:39 / janfrog" |
|
106 |
! |
|
11766 | 107 |
|
11992 | 108 |
next:charactersToRead |
109 |
||
110 |
^encoder readNext:charactersToRead charactersFrom:stream |
|
111 |
||
112 |
"Created: / 16-06-2005 / 11:43:43 / masca" |
|
11766 | 113 |
! |
114 |
||
8147 | 115 |
nextChunk |
8175 | 116 |
|chunk| |
117 |
||
118 |
chunk := stream nextChunk. |
|
119 |
chunk isNil ifTrue:[^ chunk]. |
|
120 |
^ encoder decodeString:chunk |
|
8147 | 121 |
! |
122 |
||
8213 | 123 |
nextChunkPut:chunk |
124 |
stream nextChunkPut:(encoder encodeString:chunk) |
|
125 |
! |
|
126 |
||
8047 | 127 |
nextPut:aCharacter |
128 |
self nextPutAll:(aCharacter asString). |
|
129 |
! |
|
130 |
||
131 |
nextPutAll:aCollection |
|
132 |
stream nextPutAll:(encoder encodeString:aCollection). |
|
8147 | 133 |
! |
134 |
||
8444 | 135 |
peek |
11992 | 136 |
|
137 |
^stream peek |
|
138 |
||
139 |
"Created: / 20-06-2005 / 10:13:03 / masca" |
|
140 |
"Modified: / 20-06-2005 / 13:06:14 / masca" |
|
8444 | 141 |
! |
142 |
||
8175 | 143 |
peekFor:aCharacter |
144 |
^ stream peekFor:aCharacter |
|
145 |
! |
|
146 |
||
8165 | 147 |
position |
148 |
^ stream position |
|
149 |
! |
|
150 |
||
8197 | 151 |
position0Based |
11947 | 152 |
"to be obsoleted - use position" |
153 |
||
8197 | 154 |
^ stream position0Based |
155 |
! |
|
156 |
||
157 |
position0Based:newPosition |
|
11947 | 158 |
"to be obsoleted - use position" |
159 |
||
8197 | 160 |
stream position0Based:newPosition |
161 |
! |
|
162 |
||
8175 | 163 |
position1Based |
11947 | 164 |
"to be obsoleted - use position" |
165 |
||
8175 | 166 |
^ stream position1Based |
167 |
! |
|
168 |
||
8147 | 169 |
position1Based:newPosition |
11947 | 170 |
"to be obsoleted - use position" |
171 |
||
8147 | 172 |
stream position1Based:newPosition |
8175 | 173 |
! |
174 |
||
8197 | 175 |
position:newPosition |
176 |
stream position:newPosition |
|
177 |
! |
|
178 |
||
8213 | 179 |
setToEnd |
180 |
stream setToEnd |
|
181 |
! |
|
182 |
||
11992 | 183 |
skip: anInteger |
184 |
||
185 |
"/ Should skip on character basis, not on bytes. This works for XML reader |
|
186 |
^stream skip: anInteger |
|
187 |
||
188 |
"Created: / 20-06-2005 / 13:06:06 / masca" |
|
189 |
! |
|
190 |
||
8175 | 191 |
skipSeparators |
192 |
^ stream skipSeparators |
|
8047 | 193 |
! ! |
194 |
||
8712
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
195 |
!EncodedStream methodsFor:'utilities'! |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
196 |
|
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
197 |
skipEncodingChunk |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
198 |
|pos chunk tree| |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
199 |
|
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
200 |
pos := self position. |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
201 |
chunk := self nextChunk. |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
202 |
tree := (Parser parseExpression:chunk). |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
203 |
"/ if this is a valid chunk (i.e. not a comment or encoding-directive), |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
204 |
"/ then position back, so it will be processed as usual. |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
205 |
tree notNil ifTrue:[ |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
206 |
self position:pos |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
207 |
] |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
208 |
! ! |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
209 |
|
8047 | 210 |
!EncodedStream class methodsFor:'documentation'! |
211 |
||
212 |
version |
|
11992 | 213 |
^ '$Header: /cvs/stx/stx/libbasic/EncodedStream.st,v 1.15 2009-09-21 16:48:48 fm Exp $' |
8047 | 214 |
! ! |