How to make JRuby support ISO-8859-1 for its strings?

I am running JRuby 1.1.5 through Tomcat on Windows.

I tried the $KCODE = ‘u’, $KCODE = ‘U’, $KCODE = ‘ASCII’, etc.

None of them worked. :frowning:

I have a JRuby String “Sérgio” which is converted to a Java String which
is
sent to JSP which has ISO-8859-1 in its header.

But I get “S?rgio” in the JSP.

Any help will be appreciated as I spent more than 2 hours trying to
figure
out but I was not able too.

Thanks,

-Sergio

I’m interested in the Right Way to handle this scenario as well.

Rough testing shows that converting the ruby string into javabytes and
then creating a java string from javabytes works, preserving the
non-ascii characters to use within java calls.

require ‘java’

s = “S¨¦rgio”

convert string to java bytes

and then create a java string from the javabytes

s_javabytes = s.to_java_bytes
j_string = java.lang.String.new s_javabytes

print using java println

java.lang.System.out.println j_string

print using puts

puts j_string

create a new java string directly from ruby string

j2_string = java.lang.String.new s

print using java println

java.lang.System.out.println j2_string

print using puts

puts j2_string

output:

S¨¦rgio
S¡Ì©rgio
S?rgio
S¨¦rgio

On Tue, Dec 2, 2008 at 11:26 AM, Sergio Oliveira

Thanks Derek for the help.

I see how you did it. Problem is it needs to be done transparent for
ruby
strings because I don’t have Java Strings but a bunch of Ruby strings
all
over my application that gets passed to JRuby.
Can we somehow alter (open) ruby String class to fix this? (Ruby-side
solution)

Is there a way to configure JRuby to fix this? (JRuby-side solution?)

-Sergio

If this is being rendered to a JSP why not just use the È
character entity?

On Tue, Dec 2, 2008 at 8:26 AM, Sergio Oliveira
[email protected] wrote:

-Sergio


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I think Tom is planning to land (or has landed already) some code to
help this a lot…Tom?

Sergio Oliveira wrote:

But I get “S?rgio” in the JSP.

Any help will be appreciated as I spent more than 2 hours trying to
figure out but I was not able too.

Thanks,

-Sergio


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

P.S. using accents in strings causes cross-platform issues even when
working with pure Java. Better off to use an entity or base64. At the
very least, make sure that you use # character literals on the off
chance you need to compile the code on a Windows machine (Java strings
are always utf-16 internally, but code is compiled using the native
charset.)

On Tue, Dec 2, 2008 at 10:14 PM, Adam S. [email protected]
wrote:

sent to JSP which has ISO-8859-1 in its header.
But I get “S?rgio” in the JSP.
Any help will be appreciated as I spent more than 2 hours trying to figure
out but I was not able too.
Thanks,
-Sergio


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Sergio: Please file your case as a bug, and see if you can help look
into fixing it.

Thomas E Enebo wrote:

-Tom

I tried the $KCODE = ‘u’, $KCODE = ‘U’, $KCODE = ‘ASCII’, etc.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Derek’s test script runs on trunk now whether I use -Ku or not. The
important thing for it to work was for me to make sure the characters
are really utf-8. I made the repeated mistake of pasting the chars
into emacs which then somehow saved the document as iso88591.

The problem sergio is having would be unaffected by the parser patch I
did since this is a parity mismatch between Ruby and Java.
RubyString and possibly JI has bugs in passing strings over to the
Java side of things. So I got nothing… :frowning:

-Tom

On Wed, Dec 3, 2008 at 12:19 AM, Charles Oliver N.
[email protected] wrote:

-Sergio


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Blog: http://www.bloglines.com/blog/ThomasEEnebo
Email: [email protected] , [email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I will try my best !
Thanks,

-Sergio

On Wed, Dec 3, 2008 at 4:12 PM, Charles Oliver N. <