guessEncoding - return the real encodings name
authorClaus Gittinger <cg@exept.de>
Tue, 19 Apr 2005 17:27:47 +0200
changeset 8855 289b5bda04bb
parent 8854 538b08b287ca
child 8856 cb0a15744854
guessEncoding - return the real encodings name (not what is written in the file)
CharacterEncoder.st
--- a/CharacterEncoder.st	Tue Apr 19 12:22:19 2005 +0200
+++ b/CharacterEncoder.st	Tue Apr 19 17:27:47 2005 +0200
@@ -534,7 +534,7 @@
 
         (ISO10646_to_UTF8   unicode     ( utf8 'utf-8' ))
 
-        (ISO8859_1          unicode     ( 'iso8859_1' 'iso8859-1' 'iso-8859-1' 'latin-1' 'latin1' 'iso-ir-100' 'ibm-819' 'ms-cp819' 'ibm-cp819' ))
+        (ISO8859_1          unicode     ( 'iso8859_1' 'iso8859-1' 'iso-8859-1' 'latin-1' 'latin1' 'iso-ir-100' 'ibm-819' 'ms-cp819' 'ibm-cp819' 'iso8859'))
 
         (ISO8859_2          unicode     ( 'iso8859_2' 'iso8859-2' 'iso-8859-2' 'latin2' 'latin-2' 'iso-ir-101'))
 
@@ -983,7 +983,7 @@
      within the given buffer 
      (which is usually the first few bytes of a textFile)."
 
-    |s idx w withoutQuotes lcBuffer enc quote|
+    |withoutQuotes lcBuffer quote|
 
     withoutQuotes := 
         [:word |
@@ -1002,6 +1002,8 @@
     lcBuffer := buffer asLowercase.
 
     #( 'charset' 'encoding' ) do:[:keyWord |
+        |encoderOrNil idx s w enc|
+
         (idx := lcBuffer findString:keyWord) ~~ 0 ifTrue:[
             s := ReadStream on:buffer.
             s position1Based:idx.
@@ -1021,8 +1023,10 @@
             ].
             w notNil ifTrue:[
                 enc := withoutQuotes value:w.
-                (self encoderFor:enc asSymbol ifAbsent:nil) notNil ifTrue:[
-                    ^ enc asSymbol
+                encoderOrNil := self encoderFor:enc asSymbol ifAbsent:nil.
+                encoderOrNil notNil ifTrue:[
+                    "/ ^ enc asSymbol
+                    ^ encoderOrNil nameOfEncoding
                 ].
 "/                enc size >=3 ifTrue:[
 "/                    Transcript showCR:'Unknown encoding: ' , (withoutQuotes value:w).
@@ -1498,7 +1502,7 @@
 !CharacterEncoder class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterEncoder.st,v 1.90 2005-03-31 18:49:26 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterEncoder.st,v 1.91 2005-04-19 15:27:47 cg Exp $'
 ! !
 
 CharacterEncoder initialize!