Using Netbeans, why does Ruby debug not display multibytes string properly?
The env are: netbeans(v=6.9.1), ruby-debug-base (v=0.10.4), ruby-debug-ide (0.4.16) ,ruby(v=1.8.7)
During the process of debuging a Ruby script, the debuger can not display multibytes properly and always displays "Binary Data" for multibytes string in variable window view:
require 'rubygems'
require 'active_support'
str = "调试程序"
str = str.mb_chars
puts "length: #{开发者_如何学运维str.length}"
BTW, I tried 0.4.16, 0.4.11 for ruby-debug-ide, but they have the same output.
Can someone tell me how to make it to display the multibyte string properly in the debug variable window view?
Part of the problem is that Ruby 1.8.7 had the beginning of multi-byte support. You probably need to define your $KCODE value for your source. See The $KCODE Variable and jcode Library
Ruby 1.9.2 has much better support for it, so give it a try if that's an option.
This is from messing around with 1.9.2 and irb:
Greg:~ greg$ irb -f
irb(main):001:0> RUBY_VERSION
=> "1.9.2"
irb(main):002:0> str = "调试程序"
=> "调试程序"
irb(main):003:0> str
=> "调试程序"
irb(main):004:0> str.each_char.to_a
=> ["调", "试", "程", "序"]
irb(main):005:0> str.each_byte.to_a
=> [232, 176, 131, 232, 175, 149, 231, 168, 139, 229, 186, 143]
irb(main):006:0> str.valid_encoding?
=> true
irb(main):007:0> str.codepoints
=> #<Enumerator: "调试程序":codepoints>
irb(main):008:0> str.each_codepoint.to_a
=> [35843, 35797, 31243, 24207]
irb(main):009:0> str.each_codepoint.to_a.map { |i| i.to_s(16) }
=> ["8c03", "8bd5", "7a0b", "5e8f"]
irb(main):010:0> str.encoding
=> #<Encoding:UTF-8>
irb(main):011:0>
And, if I run the following in Textmate while 1.9.2 is set as my default:
# encoding: UTF-8
puts RUBY_VERSION
str = "调试程序"
puts str
which outputs:
# >> 1.9.2
# >> 调试程序
Ruby Debug19 gets mad with the same code so I need to look into what its problem is.
精彩评论