Fixed EncodedStream>>next for UTF8 to Unicode decoder. jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Sat, 03 Oct 2015 08:50:56 +0100
branchjv
changeset 18807 d79ce9fb5198
parent 18806 2fb07499b4f2
child 18809 caa7bbec5085
Fixed EncodedStream>>next for UTF8 to Unicode decoder.
CharacterEncoder.st
CharacterEncoderImplementations__ISO10646_to_UTF8.st
--- a/CharacterEncoder.st	Sun Oct 04 06:42:01 2015 +0200
+++ b/CharacterEncoder.st	Sat Oct 03 08:50:56 2015 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 2004 by eXept Software AG
               All Rights Reserved
--- a/CharacterEncoderImplementations__ISO10646_to_UTF8.st	Sun Oct 04 06:42:01 2015 +0200
+++ b/CharacterEncoderImplementations__ISO10646_to_UTF8.st	Sat Oct 03 08:50:56 2015 +0100
@@ -424,7 +424,7 @@
     "
 ! !
 
-!ISO10646_to_UTF8 privateMethodsFor:'queries'!
+!ISO10646_to_UTF8 methodsFor:'queries'!
 
 bytesToReadFor:firstByte 
     |bytesToRead|
@@ -442,9 +442,7 @@
     ^bytesToRead
 
     "Created: / 14-06-2005 / 17:17:24 / janfrog"
-! !
-
-!ISO10646_to_UTF8 methodsFor:'queries'!
+!
 
 characterSize:charOrcodePoint
     "return the number of bytes required to encode codePoint"
@@ -482,26 +480,31 @@
     "Created: / 16-06-2005 / 11:45:14 / masca"
 !
 
-readNextCharacterFrom:aStream 
-
-    |firstByte bytesToRead str|
+readNextCharacterFrom:stream
 
-    firstByte := aStream peek. 
-    firstByte ifNil:[^nil].
-    firstByte := firstByte asInteger.
-    bytesToRead := self bytesToReadFor:firstByte.
-    str := self decodeString:(aStream next:bytesToRead).
-    str size > 1 ifTrue:[
-        self error:'Badly coded method'
+    | c bytesYetToRead s |
+    c := stream peek.
+    bytesYetToRead := self bytesToReadFor:c codePoint.
+    bytesYetToRead == 1 ifTrue:[ 
+        stream next.
+        ^ c.
     ].
-    ^ str first
+    s := (String new:1 + bytesYetToRead) writeStream.
+    s nextPutAll:(stream next: bytesYetToRead).
+    ^ self decodeString:s contents
 
     "Created: / 14-06-2005 / 17:03:59 / janfrog"
+    "Modified: / 03-10-2015 / 08:49:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !ISO10646_to_UTF8 class methodsFor:'documentation'!
 
 version
     ^ '$Header$'
+!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
 ! !