equal
deleted
inserted
replaced
|
1 "{ Encoding: utf8 }" |
|
2 |
1 " |
3 " |
2 COPYRIGHT (c) 2004 by eXept Software AG |
4 COPYRIGHT (c) 2004 by eXept Software AG |
3 All Rights Reserved |
5 All Rights Reserved |
4 |
6 |
5 This software is furnished under a license and may be used |
7 This software is furnished under a license and may be used |
9 other person. No title to or ownership of the software is |
11 other person. No title to or ownership of the software is |
10 hereby transferred. |
12 hereby transferred. |
11 " |
13 " |
12 "{ Package: 'stx:libbasic' }" |
14 "{ Package: 'stx:libbasic' }" |
13 |
15 |
|
16 "{ NameSpace: Smalltalk }" |
|
17 |
14 PeekableStream subclass:#EncodedStream |
18 PeekableStream subclass:#EncodedStream |
15 instanceVariableNames:'encoder stream' |
19 instanceVariableNames:'encoder stream' |
16 classVariableNames:'' |
20 classVariableNames:'' |
17 poolDictionaries:'' |
21 poolDictionaries:'' |
18 category:'Collections-Text-Encodings' |
22 category:'Collections-Text-Encodings' |
45 |
49 |
46 !EncodedStream class methodsFor:'instance creation'! |
50 !EncodedStream class methodsFor:'instance creation'! |
47 |
51 |
48 stream:streamArg encoder:encoder |
52 stream:streamArg encoder:encoder |
49 ^ (self basicNew) stream:streamArg; encoder:encoder |
53 ^ (self basicNew) stream:streamArg; encoder:encoder |
|
54 |
|
55 " |
|
56 |s| |
|
57 s := EncodedStream stream:Transcript encoder:(CharacterEncoder encoderToEncodeFrom:#utf8 into:#unicode). |
|
58 s nextPutAll:('öäü' utf8Encoded) |
|
59 " |
|
60 ! ! |
|
61 |
|
62 !EncodedStream class methodsFor:'Compatibility-VW5.4'! |
|
63 |
|
64 on: aStream encodedBy: aStreamEncoder |
|
65 |
|
66 ^self basicNew on: aStream encodedBy: aStreamEncoder |
50 ! ! |
67 ! ! |
51 |
68 |
52 !EncodedStream class methodsFor:'utilities'! |
69 !EncodedStream class methodsFor:'utilities'! |
53 |
70 |
54 decodedStreamFor:aStream |
71 decodedStreamFor:aStream |
77 decodedStream := self stream:aStream encoder:CharacterEncoder nullEncoderInstance. |
94 decodedStream := self stream:aStream encoder:CharacterEncoder nullEncoderInstance. |
78 ]. |
95 ]. |
79 ^ decodedStream |
96 ^ decodedStream |
80 |
97 |
81 "Modified: / 23-08-2013 / 17:30:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
98 "Modified: / 23-08-2013 / 17:30:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
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. |
|
108 ! ! |
|
109 |
|
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 |
82 ! ! |
125 ! ! |
83 |
126 |
84 !EncodedStream methodsFor:'accessing'! |
127 !EncodedStream methodsFor:'accessing'! |
85 |
128 |
86 contentsSpecies |
129 contentsSpecies |
298 stream close |
341 stream close |
299 ! |
342 ! |
300 |
343 |
301 contents |
344 contents |
302 |
345 |
303 ^String streamContents: |
346 ^String streamContents: [:s| |
304 [:s| |
347 [ self atEnd ] whileFalse:[ |
305 [ stream atEnd ] whileFalse: |
348 |ch| |
306 [s nextPut: stream next] |
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 ] |
307 ] |
355 ] |
|
356 ] |
308 |
357 |
309 "Created: / 25-02-2010 / 23:34:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
358 "Created: / 25-02-2010 / 23:34:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
310 ! |
359 ! |
311 |
360 |
312 cr |
361 cr |
375 nextPut:aCharacter |
424 nextPut:aCharacter |
376 self nextPutAll:(aCharacter asString). |
425 self nextPutAll:(aCharacter asString). |
377 ! |
426 ! |
378 |
427 |
379 nextPutAll:aCollection |
428 nextPutAll:aCollection |
380 stream nextPutAll:(encoder encodeString:aCollection). |
429 encoder encodeString:aCollection on:stream |
|
430 ! |
|
431 |
|
432 nextPutAll:aCollection startingAt:start to:stop |
|
433 encoder encodeString:(aCollection copyFrom:start to:stop) on:stream. |
381 ! |
434 ! |
382 |
435 |
383 peek |
436 peek |
384 |
437 |
385 ^stream peek |
438 ^stream peek |
472 |
525 |
473 isEncodedStream |
526 isEncodedStream |
474 ^ true |
527 ^ true |
475 |
528 |
476 "Created: / 04-02-2014 / 20:27:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
529 "Created: / 04-02-2014 / 20:27:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
530 ! |
|
531 |
|
532 isPositionable |
|
533 ^ stream isPositionable |
|
534 |
|
535 "Created: / 14-03-2014 / 16:18:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
477 ! |
536 ! |
478 |
537 |
479 isReadable |
538 isReadable |
480 ^ stream isReadable |
539 ^ stream isReadable |
481 ! |
540 ! |
524 ! ! |
583 ! ! |
525 |
584 |
526 !EncodedStream class methodsFor:'documentation'! |
585 !EncodedStream class methodsFor:'documentation'! |
527 |
586 |
528 version |
587 version |
529 ^ '$Header: /cvs/stx/stx/libbasic/EncodedStream.st,v 1.34 2013-08-21 14:07:18 stefan Exp $' |
588 ^ '$Header: /cvs/stx/stx/libbasic/EncodedStream.st,v 1.41 2015-03-26 16:20:12 cg Exp $' |
530 ! |
589 ! |
531 |
590 |
532 version_CVS |
591 version_CVS |
533 ^ '$Header: /cvs/stx/stx/libbasic/EncodedStream.st,v 1.34 2013-08-21 14:07:18 stefan Exp $' |
592 ^ '$Header: /cvs/stx/stx/libbasic/EncodedStream.st,v 1.41 2015-03-26 16:20:12 cg Exp $' |
534 ! |
|
535 |
|
536 version_HG |
|
537 |
|
538 ^ '$Changeset: <not expanded> $' |
|
539 ! |
593 ! |
540 |
594 |
541 version_SVN |
595 version_SVN |
542 ^ '$ Id: EncodedStream.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
596 ^ '$ Id: EncodedStream.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
543 ! ! |
597 ! ! |