Posted to tcl by de at Mon Dec 19 08:43:46 GMT 2022view raw

  1. # Create the data; works with Tcl 8 and 9
  2. set fd [open "data.txt" w+]
  3. fconfigure $fd -encoding binary
  4. puts -nonewline $fd \xc0\x40
  5. close $fd
  6.  
  7. # Read this with Tcl 9 / current trunk
  8. package require Tcl 9
  9. set fd [open "data.txt"]
  10. fconfigure $fd -encoding utf-8
  11. set data [read $fd]
  12. close $fd
  13. puts $data
  14.  
  15. package require Tcl 9
  16. set fd [open "data.txt"]
  17. fconfigure $fd -encoding utf-8 -strictencoding 1
  18. set data [read $fd]
  19. close $fd
  20. puts $data
  21.  
  22. # Create the data
  23. package require Tcl 9
  24. set fd [open "data.txt" w+]
  25. fconfigure $fd -encoding utf-8
  26. puts -nonewline $fd A\U10FFFFB
  27. close $fd
  28.  
  29. # Read it back
  30. set fd [open "data.txt"]
  31. fconfigure $fd -encoding utf-8 -strictencoding 1
  32. set data [read $fd]
  33. close $fd
  34. puts $data
  35.