author | Jan Vrany <jan.vrany@labware.com> |
Wed, 23 Jun 2021 12:50:05 +0100 | |
branch | jv |
changeset 25430 | acd92449dc30 |
parent 25399 | b919356a1d8b |
permissions | -rw-r--r-- |
8148 | 1 |
" |
2 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
23107 | 3 |
COPYRIGHT (c) 2010 Jan Vrany |
25399
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
4 |
COPYRIGHT (c) 2020 LabWare |
8148 | 5 |
All Rights Reserved |
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 |
" |
|
8047 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17331 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
8447
9bdea3431846
EncodedStream inherts from PeekableStream
Stefan Vogel <sv@exept.de>
parents:
8444
diff
changeset
|
18 |
PeekableStream subclass:#EncodedStream |
15618 | 19 |
instanceVariableNames:'encoder stream' |
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
15963 | 22 |
category:'Collections-Text-Encodings' |
8047 | 23 |
! |
24 |
||
8148 | 25 |
!EncodedStream class methodsFor:'documentation'! |
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
23107 | 30 |
COPYRIGHT (c) 2010 Jan Vrany |
25399
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
31 |
COPYRIGHT (c) 2020 LabWare |
8148 | 32 |
All Rights Reserved |
33 |
||
34 |
This software is furnished under a license and may be used |
|
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
15049 | 41 |
! |
42 |
||
43 |
documentation |
|
44 |
" |
|
15664 | 45 |
a stream which transparently decodes from an external decoding, |
46 |
looking for '{ Encoding: xxx' near the beginning of the file. |
|
15049 | 47 |
|
15664 | 48 |
especially targeted towards reading ST/X source files. |
15049 | 49 |
" |
8148 | 50 |
! ! |
8047 | 51 |
|
52 |
!EncodedStream class methodsFor:'instance creation'! |
|
53 |
||
54 |
stream:streamArg encoder:encoder |
|
55 |
^ (self basicNew) stream:streamArg; encoder:encoder |
|
16394 | 56 |
|
57 |
" |
|
58 |
|s| |
|
59 |
s := EncodedStream stream:Transcript encoder:(CharacterEncoder encoderToEncodeFrom:#utf8 into:#unicode). |
|
25399
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
60 |
s nextPutAll:('öäü' utf8Encoded) |
16394 | 61 |
" |
18763 | 62 |
! |
63 |
||
64 |
stream:streamArg encoding:encodingSymbol |
|
65 |
^ self stream:streamArg encoder:(CharacterEncoder encoderFor:encodingSymbol) |
|
66 |
||
67 |
" |
|
68 |
|baseStream s| |
|
69 |
baseStream := '' readWriteStream. |
|
70 |
s := EncodedStream stream:baseStream encoding:#utf8. |
|
25399
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
71 |
s nextPutAll:'öäü'. |
18763 | 72 |
baseStream reset; contents. |
73 |
" |
|
8047 | 74 |
! ! |
75 |
||
17650 | 76 |
!EncodedStream class methodsFor:'Compatibility-VW5.4'! |
77 |
||
78 |
on: aStream encodedBy: aStreamEncoder |
|
79 |
||
80 |
^self basicNew on: aStream encodedBy: aStreamEncoder |
|
81 |
! ! |
|
82 |
||
12610 | 83 |
!EncodedStream class methodsFor:'utilities'! |
84 |
||
85 |
decodedStreamFor:aStream |
|
15345 | 86 |
"given a positionable stream, guess its encoding (by reading the |
87 |
first few lines, looking for a string with an encoding hint, |
|
88 |
and return an appropriate encoded string, which does the decoding |
|
89 |
on the fly. Used mostly to read UTF8 files (source code)" |
|
90 |
||
18763 | 91 |
|encodingSymbol decodedStream| |
12610 | 92 |
|
15664 | 93 |
aStream inputStream isPositionable ifTrue:[ |
94 |
encodingSymbol := CharacterEncoder guessEncodingOfStream:aStream inputStream. |
|
18763 | 95 |
decodedStream := self stream:aStream encoding:encodingSymbol. |
15963 | 96 |
"JV@2012-03-27: NO, DO NOT CHANGE POSITION!! Caller might be interested |
97 |
in all data!!!!!!" |
|
98 |
"/decodedStream skipEncodingChunk. |
|
15049 | 99 |
] ifFalse:[ |
100 |
"/ setup for no-encoding; |
|
101 |
"/ switch to a real encoder later, |
|
15664 | 102 |
"/ whenever an encoding pragma is encountered later by #nextChunk. |
103 |
decodedStream := self stream:aStream encoder:CharacterEncoder nullEncoderInstance. |
|
14095 | 104 |
]. |
12610 | 105 |
^ decodedStream |
15963 | 106 |
|
107 |
"Modified: / 23-08-2013 / 17:30:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
15049 | 108 |
! |
109 |
||
110 |
encoderFor:anEncodingSymbol |
|
111 |
(anEncodingSymbol isNil |
|
112 |
or:[ anEncodingSymbol = #'iso8859-1' |
|
113 |
or:[ anEncodingSymbol = #'ascii' ]]) ifTrue:[ |
|
114 |
^ nil |
|
115 |
]. |
|
116 |
^ CharacterEncoder encoderFor:anEncodingSymbol. |
|
12610 | 117 |
! ! |
118 |
||
17650 | 119 |
!EncodedStream methodsFor:'Compatibility-VW5.4'! |
120 |
||
121 |
on:aStream encodedBy:aStreamEncoder |
|
122 |
"Initialize the receiver on aStream with aStreamEncoder." |
|
123 |
||
124 |
"/ skipSize := PositionRecord new. |
|
125 |
"/ aStreamEncoder skipRecord: skipSize. |
|
126 |
"/ binary := false. |
|
127 |
"/ lineEndConvention == nil |
|
128 |
"/ ifTrue: |
|
129 |
"/ [aStream needsFileLineEndConversion |
|
130 |
"/ ifTrue: [self lineEndConvention: IOAccessor defaultLineEndConvention] |
|
131 |
"/ ifFalse: [self lineEndConvention: LineEndTransparent]]. |
|
132 |
self stream: aStream. |
|
133 |
self encoder: aStreamEncoder |
|
134 |
! ! |
|
135 |
||
8047 | 136 |
!EncodedStream methodsFor:'accessing'! |
137 |
||
11992 | 138 |
contentsSpecies |
139 |
||
140 |
"Not sure if this is ok" |
|
141 |
||
142 |
^ stream contentsSpecies. |
|
143 |
||
144 |
"/ ^UnicodeString |
|
145 |
||
146 |
"Created: / 14-06-2005 / 17:11:01 / janfrog" |
|
147 |
! |
|
148 |
||
8047 | 149 |
encoder |
150 |
^ encoder |
|
151 |
! |
|
152 |
||
153 |
encoder:something |
|
154 |
encoder := something. |
|
155 |
! |
|
156 |
||
15593 | 157 |
inputStream |
158 |
^ stream inputStream |
|
159 |
! |
|
160 |
||
161 |
lineNumber |
|
162 |
^ stream lineNumber |
|
163 |
! |
|
164 |
||
12646 | 165 |
pathName |
20477 | 166 |
"if our base stream has a pathname, delegate..." |
12646 | 167 |
|
168 |
stream isNil ifTrue:[ |
|
169 |
^ nil. |
|
170 |
]. |
|
171 |
^ stream pathName. |
|
172 |
! |
|
173 |
||
11766 | 174 |
readStream |
175 |
^ self |
|
176 |
! |
|
177 |
||
8047 | 178 |
stream |
179 |
^ stream |
|
180 |
! |
|
181 |
||
25399
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
182 |
stream:aStream |
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
183 |
self assert: aStream isEncodedStream not. |
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
184 |
stream := aStream. |
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
185 |
|
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
186 |
"Modified: / 20-07-2020 / 15:36:54 / Jan Vrany <jan.vrany@labware.com>" |
8047 | 187 |
! ! |
188 |
||
15963 | 189 |
!EncodedStream methodsFor:'private fileIn'! |
190 |
||
191 |
basicFileInNotifying:someone passChunk:passChunk |
|
192 |
"central method to file in from the receiver, i.e. read chunks and evaluate them - |
|
193 |
return the value of the last chunk. |
|
194 |
Someone (which is usually some codeView) is notified of errors." |
|
195 |
||
196 |
|lastValue pkg nameSpace usedNameSpaces |
|
197 |
packageQuerySignal nameSpaceQuerySignal usedNameSpaceQuerySignal |
|
198 |
changeDefaultApplicationNotificationSignal |
|
199 |
defaultApplicationQuerySignal defaultApplication |
|
200 |
confirmationQuerySignal handledSignals passedSignals askSomeoneForPackage outerContext askForVariableTypeOfUndeclaredQuery| |
|
201 |
||
202 |
self skipSeparators. |
|
203 |
lastValue := self peek. |
|
204 |
lastValue == $< ifTrue:[ |
|
205 |
"/ assume, it's an xml file |
|
206 |
^ self fileInXMLNotifying:someone passChunk:passChunk. |
|
207 |
]. |
|
208 |
lastValue == $# ifTrue:[ |
|
209 |
"assume unix interpreter name: |
|
210 |
'#!!stx -e' or something like this" |
|
211 |
self nextPeek == $!! ifTrue:[ |
|
212 |
"skip the unix command line" |
|
213 |
self nextLine |
|
214 |
] ifFalse:[ |
|
215 |
self error:'Invalid chunk start' |
|
216 |
] |
|
217 |
]. |
|
218 |
||
18876 | 219 |
(Smalltalk at:#Compiler) isNil ifTrue:[ |
15963 | 220 |
self isFileStream ifTrue:[ |
221 |
Transcript show:('[' , self pathName , '] '). |
|
222 |
]. |
|
223 |
Transcript showCR:'cannot fileIn (no compiler).'. |
|
224 |
^ nil. |
|
225 |
]. |
|
226 |
||
227 |
"/ support for V'Age applications |
|
228 |
defaultApplicationQuerySignal := Class defaultApplicationQuerySignal. |
|
229 |
changeDefaultApplicationNotificationSignal := Class changeDefaultApplicationNotificationSignal. |
|
230 |
||
231 |
"/ support for ST/X's nameSpaces & packages |
|
232 |
packageQuerySignal := Class packageQuerySignal. |
|
233 |
nameSpaceQuerySignal := Class nameSpaceQuerySignal. |
|
234 |
usedNameSpaceQuerySignal := Class usedNameSpaceQuerySignal. |
|
235 |
||
236 |
(someone respondsTo:#packageToInstall) ifTrue:[ |
|
237 |
pkg := someone packageToInstall. |
|
238 |
askSomeoneForPackage := true. |
|
239 |
] ifFalse:[ |
|
240 |
pkg := packageQuerySignal query. |
|
241 |
askSomeoneForPackage := false. |
|
242 |
]. |
|
243 |
(someone respondsTo:#currentNameSpace) ifTrue:[ |
|
244 |
nameSpace := someone currentNameSpace |
|
245 |
] ifFalse:[ |
|
246 |
nameSpace := nameSpaceQuerySignal query. |
|
247 |
]. |
|
248 |
(someone respondsTo:#usedNameSpaces) ifTrue:[ |
|
249 |
usedNameSpaces := someone usedNameSpaces |
|
250 |
] ifFalse:[ |
|
251 |
usedNameSpaces := usedNameSpaceQuerySignal query. |
|
252 |
]. |
|
253 |
(someone respondsTo:#defaultApplication) ifTrue:[ |
|
254 |
defaultApplication := someone defaultApplication |
|
255 |
] ifFalse:[ |
|
256 |
defaultApplication := defaultApplicationQuerySignal query. |
|
257 |
]. |
|
258 |
||
259 |
confirmationQuerySignal := Metaclass confirmationQuerySignal. |
|
260 |
||
261 |
handledSignals := SignalSet new. |
|
262 |
passedSignals := IdentitySet new. |
|
263 |
||
264 |
handledSignals add:changeDefaultApplicationNotificationSignal. |
|
265 |
passedSignals add:changeDefaultApplicationNotificationSignal. |
|
266 |
handledSignals add:defaultApplicationQuerySignal. |
|
267 |
passedSignals add:defaultApplicationQuerySignal. |
|
268 |
||
269 |
handledSignals add:packageQuerySignal. |
|
270 |
handledSignals add:usedNameSpaceQuerySignal. |
|
271 |
handledSignals add:nameSpaceQuerySignal. |
|
272 |
handledSignals add:confirmationQuerySignal. |
|
273 |
passedSignals add:confirmationQuerySignal. |
|
274 |
Parser notNil ifTrue:[ |
|
275 |
"only if libcomp is present" |
|
276 |
"Also catch a 'Parser askForVariableTypeOfUndeclaredQuery' and proceed with nil. |
|
277 |
Imagine somebody has autodefine workspace variables on and then |
|
278 |
evaluate Smalltalk loadPackage:'xyz' that loads code from source (using file-in), |
|
279 |
certainly we don't want to compile workspace variable access for every |
|
280 |
not-yet-loaded class in some namespace. |
|
281 |
This is demonstrated by Regression::CompilerTests2>>test_01 |
|
282 |
and this change actually fixes this test." |
|
283 |
askForVariableTypeOfUndeclaredQuery := Parser askForVariableTypeOfUndeclaredQuery. |
|
284 |
handledSignals add:askForVariableTypeOfUndeclaredQuery. |
|
285 |
]. |
|
286 |
||
287 |
||
288 |
outerContext := thisContext. |
|
289 |
||
290 |
handledSignals handle:[:ex | |
|
291 |
|sig| |
|
292 |
||
293 |
sig := ex creator. |
|
294 |
((passedSignals includes:sig) and:[sig isHandledIn:outerContext]) ifTrue:[ |
|
295 |
ex reject |
|
296 |
]. |
|
297 |
||
298 |
sig == changeDefaultApplicationNotificationSignal ifTrue:[ |
|
299 |
"/ invoked via #becomeDefault to set the defaultApp and the package. |
|
300 |
"/ (only when filing in V'Age code) |
|
301 |
defaultApplication := ex parameter. |
|
302 |
pkg := defaultApplication name asSymbol. |
|
303 |
ex proceedWith:nil |
|
304 |
]. |
|
305 |
sig == defaultApplicationQuerySignal ifTrue:[ |
|
306 |
"/ query for the application to add classes & methods into |
|
307 |
"/ (only when filing in V'Age code) |
|
308 |
ex proceedWith:defaultApplication |
|
309 |
]. |
|
310 |
sig == packageQuerySignal ifTrue:[ |
|
311 |
"answer the package to use for classes & methods" |
|
312 |
askSomeoneForPackage ifTrue:[ |
|
313 |
ex proceedWith:someone packageToInstall |
|
314 |
] ifFalse:[ |
|
315 |
ex proceedWith:pkg |
|
316 |
] |
|
317 |
]. |
|
318 |
sig == usedNameSpaceQuerySignal ifTrue:[ |
|
319 |
"answer the nameSpaces to be searched when encountering globals" |
|
320 |
ex proceedWith:usedNameSpaces |
|
321 |
]. |
|
322 |
sig == nameSpaceQuerySignal ifTrue:[ |
|
323 |
"answer the nameSpace to install new classes in" |
|
324 |
ex proceedWith:nameSpace |
|
325 |
]. |
|
326 |
sig == confirmationQuerySignal ifTrue:[ |
|
327 |
"don't pop up dialogs" |
|
328 |
ex proceedWith:false |
|
329 |
]. |
|
330 |
sig == askForVariableTypeOfUndeclaredQuery ifTrue:[ |
|
331 |
"no autodefined variables or so" |
|
332 |
ex proceedWith:nil. |
|
333 |
]. |
|
334 |
] do:[ |
|
335 |
[self atEnd] whileFalse:[ |
|
336 |
lastValue := self fileInNextChunkNotifying:someone passChunk:passChunk |
|
337 |
] |
|
338 |
]. |
|
339 |
^ lastValue |
|
340 |
||
341 |
"Modified: / 10.9.1999 / 16:54:01 / stefan" |
|
342 |
"Modified: / 16.11.2001 / 16:21:28 / cg" |
|
343 |
"Modified: / 18-03-2013 / 17:45:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
344 |
! ! |
|
345 |
||
8047 | 346 |
!EncodedStream methodsFor:'stream protocol'! |
347 |
||
8175 | 348 |
atEnd |
349 |
^ stream atEnd |
|
350 |
! |
|
351 |
||
8165 | 352 |
close |
353 |
stream close |
|
354 |
! |
|
355 |
||
13400 | 356 |
contents |
357 |
||
18157 | 358 |
^String streamContents: [:s| |
359 |
[ self atEnd ] whileFalse:[ |
|
360 |
|ch| |
|
361 |
ch := self next. |
|
362 |
"/ decoder may decide to return nil from #next, even though the |
|
363 |
"/ underlying stream was not at the end before. This is probably a bug... |
|
364 |
ch notNil ifTrue:[ |
|
365 |
s nextPut: ch |
|
366 |
] |
|
13400 | 367 |
] |
18157 | 368 |
] |
13400 | 369 |
|
370 |
"Created: / 25-02-2010 / 23:34:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
371 |
! |
|
372 |
||
8213 | 373 |
cr |
8459 | 374 |
self nextPutAll:(Character cr asString) |
8213 | 375 |
! |
376 |
||
11992 | 377 |
emphasis:anObject |
378 |
||
379 |
stream emphasis:anObject |
|
380 |
||
381 |
"Created: / 15-06-2005 / 11:16:33 / janfrog" |
|
382 |
! |
|
383 |
||
15477 | 384 |
flush |
385 |
stream flush |
|
386 |
! |
|
387 |
||
20363 | 388 |
isEmpty |
389 |
^ stream isEmpty |
|
390 |
! |
|
391 |
||
11946 | 392 |
isOpen |
12690 | 393 |
^ stream notNil and:[stream isOpen] |
11946 | 394 |
! |
395 |
||
11766 | 396 |
next |
11992 | 397 |
|
398 |
^encoder readNextCharacterFrom:stream |
|
399 |
||
400 |
"Created: / 14-06-2005 / 17:01:39 / janfrog" |
|
401 |
! |
|
11766 | 402 |
|
11992 | 403 |
next:charactersToRead |
404 |
||
405 |
^encoder readNext:charactersToRead charactersFrom:stream |
|
406 |
||
407 |
"Created: / 16-06-2005 / 11:43:43 / masca" |
|
11766 | 408 |
! |
409 |
||
8147 | 410 |
nextChunk |
15049 | 411 |
"as a side effect, check for an encoding chunk" |
15664 | 412 |
|
413 |
|prevEncoder chunk| |
|
8175 | 414 |
|
415 |
chunk := stream nextChunk. |
|
15664 | 416 |
chunk isNil ifTrue:[ |
417 |
^ nil |
|
418 |
]. |
|
15049 | 419 |
prevEncoder := encoder. |
15664 | 420 |
(prevEncoder isNullEncoder and:[stream isPositionable not]) ifTrue:[ |
15049 | 421 |
"/ not already checked |
15664 | 422 |
"/ check if we need lazy setup of the encoder |
423 |
"/ (used with non-positionable streams) |
|
424 |
(chunk includesString:'{ Encoding:') ifTrue:[ |
|
425 |
|enc| |
|
426 |
||
427 |
enc := self class encoderFor:(CharacterEncoder guessEncodingOfBuffer:chunk). |
|
428 |
enc notNil ifTrue:[ |
|
429 |
prevEncoder := encoder := enc. |
|
430 |
]. |
|
431 |
] |
|
15049 | 432 |
]. |
433 |
^ prevEncoder decodeString:chunk |
|
8147 | 434 |
! |
435 |
||
8213 | 436 |
nextChunkPut:chunk |
437 |
stream nextChunkPut:(encoder encodeString:chunk) |
|
438 |
! |
|
439 |
||
8047 | 440 |
nextPut:aCharacter |
441 |
self nextPutAll:(aCharacter asString). |
|
442 |
! |
|
443 |
||
444 |
nextPutAll:aCollection |
|
17668 | 445 |
encoder encodeString:aCollection on:stream |
8147 | 446 |
! |
447 |
||
17331 | 448 |
nextPutAll:aCollection startingAt:start to:stop |
17668 | 449 |
encoder encodeString:(aCollection copyFrom:start to:stop) on:stream. |
17331 | 450 |
! |
451 |
||
8444 | 452 |
peek |
11992 | 453 |
|
454 |
^stream peek |
|
455 |
||
456 |
"Created: / 20-06-2005 / 10:13:03 / masca" |
|
457 |
"Modified: / 20-06-2005 / 13:06:14 / masca" |
|
8444 | 458 |
! |
459 |
||
8175 | 460 |
peekFor:aCharacter |
461 |
^ stream peekFor:aCharacter |
|
462 |
! |
|
463 |
||
8165 | 464 |
position |
465 |
^ stream position |
|
466 |
! |
|
467 |
||
8197 | 468 |
position0Based |
15618 | 469 |
<resource: #obsolete> |
11947 | 470 |
"to be obsoleted - use position" |
471 |
||
15618 | 472 |
^ stream position |
8197 | 473 |
! |
474 |
||
475 |
position0Based:newPosition |
|
15618 | 476 |
<resource: #obsolete> |
11947 | 477 |
"to be obsoleted - use position" |
478 |
||
15618 | 479 |
stream position:newPosition |
8197 | 480 |
! |
481 |
||
8175 | 482 |
position1Based |
15618 | 483 |
<resource: #obsolete> |
11947 | 484 |
"to be obsoleted - use position" |
485 |
||
15618 | 486 |
^ stream position + 1 |
8175 | 487 |
! |
488 |
||
8147 | 489 |
position1Based:newPosition |
15618 | 490 |
<resource: #obsolete> |
11947 | 491 |
"to be obsoleted - use position" |
492 |
||
15618 | 493 |
stream position:newPosition-1 |
8175 | 494 |
! |
495 |
||
8197 | 496 |
position:newPosition |
497 |
stream position:newPosition |
|
498 |
! |
|
499 |
||
13400 | 500 |
reset |
501 |
stream reset |
|
502 |
||
503 |
"Created: / 25-02-2010 / 23:37:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
504 |
! |
|
505 |
||
8213 | 506 |
setToEnd |
507 |
stream setToEnd |
|
508 |
! |
|
509 |
||
14333 | 510 |
size |
20363 | 511 |
"not always correct, but probably better than 0. |
512 |
Better use #isEmpty." |
|
14333 | 513 |
|
15585 | 514 |
"/ is that better? |
515 |
"/ self error:'size of input is unknown (due to decoding)' |
|
14333 | 516 |
^ stream size |
517 |
||
518 |
"Created: / 31-08-2012 / 16:52:40 / cg" |
|
519 |
! |
|
520 |
||
11992 | 521 |
skip: anInteger |
522 |
||
523 |
"/ Should skip on character basis, not on bytes. This works for XML reader |
|
524 |
^stream skip: anInteger |
|
525 |
||
526 |
"Created: / 20-06-2005 / 13:06:06 / masca" |
|
527 |
! |
|
528 |
||
8175 | 529 |
skipSeparators |
530 |
^ stream skipSeparators |
|
15477 | 531 |
! |
532 |
||
533 |
sync |
|
534 |
stream sync |
|
535 |
! |
|
536 |
||
537 |
syncData |
|
538 |
stream syncData |
|
8047 | 539 |
! ! |
540 |
||
15049 | 541 |
!EncodedStream methodsFor:'testing'! |
542 |
||
543 |
isEncodedStream |
|
544 |
^ true |
|
15963 | 545 |
|
546 |
"Created: / 04-02-2014 / 20:27:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
15592 | 547 |
! |
548 |
||
16258
1582c656cdb0
Added EncodedStream>>isPositionable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15963
diff
changeset
|
549 |
isPositionable |
1582c656cdb0
Added EncodedStream>>isPositionable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15963
diff
changeset
|
550 |
^ stream isPositionable |
1582c656cdb0
Added EncodedStream>>isPositionable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15963
diff
changeset
|
551 |
|
1582c656cdb0
Added EncodedStream>>isPositionable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15963
diff
changeset
|
552 |
"Created: / 14-03-2014 / 16:18:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1582c656cdb0
Added EncodedStream>>isPositionable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15963
diff
changeset
|
553 |
! |
1582c656cdb0
Added EncodedStream>>isPositionable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15963
diff
changeset
|
554 |
|
15592 | 555 |
isReadable |
556 |
^ stream isReadable |
|
557 |
! |
|
558 |
||
559 |
isWritable |
|
560 |
^ stream isWritable |
|
15049 | 561 |
! ! |
562 |
||
8712
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
563 |
!EncodedStream methodsFor:'utilities'! |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
564 |
|
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
565 |
skipEncodingChunk |
14091 | 566 |
|pos chunk token| |
8712
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
567 |
|
13525
e17ebc11ca73
changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents:
13400
diff
changeset
|
568 |
stream isPositionable ifFalse:[ |
e17ebc11ca73
changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents:
13400
diff
changeset
|
569 |
^ self |
e17ebc11ca73
changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents:
13400
diff
changeset
|
570 |
]. |
e17ebc11ca73
changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents:
13400
diff
changeset
|
571 |
|
8712
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
572 |
pos := self position. |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
573 |
chunk := self nextChunk. |
14084 | 574 |
[ |
575 |
"/ if this is a valid chunk (i.e. not a comment or encoding-directive), |
|
576 |
"/ then position back, so it will be processed as usual. |
|
14091 | 577 |
"/ We could parse here, but this is overkill, since we are only interested in the fact, |
578 |
"/ that there is anything else than a comment in the chunk. |
|
579 |
"/ result := (Parser for:chunk) |
|
580 |
"/ ignoreErrors:true; |
|
581 |
"/ ignoreWarnings:true; |
|
582 |
"/ parseMethodBody. |
|
583 |
||
584 |
token := (Scanner for:chunk) |
|
585 |
ignoreErrors:true; |
|
586 |
ignoreWarnings:true; |
|
587 |
nextToken. |
|
588 |
||
589 |
token ~= #EOF ifTrue:[ |
|
14084 | 590 |
self position:pos |
591 |
]. |
|
14086 | 592 |
] on:Parser parseWarningSignal do:[:ex| |
14084 | 593 |
"really ignore any error. |
594 |
Even setting ignorError will output diagnostics here |
|
595 |
during standalone startup when debugging" |
|
14086 | 596 |
ex proceedWith:#ignore. |
14084 | 597 |
]. |
13525
e17ebc11ca73
changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents:
13400
diff
changeset
|
598 |
|
e17ebc11ca73
changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents:
13400
diff
changeset
|
599 |
"Modified: / 29-07-2011 / 17:42:11 / cg" |
8712
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
600 |
! ! |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
601 |
|
8047 | 602 |
!EncodedStream class methodsFor:'documentation'! |
603 |
||
14086 | 604 |
version |
18763 | 605 |
^ '$Header$' |
14086 | 606 |
! |
607 |
||
13400 | 608 |
version_CVS |
18763 | 609 |
^ '$Header$' |
12610 | 610 |
! |
611 |
||
25399
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
612 |
version_HG |
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
613 |
|
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
614 |
^ '$Changeset: <not expanded> $' |
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
615 |
! |
b919356a1d8b
`EncodedStream`: add assertion
Jan Vrany <jan.vrany@labware.com>
parents:
23547
diff
changeset
|
616 |
|
13400 | 617 |
version_SVN |
15345 | 618 |
^ '$ Id: EncodedStream.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
8047 | 619 |
! ! |
15049 | 620 |