[Kde-bindings] Re: Text encoding in Ruby 1.8 plugins

David Palacio dpalacio at orbitalibre.org
Sat Feb 19 00:22:34 UTC 2011


On Fri, Feb 18, 2011 at 03:58:59PM +0100, Arno Rehn wrote:
> On Tuesday 15 February 2011 20:25:57 David Palacio wrote:
> > Hi,
> > 
> > When passing UTF8 text to Qt widgets the text appears garbled. Setting
> > $KCODE='u' in the plugin code does not fix it as QtRuby might have
> > already guessed how to encode Ruby strings (see init_codec() in
> > handlers.cpp). And the interpreter sets $KCODE to "NONE" by default,
> > so ruby strings are always treated as Latin strings. I am thinking of
> > two solutions for this:
> > 
> > 1. Use to/fromLocal8Bit as default case when converting strings.
> > 2. Let krubypluginfactory set $KCODE when -Kkcode is set in RUBYOPT
> > environment variable.
> > 
> > I prefer 1. as my current problem does not involve utf8 strings in the
> > code at all, but only user data (from a 3rd party library), that might
> > be in any encoding, in any locale. fromLocal8Bit should handle this well.
> > What I do not like about 2. is that it requires each user to modify
> > their environment.
> > 
> > What do you think? Am I missing a way to set $KCODE early?
> Difficult. What does KCODE being "NONE" mean? Does it mean "use ASCII" (in 
> which case Local8Bit would be wrong I guess) or does it mean "use the encoding 
> matching the locale"?
> Maybe we should simply default to UTF-8 in krubypluginfactory. I guess that 
> would make life easier.
> 
> -- 
> Arno Rehn
> arno at arnorehn.de

Currently it is used by the parser to allow multibyte characters in
method and variable names. It also lets regular expresions and
IO.each_char methods to correctly handle these characters. I don't know
any other use for it. For any other use, UTF8 strings work fine without
KCODE:
ruby -e "puts 'おはよう'"

I wonder if these are ALL the uses of KCODE. The Ruby source tree does
not document it's use.




More information about the Kde-bindings mailing list