Skip to content

Instantly share code, notes, and snippets.

@Farzy
Created January 22, 2009 20:16
Show Gist options
  • Save Farzy/50689 to your computer and use it in GitHub Desktop.
Save Farzy/50689 to your computer and use it in GitHub Desktop.
Sort strings while handling accentuated characters correctly
#!/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