Skip to content

Instantly share code, notes, and snippets.

@LTe
Created October 4, 2010 17:24
Show Gist options
  • Save LTe/610100 to your computer and use it in GitHub Desktop.
Save LTe/610100 to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
module Textual
def to_ascii
foo = self.downcase.strip
foo.gsub!(/[ĄÀ�?ÂÃâäàãáäå�?ăąǎǟǡǻ�?ȃȧẵặ]/,'a')
foo.gsub!(/[Ęëêéèẽēĕėẻȅȇẹȩęḙḛ�?ếễểḕḗệ�?]/,'e')
foo.gsub!(/[Ì�?ÎĨ�?iìíîĩīĭïỉ�?ịįȉȋḭɨḯ]/,'i')
foo.gsub!(/[ÒÓÔÕÖòóôõ�?�?ȯö�?őǒ�?�?ơǫ�?ɵøồốỗổȱȫȭ�?�?ṑṓ�?ớỡởợǭộǿ]/,'o')
foo.gsub!(/[ÙÚÛŨÜùúûũūŭüủůűǔȕȗưụṳųṷṵṹṻǖǜǘǖǚừứữửự]/,'u')
foo.gsub!(/[ỳýŷỹȳ�?ÿỷẙƴỵ]/,'y')
foo.gsub!(/[œ]/,'oe')
foo.gsub!(/[ÆǼǢæ]/,'ae')
foo.gsub!(/[ñǹńŃ]/,'n')
foo.gsub!(/[ÇçćĆ]/,'c')
foo.gsub!(/[ß]/,'ss')
foo.gsub!(/[œ]/,'oe')
foo.gsub!(/[ij]/,'ij')
foo.gsub!(/[�?łŁ]/,'l')
foo.gsub!(/[śŚ]/,'s')
foo.gsub!(/[źżŹŻ]/,'z')
foo.sub!(/[\s\'\"\\\/\?\.\=\+\&\%]$/,'')
foo.gsub!(/[\s\'\"\\\/\?\.\=\+\&\%]/,'_')
foo.gsub!(/_+/,'_')
foo
end
end
class String
include Textual
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment