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