Skip to content

Instantly share code, notes, and snippets.

@jpignata
Created November 13, 2011 12:44
Show Gist options
  • Save jpignata/1362072 to your computer and use it in GitHub Desktop.
Save jpignata/1362072 to your computer and use it in GitHub Desktop.
# Split unicode characters from supplementary planes (such as iOS 5 emoji) into surrogate pairs
# so that node.js can parse them.
def split_into_surrogate_pairs(text)
text.gsub(/[\u{10000}-\u{10ffff}]/) do |match|
codepoint = match.codepoints.first
pair = [0xD7C0 + (codepoint >> 10), 0xDC00 | codepoint & 0x3FF]
pair.pack("U*")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment