Last active
December 27, 2015 00:59
-
-
Save benhoskings/7241823 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class String | |
def normalize | |
mb_chars.normalize(:kd).gsub(/[^\x00-\x7f]/n, '').to_s | |
end | |
def normalize_for_display | |
mb_chars.normalize(:kd). | |
gsub('æ', 'ae'). | |
gsub('ð', 'd'). | |
gsub(/[^\x00-\x7f]/n, '').to_s | |
end | |
end |
This file contains hidden or 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
class String | |
def to_utf8 | |
if valid_encoding? | |
force_encoding("utf-8") | |
else | |
force_encoding("utf-8").encode("utf-16be", :invalid => :replace, :replace => "?").encode("utf-8") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment