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