Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmarreck/400426 to your computer and use it in GitHub Desktop.
Save pmarreck/400426 to your computer and use it in GitHub Desktop.
class String
# note: very rough, does not handle caps (but that could be added), just something to help sort accented characters correctly...
TRANSLATION_HASH = {"’"=>"'","åäáàâ" => "a", "ëéèê" => "e", "ïíìî" => "i", "öóòô" => "o", "üúùû" => "u", "ß" => "ss"}
UNUNICODE = Hash[*TRANSLATION_HASH.map{|u,as| u.unpack("U*").inject([]){|sum,e| sum << e; sum << as}}.flatten]
def un_unicode
self.unpack("U*").map{|c| UNUNICODE[c] ? UNUNICODE[c] : c.chr}.join
end
end
# use case
# array_of_strings_with_some_unicode.sort_by{|s| s.un_unicode }
@guv3n
Copy link

guv3n commented Oct 28, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment