EncodedStream.st
branchjv
changeset 18066 89d51443ba6f
parent 18062 014678b4657a
parent 15345 8f04bcf567e6
child 18071 009cf668b0ed
--- a/EncodedStream.st	Sun Jun 09 00:49:37 2013 +0100
+++ b/EncodedStream.st	Mon Jun 10 17:32:35 2013 +0100
@@ -43,29 +43,32 @@
 "
 ! !
 
-
 !EncodedStream class methodsFor:'instance creation'!
 
 stream:streamArg encoder:encoder
     ^ (self basicNew) stream:streamArg; encoder:encoder
 ! !
 
-
 !EncodedStream class methodsFor:'utilities'!
 
 decodedStreamFor:aStream
-    |encoding decoder decodedStream|
+    "given a positionable stream, guess its encoding (by reading the
+     first few lines, looking for a string with an encoding hint,
+     and return an appropriate encoded string, which does the decoding
+     on the fly. Used mostly to read UTF8 files (source code)"
+
+    |encodingSymbol decoder decodedStream|
 
     aStream isPositionable ifTrue:[
-        encoding := CharacterEncoder guessEncodingOfStream:aStream.
-        (encoding notNil
-        and:[ encoding ~= #'iso8859-1' 
-        and:[ encoding ~= #'ascii' ]]) ifTrue:[
-            decoder := CharacterEncoder encoderFor:encoding.
+        encodingSymbol := CharacterEncoder guessEncodingOfStream:aStream.
+        decoder := CharacterEncoder encoderFor:encodingSymbol.
+        decoder isNil ifTrue:[
+            "/ ascii or iso8895-1
+            ^ aStream
         ].
-    ].
-    decoder isNil ifTrue:[
-        "/ setup for no-encoding; allows for a later switch to a real encoder,
+    ] ifFalse:[
+        "/ setup for no-encoding; 
+        "/ switch to a real encoder later,
         "/ whenever an encoding pragma is encountered later.
         decoder := CharacterEncoder nullEncoderInstance.
     ].
@@ -76,7 +79,9 @@
     ^ decodedStream
 
     "Modified: / 27-03-2013 / 17:08:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
+!
+
+ !
 
 !EncodedStream methodsFor:'accessing'!
 
@@ -277,7 +282,6 @@
     "Modified: / 18-03-2013 / 17:45:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-
 !EncodedStream methodsFor:'stream protocol'!
 
 atEnd
@@ -422,6 +426,10 @@
     ^ stream skipSeparators
 ! !
 
+!EncodedStream methodsFor:'testing'!
+
+ !
+
 !EncodedStream methodsFor:'utilities'!
 
 skipEncodingChunk
@@ -461,15 +469,14 @@
     "Modified: / 29-07-2011 / 17:42:11 / cg"
 ! !
 
-
 !EncodedStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/EncodedStream.st,v 1.27 2013-04-03 16:10:25 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/EncodedStream.st,v 1.28 2013-06-03 10:39:29 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/EncodedStream.st,v 1.27 2013-04-03 16:10:25 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/EncodedStream.st,v 1.28 2013-06-03 10:39:29 cg Exp $'
 !
 
 version_HG
@@ -478,6 +485,6 @@
 !
 
 version_SVN
-    ^ '§ Id: EncodedStream.st 10643 2011-06-08 21:53:07Z vranyj1  §'
+    ^ '$ Id: EncodedStream.st 10643 2011-06-08 21:53:07Z vranyj1  $'
 ! !