#REFACTORING by stefan
authorStefan Vogel <sv@exept.de>
Fri, 19 Jan 2018 14:43:55 +0100
changeset 22476 b30058f26971
parent 22475 71b77246e002
child 22477 5b8c1f5f8ffa
#REFACTORING by stefan class: CharacterEncoderImplementations::ISO10646_to_JavaText class definition added: #characterSize: #readNextCharacterFrom: removed: #decode: #encode: changed: #decodeString:
CharacterEncoderImplementations__ISO10646_to_JavaText.st
--- a/CharacterEncoderImplementations__ISO10646_to_JavaText.st	Fri Jan 19 14:43:38 2018 +0100
+++ b/CharacterEncoderImplementations__ISO10646_to_JavaText.st	Fri Jan 19 14:43:55 2018 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 2006 by eXept Software AG
               All Rights Reserved
@@ -13,7 +15,7 @@
 
 "{ NameSpace: CharacterEncoderImplementations }"
 
-TwoByteEncoder subclass:#ISO10646_to_JavaText
+VariableBytesEncoder subclass:#ISO10646_to_JavaText
 	instanceVariableNames:''
 	classVariableNames:''
 	poolDictionaries:''
@@ -44,23 +46,19 @@
 
 !ISO10646_to_JavaText methodsFor:'encoding & decoding'!
 
-decode:aCode
-    self shouldNotImplement "/ no single byte conversion possible
-!
-
 decodeString:aStringOrByteCollection
     "given a string in JavaText encoding (i.e. with \uXXXX escaped characters),
      return a new string containing the same characters, in 16bit (or more) encoding.
-     Returns either a normal String, a TwoByteString or a FourByteString instance.
+     Returns either a normal String, a Unicode16String or a Unicode32String instance.
      Only useful, when reading Java property and resource files.
      This only handles up-to 30bit characters."
 
     |nBits ch 
-     in out codePoint t|
+     in out codePoint|
 
     nBits := 8.
     in := aStringOrByteCollection readStream.
-    out := WriteStream on:(String new:10).
+    out := CharacterWriteStream on:(String new:10).
     [in atEnd] whileFalse:[
         ch := in next.
         ch == $\ ifTrue:[
@@ -68,28 +66,9 @@
                 in next.
                 codePoint := 0.
                 4 timesRepeat:[
-                    ch := in peekOrNil.
-                    codePoint := (codePoint * 16) + ch digitValue.
-                    in next.
+                    codePoint := (codePoint * 16) + in next digitValue.
                 ].
-                codePoint > 16rFF ifTrue:[
-                    codePoint > 16rFFFF ifTrue:[
-                        nBits < 32 ifTrue:[
-                            t := out contents.
-                            out := WriteStream on:(Unicode32String fromString:t).
-                            out position:t size.
-                            nBits := 32.
-                        ]
-                    ] ifFalse:[
-                        nBits < 16 ifTrue:[
-                            t := out contents.
-                            out := WriteStream on:(Unicode16String fromString:t).
-                            out position:t size.
-                            nBits := 16.
-                        ]
-                    ]
-                ].
-                out nextPut:(Character value:codePoint).
+                out nextPut:(Character codePoint:codePoint).
             ] ifFalse:[
                 out nextPut:ch
             ]
@@ -105,10 +84,7 @@
     "
 
     "Modified: / 23-10-2006 / 13:23:18 / cg"
-!
-
-encode:aCode
-    self shouldNotImplement "/ no single byte conversion possible
+    "Modified: / 17-01-2018 / 18:34:52 / stefan"
 !
 
 encodeString:aUnicodeString
@@ -143,13 +119,43 @@
     "Modified: / 23-10-2006 / 13:25:03 / cg"
 ! !
 
+!ISO10646_to_JavaText methodsFor:'queries'!
+
+characterSize:aCharacter
+    (aCharacter codePoint between:16r20 and:16r7F) ifTrue:[
+        ^ 1.
+    ].
+    ^ 6    "\u1234"
+
+    "Created: / 17-01-2018 / 17:58:59 / stefan"
+! !
+
+!ISO10646_to_JavaText methodsFor:'stream support'!
+
+readNextCharacterFrom:aStream
+    |char codePoint|
+
+    char := aStream next.
+    (char ~~ $\ and:[aStream peek ~~ $u]) ifTrue:[
+        ^ char.
+    ].
+    aStream next.
+    codePoint := 0.
+    4 timesRepeat:[
+        codePoint := (codePoint * 16) + aStream next digitValue.
+    ].
+    ^ Character codePoint:codePoint.
+
+    "Created: / 17-01-2018 / 18:33:22 / stefan"
+! !
+
 !ISO10646_to_JavaText class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterEncoderImplementations__ISO10646_to_JavaText.st,v 1.1 2014-02-05 17:11:06 cg Exp $'
+    ^ '$Header$'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterEncoderImplementations__ISO10646_to_JavaText.st,v 1.1 2014-02-05 17:11:06 cg Exp $'
+    ^ '$Header$'
 ! !