Tcl Source Code

Artifact [88ae1a6aca]
Login

Artifact 88ae1a6aca7827277bd009facf95fe61dd386c74:

Attachment "utf8_test.tcl" to ticket [f9539dce52] added by samoc 2014-07-10 03:54:53. (unpublished)
#!/usr/bin/tclsh8.6

# Check that system and output encodings are set to UTF-8...
if {[encoding system] ne "utf-8"} {error !}
if {[fconfigure stdout -encoding] ne "utf-8"} {error !}

# A string containing a 2, 3 and 4 byte UTF-8 characters...
set string -รก-โœ-๐Ÿ˜ƒ-

# This puts produces 8 bytes where the 4-byte charater should be!
puts $string

# This puts produces only 1 bytes where the 2 and 3 byte characters should be!
fconfigure stdout -encoding binary
puts $string

# This puts produces what we expected to get in the first place...
set string -[encoding convertto utf-8 รก]-[encoding convertto utf-8 โœ]-๐Ÿ˜ƒ-
puts $string