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.
Bfcd2ee582d9e83ab4c742509ce1010a?d=identicon&s=25 Sergio Oliveira (Guest)
on 2008-12-02 17: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
F7c60d61f6ec468bd3ded750a770ed4b?d=identicon&s=25 Derek Neptune (Guest)
on 2008-12-02 18: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
Bfcd2ee582d9e83ab4c742509ce1010a?d=identicon&s=25 Sergio Oliveira (Guest)
on 2008-12-02 20: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
E0737dd2ec32558e989ff48536039f73?d=identicon&s=25 Adam Sroka (Guest)
on 2008-12-03 07: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
<sergio.soujava@gmail.com> wrote:
> -Sergio
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Ede2aa10c6462f1d825143879be59e38?d=identicon&s=25 Charles Oliver Nutter (Guest)
on 2008-12-03 07: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
E0737dd2ec32558e989ff48536039f73?d=identicon&s=25 Adam Sroka (Guest)
on 2008-12-03 07: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 Sroka <adam.sroka@gmail.com>
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
13313ac2ec7ba7c43b1b952db034ff3b?d=identicon&s=25 Thomas E Enebo (Guest)
on 2008-12-03 17: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 Nutter
<charles.nutter@sun.com> wrote:
>>
>> -Sergio
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>   http://xircles.codehaus.org/manage_email
>
>
>



--
Blog: http://www.bloglines.com/blog/ThomasEEnebo
Email: enebo@acm.org , tom.enebo@gmail.com

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

    http://xircles.codehaus.org/manage_email
Ede2aa10c6462f1d825143879be59e38?d=identicon&s=25 Charles Oliver Nutter (Guest)
on 2008-12-03 19: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
Bfcd2ee582d9e83ab4c742509ce1010a?d=identicon&s=25 Sergio Oliveira (Guest)
on 2008-12-03 22:19
(Received via mailing list)
I will try my best !
Thanks,

-Sergio

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