author | Claus Gittinger <cg@exept.de> |
Thu, 27 Jun 2019 15:21:18 +0200 | |
changeset 24377 | 2fbcb2fa6c43 |
parent 24030 | 4f1f0d4e1ce4 |
child 24641 | c8b9d72e1a36 |
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 |
24000 | 17 |
instanceVariableNames:'encoder stream peekChar' |
15618 | 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). |
|
24030 | 56 |
s nextPutAll:('öäü' utf8Encoded) |
22480 | 57 |
|
58 |
|s| |
|
24030 | 59 |
s := EncodedStream stream:('öäü' readStream) encoder:(CharacterEncoder encoderToEncodeFrom:#utf8 into:#unicode). |
22480 | 60 |
s next:3 |
16394 | 61 |
" |
22480 | 62 |
|
63 |
"Modified (comment): / 17-01-2018 / 13:36:28 / stefan" |
|
18763 | 64 |
! |
65 |
||
66 |
stream:streamArg encoding:encodingSymbol |
|
67 |
^ self stream:streamArg encoder:(CharacterEncoder encoderFor:encodingSymbol) |
|
68 |
||
69 |
" |
|
70 |
|baseStream s| |
|
71 |
baseStream := '' readWriteStream. |
|
72 |
s := EncodedStream stream:baseStream encoding:#utf8. |
|
24030 | 73 |
s nextPutAll:'öäü'. |
18763 | 74 |
baseStream reset; contents. |
22480 | 75 |
|
76 |
s contents |
|
18763 | 77 |
" |
22480 | 78 |
|
79 |
"Modified (comment): / 17-01-2018 / 13:32:10 / stefan" |
|
8047 | 80 |
! ! |
81 |
||
17650 | 82 |
!EncodedStream class methodsFor:'Compatibility-VW5.4'! |
83 |
||
84 |
on: aStream encodedBy: aStreamEncoder |
|
85 |
||
86 |
^self basicNew on: aStream encodedBy: aStreamEncoder |
|
87 |
! ! |
|
88 |
||
12610 | 89 |
!EncodedStream class methodsFor:'utilities'! |
90 |
||
91 |
decodedStreamFor:aStream |
|
15345 | 92 |
"given a positionable stream, guess its encoding (by reading the |
93 |
first few lines, looking for a string with an encoding hint, |
|
94 |
and return an appropriate encoded string, which does the decoding |
|
95 |
on the fly. Used mostly to read UTF8 files (source code)" |
|
96 |
||
18763 | 97 |
|encodingSymbol decodedStream| |
12610 | 98 |
|
15664 | 99 |
aStream inputStream isPositionable ifTrue:[ |
100 |
encodingSymbol := CharacterEncoder guessEncodingOfStream:aStream inputStream. |
|
18763 | 101 |
decodedStream := self stream:aStream encoding:encodingSymbol. |
15963 | 102 |
"JV@2012-03-27: NO, DO NOT CHANGE POSITION!! Caller might be interested |
103 |
in all data!!!!!!" |
|
104 |
"/decodedStream skipEncodingChunk. |
|
15049 | 105 |
] ifFalse:[ |
106 |
"/ setup for no-encoding; |
|
107 |
"/ switch to a real encoder later, |
|
15664 | 108 |
"/ whenever an encoding pragma is encountered later by #nextChunk. |
109 |
decodedStream := self stream:aStream encoder:CharacterEncoder nullEncoderInstance. |
|
14095 | 110 |
]. |
12610 | 111 |
^ decodedStream |
15963 | 112 |
|
113 |
"Modified: / 23-08-2013 / 17:30:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
15049 | 114 |
! |
115 |
||
116 |
encoderFor:anEncodingSymbol |
|
117 |
(anEncodingSymbol isNil |
|
118 |
or:[ anEncodingSymbol = #'iso8859-1' |
|
119 |
or:[ anEncodingSymbol = #'ascii' ]]) ifTrue:[ |
|
120 |
^ nil |
|
121 |
]. |
|
122 |
^ CharacterEncoder encoderFor:anEncodingSymbol. |
|
12610 | 123 |
! ! |
124 |
||
17650 | 125 |
!EncodedStream methodsFor:'Compatibility-VW5.4'! |
126 |
||
127 |
on:aStream encodedBy:aStreamEncoder |
|
128 |
"Initialize the receiver on aStream with aStreamEncoder." |
|
129 |
||
130 |
"/ skipSize := PositionRecord new. |
|
131 |
"/ aStreamEncoder skipRecord: skipSize. |
|
132 |
"/ binary := false. |
|
133 |
"/ lineEndConvention == nil |
|
134 |
"/ ifTrue: |
|
135 |
"/ [aStream needsFileLineEndConversion |
|
136 |
"/ ifTrue: [self lineEndConvention: IOAccessor defaultLineEndConvention] |
|
137 |
"/ ifFalse: [self lineEndConvention: LineEndTransparent]]. |
|
138 |
self stream: aStream. |
|
139 |
self encoder: aStreamEncoder |
|
140 |
! ! |
|
141 |
||
8047 | 142 |
!EncodedStream methodsFor:'accessing'! |
143 |
||
144 |
encoder |
|
145 |
^ encoder |
|
146 |
! |
|
147 |
||
24030 | 148 |
encoder:aCharacterEncoder |
149 |
encoder := aCharacterEncoder. |
|
8047 | 150 |
! |
151 |
||
21642 | 152 |
encoding |
153 |
^ encoder nameOfEncoding |
|
154 |
||
155 |
"Created: / 13-03-2017 / 11:17:56 / stefan" |
|
156 |
! |
|
157 |
||
15593 | 158 |
inputStream |
159 |
^ stream inputStream |
|
160 |
! |
|
161 |
||
162 |
lineNumber |
|
22415 | 163 |
"the linenumber doesn't change when characters are decoded" |
164 |
||
165 |
stream isNil ifTrue:[ |
|
166 |
^ nil. |
|
167 |
]. |
|
15593 | 168 |
^ stream lineNumber |
22415 | 169 |
|
170 |
"Modified: / 02-01-2018 / 20:12:18 / stefan" |
|
171 |
"Modified (comment): / 09-01-2018 / 17:47:20 / stefan" |
|
15593 | 172 |
! |
173 |
||
12646 | 174 |
pathName |
20477 | 175 |
"if our base stream has a pathname, delegate..." |
12646 | 176 |
|
177 |
stream isNil ifTrue:[ |
|
178 |
^ nil. |
|
179 |
]. |
|
180 |
^ stream pathName. |
|
181 |
! |
|
182 |
||
11766 | 183 |
readStream |
21472 | 184 |
"read from self" |
185 |
||
11766 | 186 |
^ self |
21472 | 187 |
|
188 |
"Modified (comment): / 16-02-2017 / 15:59:52 / stefan" |
|
11766 | 189 |
! |
190 |
||
8047 | 191 |
stream |
192 |
^ stream |
|
193 |
! |
|
194 |
||
195 |
stream:something |
|
196 |
stream := something. |
|
197 |
! ! |
|
198 |
||
21472 | 199 |
!EncodedStream methodsFor:'chunk input/output'! |
15963 | 200 |
|
21472 | 201 |
nextChunk |
23988 | 202 |
"reads a smalltalk chunk. |
203 |
as a side effect, check for an encoding chunk" |
|
21472 | 204 |
|
22415 | 205 |
|chunk| |
15963 | 206 |
|
22415 | 207 |
chunk := super nextChunk. |
15963 | 208 |
|
22415 | 209 |
(encoder isNullEncoder and:[stream isPositionable not]) ifTrue:[ |
210 |
"/ encoding not already checked |
|
21472 | 211 |
"/ check if we need lazy setup of the encoder |
212 |
"/ (used with non-positionable streams) |
|
22415 | 213 |
"/ encoder for PositionableStream is set up in self class decodedStreamFor: |
214 |
(chunk notNil and:[chunk includesString:'{ Encoding:']) ifTrue:[ |
|
21472 | 215 |
|enc| |
15963 | 216 |
|
21472 | 217 |
enc := self class encoderFor:(CharacterEncoder guessEncodingOfBuffer:chunk). |
218 |
enc notNil ifTrue:[ |
|
22415 | 219 |
encoder := enc. |
220 |
^ encoder decodeString:chunk. |
|
21472 | 221 |
]. |
22415 | 222 |
]. |
15963 | 223 |
]. |
224 |
||
22415 | 225 |
^ chunk. |
226 |
||
227 |
"Modified (format): / 04-01-2018 / 00:33:57 / stefan" |
|
15963 | 228 |
! ! |
229 |
||
21642 | 230 |
!EncodedStream methodsFor:'queries'! |
231 |
||
22415 | 232 |
contentsSpecies |
233 |
^ String |
|
234 |
||
235 |
"Created: / 14-06-2005 / 17:11:01 / janfrog" |
|
236 |
"Modified: / 10-01-2018 / 11:43:57 / stefan" |
|
237 |
! |
|
238 |
||
21642 | 239 |
isEncoderFor:encodingString |
240 |
^ encoder isEncoderFor:encodingString |
|
241 |
||
242 |
"Created: / 13-03-2017 / 11:20:20 / stefan" |
|
243 |
! ! |
|
244 |
||
8047 | 245 |
!EncodedStream methodsFor:'stream protocol'! |
246 |
||
8175 | 247 |
atEnd |
22415 | 248 |
^ peekChar isNil and:[stream atEnd] |
249 |
||
250 |
"Modified: / 02-01-2018 / 21:47:17 / stefan" |
|
8175 | 251 |
! |
252 |
||
8165 | 253 |
close |
22415 | 254 |
peekChar := nil. |
8165 | 255 |
stream close |
22415 | 256 |
|
257 |
"Modified: / 09-01-2018 / 18:33:01 / stefan" |
|
8165 | 258 |
! |
259 |
||
21521 | 260 |
collection |
21522 | 261 |
"return the underlying container; nil, if there is none (eg. external streams). |
262 |
Here we return nil, as the underlying collection (if any) is useless to the outside world" |
|
21521 | 263 |
|
21522 | 264 |
^ nil |
21521 | 265 |
|
266 |
"Created: / 22-02-2017 / 11:15:00 / cg" |
|
267 |
! |
|
268 |
||
13400 | 269 |
contents |
22415 | 270 |
^String streamContents:[:s| |
271 |
[self atEnd] whileFalse:[ |
|
18157 | 272 |
|ch| |
273 |
ch := self next. |
|
274 |
"/ decoder may decide to return nil from #next, even though the |
|
275 |
"/ underlying stream was not at the end before. This is probably a bug... |
|
276 |
ch notNil ifTrue:[ |
|
277 |
s nextPut: ch |
|
278 |
] |
|
13400 | 279 |
] |
18157 | 280 |
] |
13400 | 281 |
|
282 |
"Created: / 25-02-2010 / 23:34:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
22415 | 283 |
"Modified (format): / 02-01-2018 / 19:35:10 / stefan" |
8213 | 284 |
! |
285 |
||
11992 | 286 |
emphasis:anObject |
287 |
||
288 |
stream emphasis:anObject |
|
289 |
||
290 |
"Created: / 15-06-2005 / 11:16:33 / janfrog" |
|
291 |
! |
|
292 |
||
15477 | 293 |
flush |
22415 | 294 |
peekChar := nil. |
15477 | 295 |
stream flush |
22415 | 296 |
|
297 |
"Modified: / 02-01-2018 / 19:17:40 / stefan" |
|
15477 | 298 |
! |
299 |
||
20363 | 300 |
isEmpty |
22415 | 301 |
^ stream isEmptyOrNil. |
20363 | 302 |
|
22415 | 303 |
"Modified: / 02-01-2018 / 19:59:09 / stefan" |
11946 | 304 |
! |
305 |
||
11766 | 306 |
next |
22415 | 307 |
peekChar notNil ifTrue:[ |
308 |
|p| |
|
309 |
p := peekChar. |
|
310 |
peekChar := nil. |
|
311 |
^ p. |
|
312 |
]. |
|
313 |
^ encoder readNextCharacterFrom:stream |
|
11992 | 314 |
|
315 |
"Created: / 14-06-2005 / 17:01:39 / janfrog" |
|
22415 | 316 |
"Modified: / 02-01-2018 / 19:19:29 / stefan" |
11992 | 317 |
! |
11766 | 318 |
|
22415 | 319 |
next:nCharactersToRead |
320 |
|chars| |
|
11992 | 321 |
|
22415 | 322 |
nCharactersToRead == 1 ifTrue:[ |
323 |
^ self next. |
|
324 |
]. |
|
325 |
nCharactersToRead == 0 ifTrue:[ |
|
326 |
^ ''. |
|
327 |
]. |
|
328 |
||
329 |
peekChar isNil ifTrue:[ |
|
330 |
^ encoder readNext:nCharactersToRead charactersFrom:stream. |
|
331 |
]. |
|
332 |
||
333 |
chars := encoder readNext:nCharactersToRead-1 charactersFrom:stream. |
|
334 |
chars := chars copyWithFirst:peekChar. |
|
335 |
peekChar := nil. |
|
336 |
^ chars. |
|
11992 | 337 |
|
338 |
"Created: / 16-06-2005 / 11:43:43 / masca" |
|
22415 | 339 |
"Modified: / 03-01-2018 / 22:22:51 / stefan" |
11766 | 340 |
! |
341 |
||
21472 | 342 |
nextPut:aCharacter |
343 |
encoder encodeCharacter:aCharacter on:stream. |
|
8175 | 344 |
|
21472 | 345 |
"Modified: / 16-02-2017 / 16:22:23 / stefan" |
8047 | 346 |
! |
347 |
||
348 |
nextPutAll:aCollection |
|
17668 | 349 |
encoder encodeString:aCollection on:stream |
8147 | 350 |
! |
351 |
||
17331 | 352 |
nextPutAll:aCollection startingAt:start to:stop |
24030 | 353 |
"append the elements from first index to last index |
354 |
of the argument, aCollection onto the receiver (i.e. both outstreams)" |
|
355 |
||
17668 | 356 |
encoder encodeString:(aCollection copyFrom:start to:stop) on:stream. |
24030 | 357 |
|
358 |
"Modified (comment): / 01-04-2019 / 17:13:01 / Claus Gittinger" |
|
17331 | 359 |
! |
360 |
||
8444 | 361 |
peek |
22415 | 362 |
peekChar isNil ifTrue:[ |
363 |
peekChar := self next. |
|
364 |
]. |
|
365 |
^ peekChar |
|
11992 | 366 |
|
367 |
"Created: / 20-06-2005 / 10:13:03 / masca" |
|
368 |
"Modified: / 20-06-2005 / 13:06:14 / masca" |
|
22415 | 369 |
"Modified (format): / 02-01-2018 / 19:21:00 / stefan" |
8175 | 370 |
! |
371 |
||
8165 | 372 |
position |
22415 | 373 |
"only use #position/#position: to restore a previous position. |
374 |
Computing relative positions does not work!!" |
|
375 |
||
22421 | 376 |
|pos| |
22415 | 377 |
|
22421 | 378 |
pos := stream position. |
379 |
peekChar notNil ifTrue:[ |
|
380 |
"#position: nils peekChar - make sure, that it positions before peekChar" |
|
22423 | 381 |
pos := pos - (encoder characterSize:peekChar). |
22421 | 382 |
]. |
383 |
^ pos. |
|
384 |
||
22423 | 385 |
"Modified: / 15-01-2018 / 22:42:01 / stefan" |
8165 | 386 |
! |
387 |
||
8197 | 388 |
position0Based |
15618 | 389 |
<resource: #obsolete> |
11947 | 390 |
"to be obsoleted - use position" |
391 |
||
15618 | 392 |
^ stream position |
8197 | 393 |
! |
394 |
||
395 |
position0Based:newPosition |
|
15618 | 396 |
<resource: #obsolete> |
11947 | 397 |
"to be obsoleted - use position" |
398 |
||
15618 | 399 |
stream position:newPosition |
8197 | 400 |
! |
401 |
||
8175 | 402 |
position1Based |
15618 | 403 |
<resource: #obsolete> |
11947 | 404 |
"to be obsoleted - use position" |
405 |
||
22415 | 406 |
^ stream position1Based |
407 |
||
408 |
"Modified: / 02-01-2018 / 20:00:57 / stefan" |
|
8175 | 409 |
! |
410 |
||
8147 | 411 |
position1Based:newPosition |
15618 | 412 |
<resource: #obsolete> |
11947 | 413 |
"to be obsoleted - use position" |
414 |
||
22415 | 415 |
stream position1Based:newPosition |
416 |
||
417 |
"Modified: / 02-01-2018 / 20:00:46 / stefan" |
|
8175 | 418 |
! |
419 |
||
8197 | 420 |
position:newPosition |
22415 | 421 |
"only use #position/#position: to restore a previous position. |
422 |
Computing relative positions does not work!! |
|
423 |
Use #skip: to advance forward." |
|
424 |
||
425 |
peekChar := nil. |
|
8197 | 426 |
stream position:newPosition |
22415 | 427 |
|
428 |
"Modified (comment): / 09-01-2018 / 17:53:04 / stefan" |
|
8197 | 429 |
! |
430 |
||
13400 | 431 |
reset |
22415 | 432 |
peekChar := nil. |
13400 | 433 |
stream reset |
434 |
||
435 |
"Created: / 25-02-2010 / 23:37:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
22415 | 436 |
"Modified: / 02-01-2018 / 19:34:20 / stefan" |
13400 | 437 |
! |
438 |
||
8213 | 439 |
setToEnd |
22415 | 440 |
peekChar := nil. |
8213 | 441 |
stream setToEnd |
22415 | 442 |
|
443 |
"Modified (comment): / 09-01-2018 / 17:50:27 / stefan" |
|
8213 | 444 |
! |
445 |
||
14333 | 446 |
size |
20363 | 447 |
"not always correct, but probably better than 0. |
448 |
Better use #isEmpty." |
|
14333 | 449 |
|
15585 | 450 |
"/ is that better? |
451 |
"/ self error:'size of input is unknown (due to decoding)' |
|
14333 | 452 |
^ stream size |
453 |
||
454 |
"Created: / 31-08-2012 / 16:52:40 / cg" |
|
455 |
! |
|
456 |
||
23988 | 457 |
skip:nrToSkip |
24000 | 458 |
"/ can only skip forward |
459 |
nrToSkip < 0 ifTrue:[ |
|
460 |
self proceedableError:'cannot position backwards'. |
|
23988 | 461 |
^ self. |
462 |
]. |
|
24000 | 463 |
nrToSkip timesRepeat:[self next] |
23988 | 464 |
! |
465 |
||
15477 | 466 |
sync |
467 |
stream sync |
|
468 |
! |
|
469 |
||
470 |
syncData |
|
471 |
stream syncData |
|
8047 | 472 |
! ! |
473 |
||
15049 | 474 |
!EncodedStream methodsFor:'testing'! |
475 |
||
476 |
isEncodedStream |
|
477 |
^ true |
|
15963 | 478 |
|
479 |
"Created: / 04-02-2014 / 20:27:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
15592 | 480 |
! |
481 |
||
22415 | 482 |
isOpen |
483 |
"for compatibility with externalStream: |
|
484 |
return true, if this stream is open." |
|
485 |
||
486 |
^ stream notNil and:[stream isOpen]. |
|
487 |
||
488 |
"Modified (comment): / 09-01-2018 / 18:34:47 / stefan" |
|
489 |
! |
|
490 |
||
16258
1582c656cdb0
Added EncodedStream>>isPositionable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15963
diff
changeset
|
491 |
isPositionable |
1582c656cdb0
Added EncodedStream>>isPositionable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15963
diff
changeset
|
492 |
^ stream isPositionable |
1582c656cdb0
Added EncodedStream>>isPositionable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15963
diff
changeset
|
493 |
|
1582c656cdb0
Added EncodedStream>>isPositionable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15963
diff
changeset
|
494 |
"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
|
495 |
! |
1582c656cdb0
Added EncodedStream>>isPositionable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
15963
diff
changeset
|
496 |
|
15592 | 497 |
isReadable |
498 |
^ stream isReadable |
|
499 |
! |
|
500 |
||
501 |
isWritable |
|
502 |
^ stream isWritable |
|
15049 | 503 |
! ! |
504 |
||
8712
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
505 |
!EncodedStream methodsFor:'utilities'! |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
506 |
|
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
507 |
skipEncodingChunk |
14091 | 508 |
|pos chunk token| |
8712
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
509 |
|
13525
e17ebc11ca73
changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents:
13400
diff
changeset
|
510 |
stream isPositionable ifFalse:[ |
e17ebc11ca73
changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents:
13400
diff
changeset
|
511 |
^ self |
e17ebc11ca73
changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents:
13400
diff
changeset
|
512 |
]. |
e17ebc11ca73
changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents:
13400
diff
changeset
|
513 |
|
8712
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
514 |
pos := self position. |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
515 |
chunk := self nextChunk. |
14084 | 516 |
[ |
517 |
"/ if this is a valid chunk (i.e. not a comment or encoding-directive), |
|
518 |
"/ then position back, so it will be processed as usual. |
|
14091 | 519 |
"/ We could parse here, but this is overkill, since we are only interested in the fact, |
520 |
"/ that there is anything else than a comment in the chunk. |
|
521 |
"/ result := (Parser for:chunk) |
|
522 |
"/ ignoreErrors:true; |
|
523 |
"/ ignoreWarnings:true; |
|
524 |
"/ parseMethodBody. |
|
525 |
||
526 |
token := (Scanner for:chunk) |
|
527 |
ignoreErrors:true; |
|
528 |
ignoreWarnings:true; |
|
529 |
nextToken. |
|
530 |
||
531 |
token ~= #EOF ifTrue:[ |
|
14084 | 532 |
self position:pos |
533 |
]. |
|
14086 | 534 |
] on:Parser parseWarningSignal do:[:ex| |
14084 | 535 |
"really ignore any error. |
21472 | 536 |
Even setting ignoreError will output diagnostics here |
14084 | 537 |
during standalone startup when debugging" |
14086 | 538 |
ex proceedWith:#ignore. |
14084 | 539 |
]. |
13525
e17ebc11ca73
changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents:
13400
diff
changeset
|
540 |
|
e17ebc11ca73
changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents:
13400
diff
changeset
|
541 |
"Modified: / 29-07-2011 / 17:42:11 / cg" |
21472 | 542 |
"Modified (format): / 16-02-2017 / 16:01:09 / stefan" |
8712
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
543 |
! ! |
bcef3a0c0a1d
skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents:
8459
diff
changeset
|
544 |
|
8047 | 545 |
!EncodedStream class methodsFor:'documentation'! |
546 |
||
14086 | 547 |
version |
18763 | 548 |
^ '$Header$' |
14086 | 549 |
! |
550 |
||
13400 | 551 |
version_CVS |
18763 | 552 |
^ '$Header$' |
12610 | 553 |
! |
554 |
||
13400 | 555 |
version_SVN |
15345 | 556 |
^ '$ Id: EncodedStream.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
8047 | 557 |
! ! |
15049 | 558 |