Created
January 22, 2009 20:16
-
-
Save Farzy/50689 to your computer and use it in GitHub Desktop.
Sort strings while handling accentuated characters correctly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby -w | |
# -*- coding: None -*- | |
# vim: sw=2 sts=2: | |
# Tri sans accents | |
$KCODE = 'u' | |
class String | |
def no_accent | |
require 'rubygems' | |
require 'unicode' | |
Unicode.normalize_KD(self).unpack('U*').select{ |cp| | |
cp < 0x0300 || cp > 0x036F | |
}.pack('U*') | |
end | |
end | |
p ["az","aea","aéb"].sort { |x, y| x.no_accent <=> y.no_accent } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment