--- a/CharacterEncoderImplementations__TwoByteEncoder.st Fri Jan 19 14:44:22 2018 +0100
+++ b/CharacterEncoderImplementations__TwoByteEncoder.st Fri Jan 19 14:44:37 2018 +0100
@@ -15,7 +15,7 @@
"{ NameSpace: CharacterEncoderImplementations }"
-CharacterEncoder subclass:#TwoByteEncoder
+FixedBytesEncoder subclass:#TwoByteEncoder
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
@@ -56,10 +56,25 @@
maxCode
^ 16rFFFF
-!
+! !
+
+!TwoByteEncoder methodsFor:'encoding & decoding'!
+
+encodeString:aUnicodeString
+ "given a string in unicode, return a string in my encoding for it"
+
+ |newString myCode stringSize "{ Class: SmallInteger }"|
-minCode
- ^ 0
+ stringSize := aUnicodeString size.
+ newString := self newString:stringSize.
+
+ 1 to:stringSize do:[:idx |
+ myCode := self encode:((aUnicodeString at:idx) codePoint).
+ newString at:idx put:(Character codePoint:myCode).
+ ].
+ ^ newString
+
+ "Created: / 17-01-2018 / 16:33:52 / stefan"
! !
!TwoByteEncoder methodsFor:'queries'!
@@ -67,24 +82,43 @@
characterSize:charOrCodePoint
"return the number of bytes required to encode codePoint"
- ^2
+ ^ 2
"Created: / 15-06-2005 / 15:12:01 / janfrog"
+ "Modified (format): / 16-01-2018 / 22:32:03 / stefan"
+!
+
+newString:size
+ ^ TwoByteString new:size.
+
+ "Created: / 17-01-2018 / 16:36:56 / stefan"
! !
!TwoByteEncoder methodsFor:'stream support'!
-readNextCharacterFrom:aStream
- | c |
+encodeCharacter:aUnicodeCharacterOrCodePoint on:aStream
+ "given a character in unicode, encode it onto aStream.
+ Subclasses can redefine this to avoid allocating many new string instances."
+
+ aStream nextPutInt16:(self encode:aUnicodeCharacterOrCodePoint codePoint) MSB:false.
- c := aStream nextUnsignedInt16MSB:false.
- ^ c isNil
- ifTrue: [nil]
- ifFalse: [(self decode:c) asCharacter]
+ "
+ CharacterEncoderImplementations::ISO8859_10 new encodeCharacter:260 on:Transcript
+ CharacterEncoderImplementations::ISO8859_10 new encodeCharacter:$Ą on:Transcript
+ "
+
+ "Created: / 17-01-2018 / 16:41:09 / stefan"
!
-readNextInputCharacterFrom:aStream
- ^ aStream nextUnsignedInt16MSB:false
+readNextCharacterFrom:aStream
+ | codePoint |
+
+ codePoint := aStream nextUnsignedInt16MSB:false.
+ ^ codePoint isNil
+ ifTrue: [nil]
+ ifFalse: [Character codePoint:codePoint]
+
+ "Modified: / 16-01-2018 / 22:30:36 / stefan"
! !
!TwoByteEncoder class methodsFor:'documentation'!