--- a/FileBrowser.st Fri Feb 13 02:02:20 2004 +0100
+++ b/FileBrowser.st Fri Feb 13 14:44:02 2004 +0100
@@ -5933,7 +5933,7 @@
|n "{Class: SmallInteger }"
binary idx s w enc
- withoutQuotes|
+ withoutQuotes isHTML lcBuffer|
binary := false.
n := aBuffer size.
@@ -5949,33 +5949,25 @@
w
].
-
- (idx := aBuffer findString:'charset=') ~~ 0 ifTrue:[
- s := ReadStream on:aBuffer.
- s position1Based:idx + 8.
- s skipSeparators.
- w := s upToSeparator.
- w notNil ifTrue:[
- ^ (withoutQuotes value) asSymbol
+ lcBuffer := aBuffer asLowercase.
+
+ #( 'charset' 'encoding' ) do:[:keyWord |
+ (idx := lcBuffer findString:keyWord) ~~ 0 ifTrue:[
+ s := ReadStream on:aBuffer.
+ s position1Based:idx.
+ s skip:keyWord size.
+ ['=:#' includes:s peek] whileTrue:[
+ s next.
+ s skipSeparators.
+ ].
+ w := s upToSeparator.
+ w notNil ifTrue:[
+ ^ (withoutQuotes value) asSymbol
+ ].
].
].
- (idx := aBuffer findString:'encoding') ~~ 0 ifTrue:[
- s := ReadStream on:aBuffer.
- s position1Based:idx + 8.
- s skipSeparators.
- s peek == $: ifTrue:[
- s next.
- s skipSeparators.
- ].
- s peek == $# ifTrue:[
- s next.
- s skipSeparators.
- ].
- w := s upToSeparator.
- w notNil ifTrue:[
- ^ (withoutQuotes value) asSymbol
- ].
- ].
+
+ isHTML := (lcBuffer findString:'doctype html') ~~ 0.
1 to:n do:[:i |
(aBuffer at:i) isPrintable ifFalse:[binary := true].
@@ -5984,17 +5976,23 @@
binary ifTrue:[
"/ look for JIS7 / EUC encoding
+ isHTML ifTrue:[
+ "/ its aHTML, but no charset= / or encoding= found.
+ "/ assume utf-8
+ ^ #'utf-8'
+ ].
+
enc := CharacterArray guessEncodingFrom:aBuffer.
enc notNil ifTrue:[
^ enc
].
- "/ if the encoding has been set to any non iso setting,
- "/ assume its what we defined ...
-
- (('iso*' match:fileEncoding) or:['ascii*' match:fileEncoding]) ifTrue:[
- ^ #binary
- ].
+"/ "/ if the encoding has been set to any non iso setting,
+"/ "/ assume its what we defined ...
+"/
+"/ (('iso*' match:fileEncoding) or:['ascii*' match:fileEncoding]) ifTrue:[
+"/ ^ #binary
+"/ ].
^ fileEncoding ? #binary
].
^ #ascii
@@ -7599,5 +7597,5 @@
!FileBrowser class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.570 2004-02-13 01:02:20 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.571 2004-02-13 13:44:02 cg Exp $'
! !