]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/xml/autoencoding/autoencoding.factor
use radix literals
[factor.git] / basis / xml / autoencoding / autoencoding.factor
index fe4762acbe686d1edb84135b7ca58fb224c627eb..ed9b341c52dbdedacb0e43e3dd2fae24d3a40bb3 100644 (file)
@@ -3,7 +3,7 @@
 USING: kernel namespaces xml.name io.encodings.utf8 xml.elements
 io.encodings.utf16 xml.tokenize xml.state math ascii sequences
 io.encodings.string io.encodings combinators accessors
-xml.data io.encodings.iana ;
+xml.data io.encodings.iana xml.errors ;
 IN: xml.autoencoding
 
 : decode-stream ( encoding -- )
@@ -19,7 +19,7 @@ IN: xml.autoencoding
 
 : 10xxxxxx? ( ch -- ? )
     -6 shift 3 bitand 2 = ;
-          
+
 : start<name ( ch -- tag )
     ! This is unfortunate, and exists for the corner case
     ! that the first letter of the document is < and second is
@@ -27,7 +27,7 @@ IN: xml.autoencoding
     ascii?
     [ utf8 decode-stream next make-tag ] [
         next
-        [ get-next 10xxxxxx? not ] take-until
+        [ drop get-next 10xxxxxx? not ] take-until
         get-char suffix utf8 decode
         utf8 decode-stream next
         continue-make-tag
@@ -35,7 +35,10 @@ IN: xml.autoencoding
 
 : prolog-encoding ( prolog -- )
     encoding>> dup "UTF-16" =
-    [ drop ] [ name>encoding [ decode-stream ] when* ] if ;
+    [ drop ] [
+        dup name>encoding
+        [ decode-stream ] [ bad-encoding ] ?if
+    ] if ;
 
 : instruct-encoding ( instruct/prolog -- )
     dup prolog?
@@ -74,9 +77,9 @@ IN: xml.autoencoding
     get-char {
         { CHAR: < [ start< ] }
         { 0 [ start-utf16be ] }
-        { HEX: EF [ skip-utf8-bom ] }
-        { HEX: FF [ skip-utf16le-bom ] }
-        { HEX: FE [ skip-utf16be-bom ] }
+        { 0xEF [ skip-utf8-bom ] }
+        { 0xFF [ skip-utf16le-bom ] }
+        { 0xFE [ skip-utf16be-bom ] }
         [ drop utf8 decode-stream check f ]
     } case ;