#REFACTORING by cg
class: Stream
changed:
#nextPutUtf16:
#nextPutUtf16Bytes:MSB:
--- a/Stream.st Wed Nov 02 14:09:49 2016 +0100
+++ b/Stream.st Wed Nov 02 15:21:53 2016 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
@@ -225,7 +223,6 @@
self nextPutAll: someObject asString.
! !
-
!Stream methodsFor:'Compatibility-VW'!
nl
@@ -235,7 +232,6 @@
self nextPut:(Character nl)
! !
-
!Stream methodsFor:'accessing'!
contents
@@ -2035,7 +2031,7 @@
"
(#[] writeStream
- nextPutAllUtf16Bytes:'BÄxxx' MSB:true;
+ nextPutAllUtf16Bytes:'BÄxxx' MSB:true;
nextPutUtf16:(Character codePoint:16r10CCCC) MSB:true;
contents)
"
@@ -2435,25 +2431,28 @@
|codePoint "{Class: SmallInteger}"|
codePoint := aCharacter codePoint.
- (codePoint <= 16rD7FF
- or:[codePoint >= 16rE000 and:[codePoint <= 16rFFFF]]) ifTrue:[
- self nextPut:aCharacter.
- ] ifFalse:[codePoint <= 16r10FFFF ifTrue:[
- |highBits lowBits|
-
- codePoint := codePoint - 16r100000.
- highBits := codePoint bitShift:-10.
- lowBits := codePoint bitAnd:16r3FF.
- self nextPut:(Character codePoint:highBits+16rD800).
- self nextPut:(Character codePoint:lowBits+16rDC00).
- ] ifFalse:[
- EncodingError raiseWith:aCharacter errorString:'Character cannot be encoded as UTF-16'.
- ]].
+ (codePoint <= 16rD7FF or:[codePoint between:16rE000 and:16rFFFF])
+ ifTrue:[
+ self nextPut:aCharacter.
+ ]
+ ifFalse:[
+ codePoint <= 16r10FFFF ifTrue:[
+ |highBits lowBits|
+
+ codePoint := codePoint - 16r100000.
+ highBits := codePoint bitShift:-10.
+ lowBits := codePoint bitAnd:16r3FF.
+ self nextPut:(Character codePoint:highBits+16rD800).
+ self nextPut:(Character codePoint:lowBits+16rDC00).
+ ] ifFalse:[
+ EncodingError raiseWith:aCharacter errorString:'Character cannot be encoded as UTF-16'.
+ ]
+ ].
"
((WriteStream on:Unicode16String new)
nextPutUtf16:$B;
- nextPutUtf16:$Ä;
+ nextPutUtf16:$Ä;
nextPutUtf16:(Character codePoint:16r10CCCC)
yourself) contents
"
@@ -2464,37 +2463,38 @@
UTF-16 can encode only characters with code points between 0 to 16r10FFFF.
The underlying stream must support writing of bytes."
- |codePoint|
+ |codePoint "{ Class: SmallInteger }"|
codePoint := aCharacter codePoint.
- (codePoint <= 16rD7FF
- or:[ codePoint >= 16rE000 and:[ codePoint <= 16rFFFF ] ])
- ifTrue:[ self nextPutInt16:codePoint MSB:msb. ]
- ifFalse:[
- codePoint <= 16r10FFFF ifTrue:[
- |highBits lowBits|
-
- codePoint := codePoint - 16r100000.
- highBits := codePoint bitShift:-10.
- lowBits := codePoint bitAnd:16r3FF.
- self nextPutInt16:highBits + 16rD800 MSB:msb.
- self nextPutInt16:lowBits + 16rDC00 MSB:msb.
- ] ifFalse:[
- EncodingError raiseWith:aCharacter
- errorString:'Character cannot be encoded as UTF-16'.
- ]
- ].
+ (codePoint <= 16rD7FF or:[ codePoint between:16rE000 and:16rFFFF ])
+ ifTrue:[
+ self nextPutInt16:codePoint MSB:msb.
+ ]
+ ifFalse:[
+ codePoint <= 16r10FFFF ifTrue:[
+ |highBits lowBits|
+
+ codePoint := codePoint - 16r100000.
+ highBits := codePoint bitShift:-10.
+ lowBits := codePoint bitAnd:16r3FF.
+ self nextPutInt16:(highBits + 16rD800) MSB:msb.
+ self nextPutInt16:(lowBits + 16rDC00) MSB:msb.
+ ] ifFalse:[
+ EncodingError raiseWith:aCharacter
+ errorString:'Character cannot be encoded as UTF-16'.
+ ]
+ ].
"
(#[] writeStream
nextPutUtf16:$B MSB:true;
- nextPutUtf16:$Ä MSB:true;
+ nextPutUtf16:$Ä MSB:true;
nextPutUtf16:(Character codePoint:16r10CCCC) MSB:true;
contents)
(FileStream newTemporary
nextPutUtf16:$B MSB:false;
- nextPutUtf16:$Ä MSB:false;
+ nextPutUtf16:$Ä MSB:false;
nextPutUtf16:(Character codePoint:16r10CCCC) MSB:false;
reset;
binary;
@@ -2559,7 +2559,7 @@
"
(String streamContents:[:s|
s nextPutUtf8:$a.
- s nextPutUtf8:$ü.
+ s nextPutUtf8:$ü.
s nextPutUtf8: (Character value:16r1fff).
s nextPutUtf8: (Character value:16rffff).
s nextPutUtf8: (Character value:16r1ffffff).