Created
November 13, 2011 12:44
-
-
Save jpignata/1362072 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
# 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