Skip to content

Instantly share code, notes, and snippets.

@hiroki-uchida
Created August 1, 2017 12:09
Show Gist options
  • Save hiroki-uchida/d694f381060af9ca9f975a05e6b3b37f to your computer and use it in GitHub Desktop.
Save hiroki-uchida/d694f381060af9ca9f975a05e6b3b37f to your computer and use it in GitHub Desktop.
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