Created
August 1, 2017 12:09
-
-
Save hiroki-uchida/d694f381060af9ca9f975a05e6b3b37f to your computer and use it in GitHub Desktop.
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
class String | |
def unescape_mb5 | |
gsub(/\&\#x[0-9A-F]{5};/) do |match| | |
str = match.gsub(/\&\#x/, '0x').delete(';') | |
Integer(str).chr('UTF-8') | |
end | |
end | |
def escape_mb5 | |
gsub(/[^\u{0}-\u{FFFF}]/) { format('&#x%X;', $&.ord) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment