Skip to content
Tcl Source Code History Of Ticket 950acd6df4cffdac
Login

History Of Ticket 950acd6df4cffdac

Artifacts Associated With Ticket 950acd6df4cffdac

  1. Ticket change [0cd381f658] (rid 137034) by anonymous on 2014-02-24 09:49:39:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized 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 initialized to: "Tcl 8.6.0 (pl10)"
    6. is_private initialized to: "0"
    7. login: "anonymous"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "9b7155594aadef44d10a978838b8fe108cdafdd1"
    10. resolution initialized to: "None"
    11. severity initialized to: "Critical"
    12. status initialized to: "Open"
    13. submitter initialized to: "anonymous"
    14. subsystem initialized to: "11. Conversions From String"
    15. title initialized to: "utf-8 to unicode conversion gives broken results"
    16. type initialized to: "Bug"
  2. Ticket change [1ef56cb2bf] (rid 137035) by dkf on 2014-02-24 11:55:49:

    1. icomment:
      You're doing this backwards.<p>
      <tt>encoding convertto</tt> takes a string and produces a byte-sequence that is the encoded form of the string using the specified encoding (or the system encoding). <tt>encoding convertfrom</tt> takes a byte-sequence and interprets that as an encoded string, returning the string that it thinks it is the encoded form of (where the encoding is the specified one or the system encoding). The process of converting a string <i>to</i> a particular encoding can result in information loss if the target encoding can't handle a character, and the reverse can result in information loss if the source contains a byte sequence that is not valid in the encoding.<p>
      If we take all that and try the reverse operations:
      <pre>
      % set src "Η Σάμος είναι"
      Η Σάμος είναι
      % encoding convertto utf-8 $src
      Η Σάμος είναι
      % encoding convertfrom utf-8 $src
      — £¬¼¿Â µ¯½±¹
      % encoding convertto utf-8 [encoding convertfrom utf-8 $src]
      — £¬¼¿Â µ¯½±¹
      % encoding convertfrom utf-8 [encoding convertto utf-8 $src]
      Η Σάμος είναι
      </pre>
      We can see that you really are doing things backwards. <strong>Do not think of Tcl strings as UTF-8</strong> but rather as abstract Unicode character sequences. Let Tcl manage what encoding its strings are (it's not constant!) and ask for them in a particular encoding on when you need that. By the time a <tt>source</tt>d script is interpreted at all, Tcl has already done encoding handling for the entire script; everything in it is understood as an (abstract) Unicode character.<p>
      Changing <tt>encoding system</tt> is probably a very bad idea; the main thing that is used for is actually controlling how Tcl and the OS understand bytes used in filenames…
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. resolution changed to: "Invalid"
    5. status changed to: "Pending"
    6. username: "dkf"
  3. Ticket change [5758f3f2c0] (rid 137502) by jan.nijtmans on 2014-04-04 12:50:46:

    1. closedate changed to: "2456752.03525515"
    2. closer changed to: "jan.nijtmans"
    3. icomment:
      Since no-one disputed dkf's excellent explanation (neither do I), this can be closed.
      
    4. login: "jan.nijtmans"
    5. mimetype: "text/plain"
    6. status changed to: "Closed"
  4. Ticket change [b55d432f43] (rid 148447) by dkf on 2016-08-23 13:47:57:

    1. closedate changed to: "2457624.07496862"
    2. closer changed to: "dkf"
    3. login: "dkf"
    4. mimetype: "text/plain"
    5. subsystem changed to: "11. Conversions from String"