Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 0cd381f658175dc5573f0e17f4de37f34e00a20a
Ticket: 950acd6df4cffdac6dfecd189864e86262c33ea5
utf-8 to unicode conversion gives broken results
User & Date: anonymous on 2014-02-24 09:49:39
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    So far as I understood "encoding convertfrom $enc $text" is the right command to convert from a string with known encoding to unicode. This works fine, except $enc is utf-8. Please try the following script (I hope this tracker is not corrupting the Greek):
    
    ----------------------------------------------------------------------
    #!/usr/bin/wish
    
    # 1. ensure you have the right encoding to read the string
    # 2. we want conversion utf-8 -> unicode
    encoding system utf-8
    
    set src "Η Σάμος είναι"
    
    # the result of this operation is broken!
    set uni [encoding convertfrom utf-8 $src]
    set utf [encoding convertto utf-8 $uni]
    
    # this works fine, it's a iso8859-7 encoded string
    set grk [encoding convertfrom iso8859-7 "Ç ÓÜìïò åßíáé"]
    
    pack [label .l1 -text $src]
    pack [label .l2 -text $uni]
    pack [label .l3 -text $utf]
    pack [label .l4 -text $grk]
    ----------------------------------------------------------------------
    
    You will see that the conversion from utf-8 is broken. Converting back is still broken. Conversion from iso8859-7 is fine.
    
    My application is only working if I exclude utf-8 explicitly (my system encoding is utf-8):
    
    if {$encoding eq "utf-8"} {
      set dst $src ;# because convertfrom doesn't work
    } else {
      set dst [encoding convertfrom $encoding $src]
    }
    
    But I don't think that this is intended, the generic command "convertfrom" should work with all encodings due to the manual.
    
    PS: In my tests I've figured out that sometimes the conversion to utf-8 gives results with overlong sequences, such results are invalid due to the utf-8 specification.
    
  5. foundin changed to: "Tcl 8.6.0 (pl10)"
  6. is_private changed to: "0"
  7. login: "anonymous"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "9b7155594aadef44d10a978838b8fe108cdafdd1"
  10. resolution changed to: "None"
  11. severity changed to: "Critical"
  12. status changed to: "Open"
  13. submitter changed to: "anonymous"
  14. subsystem changed to: "11. Conversions From String"
  15. title changed to: "utf-8 to unicode conversion gives broken results"
  16. type changed to: "Bug"