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

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-forum.com/\.

Hi,

···

In message "Re: [Bug] String.titlecase failing on UTF-8 with accented chars" on Fri, 1 Jun 2007 22:19:23 +0900, Manoel Lemos <manoel@lemos.net> writes:

Anybody knows how to solve that?

case conversion functions do/will not support characters out of ASCII
range (A-Za-z). Tim Bray enlightened us.

              matz.

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

···

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

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

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