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