使用Netbeans,为什么Ruby调试不正确显示多字节字符串? [英] Using Netbeans, why does Ruby debug not display multibytes string properly?

查看:130
本文介绍了使用Netbeans,为什么Ruby调试不正确显示多字节字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

env是:netbeans(v = 6.9.1),ruby-debug-base(v = 0.10.4),ruby-debug-ide(0.4.16),ruby(v = 1.8.7) p>

在调试Ruby脚本的过程中,调试器无法正确显示多字节,并且在变量窗口视图中始终显示多字节字符串的二进制数据:

  require'rubygems'
require'active_support'
str =调试程序
str = str.mb_chars
putlength:#{str.length}

BTW,我尝试了0.4.16 ,对于ruby-debug-ide为0.4.11,但是它们的输出相同。



有人可以告诉我如何在调试中正确显示多字节字符串可变窗口视图?

解决方案

部分问题是Ruby 1.8.7开始支持多字节。您可能需要为您的源定义$ KCODE值。请参阅 $ KCODE变量和jcode库



Ruby 1.9.2有更好的支持,所以请试试这是一个选项。






来自于1.9.2和irb的混乱:

  Greg:〜greg $ irb -f 
irb ):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,29,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>

如果我在Textmate中运行以下命令,而1.9.2设置为我的默认值: p>

 #encoding:UTF-8 
puts RUBY_VERSION
str =调试程序
puts str

其中输出:

 #>> 1.9.2 
#>>调试程序

Ruby Debug19生成了相同的代码,所以我需要研究一下它的问题。


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.

这篇关于使用Netbeans,为什么Ruby调试不正确显示多字节字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆