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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sergio Oliveira (Guest)
on 2008-12-02 18:28
(Received via mailing list)
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. :-(

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
Derek N. (Guest)
on 2008-12-02 19:33
(Received via mailing list)
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¡Ì(c)rgio
S?rgio
S¨¦rgio




On Tue, Dec 2, 2008 at 11:26 AM, Sergio Oliveira
Sergio Oliveira (Guest)
on 2008-12-02 21:53
(Received via mailing list)
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
Adam S. (Guest)
on 2008-12-03 08:14
(Received via mailing list)
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
<removed_email_address@domain.invalid> wrote:
> -Sergio
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Charles Oliver N. (Guest)
on 2008-12-03 08:19
(Received via mailing list)
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
Adam S. (Guest)
on 2008-12-03 08:44
(Received via mailing list)
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. <removed_email_address@domain.invalid>
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
Thomas E Enebo (Guest)
on 2008-12-03 18:46
(Received via mailing list)
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... :(

-Tom


On Wed, Dec 3, 2008 at 12:19 AM, Charles Oliver N.
<removed_email_address@domain.invalid> wrote:
>>
>> -Sergio
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>   http://xircles.codehaus.org/manage_email
>
>
>



--
Blog: http://www.bloglines.com/blog/ThomasEEnebo
Email: removed_email_address@domain.invalid , 
removed_email_address@domain.invalid

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Charles Oliver N. (Guest)
on 2008-12-03 20:13
(Received via mailing list)
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
Sergio Oliveira (Guest)
on 2008-12-03 23:19
(Received via mailing list)
I will try my best !
Thanks,

-Sergio

On Wed, Dec 3, 2008 at 4:12 PM, Charles Oliver N. <
This topic is locked and can not be replied to.