Location sensitive downcase in Ruby/Rails (unicode gem)
Posted by Kresimir Bojcic on June 4, 2010
Comments
There is one pretty annoying gotcha in Rails UTF-8 support. As it turns out, downcase is local insensitive. So if you put “HELLO”.downcase you’ll get “hello” as a result. But if you put “ŠĐČHELLOŽŽ”.downcase you’ll get “ŠĐČhelloŽŽ”. Now this is not that I would call a principle of a least surprise. On the bright side it’s supposed to be fixed in Ruby 2.0. Until then there is an easy fix:
gem install unicode
#enviroment.rb require 'unicode' require 'lib/string'
#lib/string.rb
class String
def downcase
Unicode::downcase(self)
end
end