[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[Bug] String.titlecase failing on UTF-8 with accented chars

Manoel Lemos

6/1/2007 1:19:00 PM

Anybody knows how to solve that?

Check this:

>> u.lastname
=> "Guimar\303\243es"
>> puts u.lastname
Guimarães
=> nil
>> u.lastname.titlecase
=> "Guimar\303\243Es"
>> puts u.lastname.titlecase
GuimarãEs # ------------------> Check the E in capital, this is a bug
=> nil
>>

--
Posted via http://www.ruby-....

2 Answers

Mariusz Pekala

6/1/2007 2:22:00 PM

0

On 2007-06-01 22:19:23 +0900 (Fri, Jun), Manoel Lemos wrote:
> Anybody knows how to solve that?
>
> Check this:
>
> >> u.lastname
> => "Guimar\303\243es"
> >> puts u.lastname
> Guimarães
> => nil
> >> u.lastname.titlecase
> => "Guimar\303\243Es"
> >> puts u.lastname.titlecase
> GuimarãEs # ------------------> Check the E in capital, this is a bug
> => nil

Titlecase is a Rails-ism (and the usual policy here is that Rails
questions should go to Rails lists or #rubyonrails IRC channel), but you can try:

puts u.lastname.chars.titlecase

Read: ri ActiveSupport::CoreExtensions::String::Unicode#chars


--
No virus found in this outgoing message.
Checked by 'grep -i virus $MESSAGE'
Trust me.

Daniel DeLorme

6/1/2007 2:30:00 PM

0

Manoel Lemos wrote:
> Anybody knows how to solve that?
>
> Check this:
>
>>> u.lastname
> => "Guimar\303\243es"
>>> puts u.lastname
> Guimarães
> => nil
>>> u.lastname.titlecase
> => "Guimar\303\243Es"
>>> puts u.lastname.titlecase
> GuimarãEs # ------------------> Check the E in capital, this is a bug
> => nil

If you're going to use utf-8 you need at least to set $KCODE='u'

>> $KCODE='n'
>> puts "Guimar\303\243es".titlecase
GuimarãEs

>> $KCODE='u'
>> puts "Guimar\303\243es".titlecase
Guimarães

-Daniel