Defined in
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
-
No testcase defined.
Source code:
variable utf8bom
set fd [open $filename]
if {$encodingString != {}} {
upvar $encodingString encString
}
fconfigure $fd -translation binary
if {![binary scan [read $fd 4] "H8" firstBytes]} {
seek $fd 0 start
set encString UTF-8
return $fd
}
switch [string range $firstBytes 0 3] {
"feff" {
if {$forSimple || $forRead} {
if {[package vsatisfies [package provide Tcl] 9-]} {
seek $fd 2 start
fconfigure $fd -encoding utf-16be -translation auto
} else {
error "UTF-16be is not supported"
}
} else {
seek $fd 0 start
set encString UTF-16be
fconfigure $fd -encoding utf-8 -translation auto
}
return $fd
}
"fffe" {
set encString UTF-16le
if {$forSimple || $forRead} {
seek $fd 2 start
if {[package vsatisfies [package provide Tcl] 9-]} {
fconfigure $fd -encoding utf-16le -translation auto
} else {
fconfigure $fd -encoding unicode -translation auto
}
} else {
seek $fd 0 start
fconfigure $fd -encoding utf-8 -translation auto
}
return $fd
}
}
if {$utf8bom} {
if {[string range $firstBytes 0 5] eq "efbbbf"} {
set encString UTF-8
seek $fd 3 start
fconfigure $fd -encoding utf-8 -translation auto
return $fd
}
}
switch $firstBytes {
"3c3f786d" {
set head [read $fd 296]
set closeIndex [string first ">" $head]
if {$closeIndex == -1} {
error "Weird XML data or not XML data at all"
}
seek $fd 0 start
set xmlDeclaration [read $fd [expr {$closeIndex + 5}]]
set pattern {^[^>]+encoding=[\x20\x9\xd\xa]*["']([^ "']+)['"]}
# emacs: "
if {![regexp $pattern $head - encStr]} {
set encoding utf-8
set encString UTF-8
} else {
set encoding [IANAEncoding2TclEncoding $encStr]
set encString $encStr
}
}
"0000003c" -
"0000003c" -
"3c000000" -
"00003c00" {
error "UCS-4 not supported"
}
"003c003f" {
if {$forSimple || $forRead} {
if {[package vsatisfies [package provide Tcl] 9-]} {
set encoding utf-16be
} else {
error "UTF-16be is not supported by the simple parser"
}
} else {
set encoding utf-8
}
seek $fd 0 start
set encString UTF-16be
}
"3c003f00" {
if {$forSimple || $forRead} {
if {[package vsatisfies [package provide Tcl] 9-]} {
set encoding utf-16le
} else {
set encoding unicode
}
} else {
set encoding utf-8
}
seek $fd 0 start
set encString UTF-16le
}
"4c6fa794" {
if {[package vsatisfies [package provide Tcl] 9-]} {
seek $fd 0 start
set encoding ebcdic
} else {
error "EBCDIC not supported"
}
}
default {
seek $fd 0 start
set encoding utf-8
set encString "UTF-8"
}
}
fconfigure $fd -encoding $encoding -translation auto
return $fd
XQL Not present:Generic, PostgreSQL, Oracle