CharacterEncoderImplementations__ISO10646_to_UTF16BE.st
branchjv
changeset 17951 fa0e1d7467ea
parent 17941 3651a18f3703
child 18011 deb0c3355881
--- a/CharacterEncoderImplementations__ISO10646_to_UTF16BE.st	Thu Jul 05 11:45:05 2012 +0100
+++ b/CharacterEncoderImplementations__ISO10646_to_UTF16BE.st	Wed Jul 18 17:55:48 2012 +0100
@@ -13,7 +13,7 @@
 
 "{ NameSpace: CharacterEncoderImplementations }"
 
-TwoByteEncoder subclass:#ISO10646_to_UTF16BE
+CharacterEncoderImplementations::TwoByteEncoder subclass:#'ISO10646_to_UTF16BE'
 	instanceVariableNames:''
 	classVariableNames:''
 	poolDictionaries:''
@@ -69,13 +69,13 @@
 !
 
 decodeString:aStringOrByteCollection
-    "given a byteArray (2-bytes per character) or unsignedShortArra in UTF16 encoding,
+    "given a byteArray (2-bytes per character) or unsignedShortArray in UTF16 encoding,
      return a new string containing the same characters, in 8, 16bit (or more) encoding.
      Returns either a normal String, a TwoByte- or a FourByte-String instance.
      Only useful, when reading from external sources.
      This only handles up-to 30bit characters."
 
-    |sz nBitsRequired s newString idx bitsPerElementIn nextIn
+    |s newString bitsPerElementIn nextIn
      codeIn codeIn1 codeIn2 estimatedSize out|
 
     aStringOrByteCollection isByteArray ifTrue:[
@@ -84,18 +84,22 @@
         aStringOrByteCollection isString ifTrue:[
             bitsPerElementIn := aStringOrByteCollection bitsPerCharacter.
         ] ifFalse:[
+            "can be a ShortArray"
             bitsPerElementIn := 16.
         ].
     ].
-    estimatedSize := aStringOrByteCollection size * bitsPerElementIn // 16.
 
+    s := aStringOrByteCollection readStream.
     bitsPerElementIn == 8 ifTrue:[
+        s size odd ifTrue:[
+            InvalidEncodingError raiseWith:aStringOrByteCollection errorString:' - size is not a multiple of 2 bytes'.
+        ].
         nextIn := [self nextTwoByteValueFrom:s].
     ] ifFalse:[
         nextIn := [s next].
     ].
 
-    s := aStringOrByteCollection readStream.
+    estimatedSize := s size * bitsPerElementIn // 16.
     out := CharacterWriteStream on:(String new:estimatedSize).
     [s atEnd] whileFalse:[
         codeIn := nextIn value.
@@ -181,6 +185,8 @@
                               16r0021  
                             )
     "
+
+    "Modified: / 12-07-2012 / 19:56:12 / cg"
 !
 
 encode:aCode
@@ -258,19 +264,19 @@
 !ISO10646_to_UTF16BE methodsFor:'queries'!
 
 nameOfEncoding
-    ^ #'utf8be'
+    ^ #utf16be
 ! !
 
 !ISO10646_to_UTF16BE class methodsFor:'documentation'!
 
 version
-    ^ '$Id: CharacterEncoderImplementations__ISO10646_to_UTF16BE.st 10808 2012-05-09 15:04:12Z vranyj1 $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterEncoderImplementations__ISO10646_to_UTF16BE.st,v 1.6 2012/07/12 18:07:54 cg Exp $'
 !
 
 version_CVS
-    ^ '§Header: /cvs/stx/stx/libbasic/CharacterEncoderImplementations__ISO10646_to_UTF16BE.st,v 1.3 2009/11/04 00:46:08 cg Exp §'
+    ^ '§Header: /cvs/stx/stx/libbasic/CharacterEncoderImplementations__ISO10646_to_UTF16BE.st,v 1.6 2012/07/12 18:07:54 cg Exp §'
 !
 
 version_SVN
-    ^ '$Id: CharacterEncoderImplementations__ISO10646_to_UTF16BE.st 10808 2012-05-09 15:04:12Z vranyj1 $'
+    ^ '$Id: CharacterEncoderImplementations__ISO10646_to_UTF16BE.st 10824 2012-07-18 16:55:48Z vranyj1 $'
 ! !