[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

Hi,

In message “Re: [Bug] String.titlecase failing on UTF-8 with accented
chars”
on Fri, 1 Jun 2007 22:19:23 +0900, Manoel L. [email protected]
writes:

|Anybody knows how to solve that?

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

          matz.

On 2007-06-01 22:19:23 +0900 (Fri, Jun), Manoel L. wrote:

=> “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

Manoel L. wrote:

=> “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