Encoding in ruby/tk internals

Ask a Question related to Ruby, Design and Development.

  1. #1

    Default Encoding in ruby/tk internals

    Hello ruby-talk peoples,

    It seems that something is wrong in ruby/tk libraries:

    I'm trying to work with cp1251 encoding. Everything works fine, until
    i try to use "percent substitutions" - params values are passed in
    unicode, ignoring Tk.encoding value.

    In pure Tcl all works normal -

    encoding system "cp1251"
    -command[list tblCmd $table(array) %i %C %s]

    %s value is passing to tblCmd in cp1251
    but when i try to do something like that in ruby

    Tk.encoding = 'CP1251'
    @entry = TkEntry.new
    @entry.configure('validatecommand',[proc {|s| v(s)},'%s'])

    %s is passing to v in utf-8 :(

    Such behavior is bug, feature or i'm doing something wrong?
    It there any way to retrive "percent substitutions" values in correct
    encoding?

    --
    Best regards,
    Nikolay



    Nikolay Ponomarenko Guest

  2. Similar Questions and Discussions

    1. If you can understand DBI internals...
      and how it links up to DBD::mysql, then you are pretty close to Perl God. Because I can't make heads or tails of it. But I can tell that...
    2. Ruby classes for MP3 de-/encoding
      Hello folks, does anyone know of any Ruby collection of classes / modules for decoding / encoding (maybe liblame bindings?) MP3 data? I...
    3. Ruby internals
      I'd like to get to better understand how the ruby interpreter works. I have grabbed the CVS and started rumaging around, but I got to think that...
    4. AIX Kernel Internals
      Take a look at http://publib16.boulder.ibm.com/pseries/en_US/infocenter/base/aix52.htm Cheers, ku lbalbalba@hotmail.com (J.Smith) wrote in...
    5. Ruby Character Encoding
      Hi, In message "Ruby Character Encoding" on 03/07/15, Mark Wilson <mwilson13@cox.net> writes: |I'm interested in any (i.e., arbitrary)...
  3. #2

    Default Re: Encoding in ruby/tk internals

    Hi,

    From: Nikolay Ponomarenko <ts@pstu.edu>
    Subject: Encoding in ruby/tk internals
    Date: Wed, 19 Nov 2003 17:39:02 +0900
    Message-ID: <807410826.20031119104245@pstu.edu>
    > In pure Tcl all works normal -
    >
    > encoding system "cp1251"
    > -command[list tblCmd $table(array) %i %C %s]
    >
    > %s value is passing to tblCmd in cp1251
    > but when i try to do something like that in ruby
    >
    > Tk.encoding = 'CP1251'
    > @entry = TkEntry.new
    > @entry.configure('validatecommand',[proc {|s| v(s)},'%s'])
    >
    > %s is passing to v in utf-8 :(
    After calling Tk.encoding_system = 'cp1251',
    do you get the same result?
    --
    Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)


    Hidetoshi NAGAI Guest

  4. #3

    Default Re: Encoding in ruby/tk internals

    Hello Hidetoshi,

    Wednesday, November 19, 2003, 11:23:19 AM, you wrote:
    >> In pure Tcl all works normal -
    >> encoding system "cp1251"
    >> -command[list tblCmd $table(array) %i %C %s]
    >>
    >> %s value is passing to tblCmd in cp1251
    >> but when i try to do something like that in ruby
    >>
    >> Tk.encoding = 'CP1251'
    >> @entry = TkEntry.new
    >> @entry.configure('validatecommand',[proc {|s| v(s)},'%s'])
    >>
    >> %s is passing to v in utf-8 :(
    HN> After calling Tk.encoding_system = 'cp1251',
    HN> do you get the same result?

    Yes.
    something like

    Tk.encoding_system = 'cp1251' # or Tk.encoding = 'cp1251'
    $btn = TkButton.new($root) {
    text "and here text in cp1251"
    }
    works right

    Problem is only with "%" values :(




    --
    Best regards,
    Nikolay



    Nikolay Ponomarenko Guest

  5. #4

    Default Re: Encoding in ruby/tk internals

    Hi,

    From: Nikolay Ponomarenko <ts@pstu.edu>
    Subject: Re: Encoding in ruby/tk internals
    Date: Thu, 20 Nov 2003 15:58:37 +0900
    Message-ID: <80918300.20031120090222@pstu.edu>
    > HN> After calling Tk.encoding_system = 'cp1251',
    > HN> do you get the same result?
    >
    > Yes.
    > something like
    >
    > Tk.encoding_system = 'cp1251' # or Tk.encoding = 'cp1251'
    > $btn = TkButton.new($root) {
    > text "and here text in cp1251"
    > }
    > works right
    >
    > Problem is only with "%" values :(
    Well, could you try the following patch?

    Index: tkentry.rb
    ================================================== =================
    RCS file: /src/ruby/ext/tk/lib/tkentry.rb,v
    retrieving revision 1.19
    diff -u -r1.19 tkentry.rb
    --- tkentry.rb 3 Aug 2003 22:07:46 -0000 1.19
    +++ tkentry.rb 20 Nov 2003 08:41:54 -0000
    @@ -27,9 +27,10 @@

    class ValidateArgs
    VARG_KEY = 'disvPSVW'
    - VARG_TYPE = 'nxsssssw'
    + VARG_TYPE = 'nxeseesw'

    def self.scan_args(arg_str, arg_val)
    + enc = Tk.encoding
    arg_cnv = []
    arg_str.strip.split(/\s+/).each_with_index{|kwd,idx|
    if kwd =~ /^%(.)$/
    @@ -39,6 +40,12 @@
    arg_cnv << TkComm::number(arg_val[idx])
    when ?s
    arg_cnv << TkComm::string(arg_val[idx])
    + when ?e
    + if enc
    + arg_cnv << Tk.encoding_convertto(TkComm::string(arg_val[idx]), enc)
    + else
    + arg_cnv << TkComm::string(arg_val[idx])
    + end
    when ?w
    arg_cnv << TkComm::window(arg_val[idx])
    when ?x

    --
    Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)


    Hidetoshi NAGAI Guest

  6. #5

    Default Re: Encoding in ruby/tk internals

    Hello Hidetoshi,

    Thursday, November 20, 2003, 10:44:10 AM, you wrote:

    HN> Tk.encoding_convertto(TkComm::string(arg_val[idx]), enc)

    Seems that something wrong here.

    I try to replace it with this for testing and debug purpose

    puts Tk.encoding_convertto(TkComm::string(arg_val[idx]), enc)
    puts Iconv.iconv('CP1251','UTF-8',TkComm::string(arg_val[idx]))
    arg_cnv << Iconv.iconv('CP1251','UTF-8',TkComm::string(arg_val[idx]))

    works right

    --
    Best regards,
    Nikolay



    Nikolay Ponomarenko Guest

  7. #6

    Default Re: Encoding in ruby/tk internals

    Hi,

    From: Nikolay Ponomarenko <ts@pstu.edu>
    Subject: Re: Encoding in ruby/tk internals
    Date: Thu, 20 Nov 2003 18:25:58 +0900
    Message-ID: <1649750029.20031120112934@pstu.edu>
    > HN> Tk.encoding_convertto(TkComm::string(arg_val[idx]), enc)
    > Seems that something wrong here.
    >
    > I try to replace it with this for testing and debug purpose
    >
    > puts Tk.encoding_convertto(TkComm::string(arg_val[idx]), enc)
    > puts Iconv.iconv('CP1251','UTF-8',TkComm::string(arg_val[idx]))
    > arg_cnv << Iconv.iconv('CP1251','UTF-8',TkComm::string(arg_val[idx]))
    >
    > works right
    Hmmm...
    Could you try to replace
    'Tk.encoding_convertto(TkComm::string(arg_val[idx]), enc)'
    to 'Tk.fromUTF8(TkComm::string(arg_val[idx]), enc)'?

    # Is the value of enc is 'cp1251'?
    --
    Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

    Hidetoshi NAGAI Guest

  8. #7

    Default Re: Encoding in ruby/tk internals

    Hello, Hidetoshi!
    You wrote on Fri, 21 Nov 2003 02:04:10 +0900:

    ??>> I try to replace it with this for testing and debug purpose
    ??>>
    ??>> puts Tk.encoding_convertto(TkComm::string(arg_val[idx]), enc)
    ??>> puts Iconv.iconv('CP1251','UTF-8',TkComm::string(arg_val[idx]))
    ??>> arg_cnv << Iconv.iconv('CP1251','UTF-8',TkComm::string(arg_val[idx]))
    ??>>
    ??>> works right

    HN> Hmmm...
    HN> Could you try to replace
    HN> 'Tk.encoding_convertto(TkComm::string(arg_val[idx]), enc)'
    HN> to 'Tk.fromUTF8(TkComm::string(arg_val[idx]), enc)'?

    Works right. Thanks a lot. Will this fix became official?

    HN> # Is the value of enc is 'cp1251'?

    Yes, of course.

    By the way, why such functions as
    Tk.encoding_convertto
    Tk.fromUTF8

    are not described anywhere?

    With best regards,
    Nikolay Ponomarenko.

    Nikolay Ponomarenko Guest

  9. #8

    Default Re: Encoding in ruby/tk internals

    Hi,

    From: "Nikolay Ponomarenko" <pnv82@pisem.net>
    Subject: Re: Encoding in ruby/tk internals
    Date: Fri, 21 Nov 2003 16:17:14 +0900
    Message-ID: <3fbdbbf9$1@news.itcom.net.ua>
    > HN> Hmmm...
    > HN> Could you try to replace
    > HN> 'Tk.encoding_convertto(TkComm::string(arg_val[idx]), enc)'
    > HN> to 'Tk.fromUTF8(TkComm::string(arg_val[idx]), enc)'?
    > Works right. Thanks a lot. Will this fix became official?
    Thank you for your help to debug the problem.
    I'll commit the patch.
    It will be included in 1.8.1-preview3.
    --
    Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)


    Hidetoshi NAGAI Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139