我正在使用ruby 2.2.2和表情符号 但由于某些原因,一些图标不会出现 例如(来自http://apps.timwhitlock.info/emoji/tables/unicode):
Unicode:U + 26F5
字节(UTF-8):\ xE2 \ x9B \ xB5
描述:SAILBOAT
也许有人知道,我该如何解决?
我知道它适用于Java,JS,JRuby,问题是:
https://en.wikipedia.org/wiki/UTF-8#Invalid_code_points
谢谢!
// for JS // for converting unicode code points and code pairs to their respective characters convert = function(unicode) { if(unicode.indexOf("-") > -1) { var parts = []; var s = unicode.split('-'); for(var i = 0; i < s.length; i++) { var part = parseInt(s[i], 16); if (part >= 0x10000 && part <= 0x10FFFF) { var hi = Math.floor((part - 0x10000) / 0x400) + 0xD800; var lo = ((part - 0x10000) % 0x400) + 0xDC00; part = (String.fromCharCode(hi) + String.fromCharCode(lo)); } else { part = String.fromCharCode(part); } parts.push(part); } return parts.join(''); } else { var s = parseInt(unicode, 16); if (s >= 0x10000 && s <= 0x10FFFF) { var hi = Math.floor((s - 0x10000) / 0x400) + 0xD800; var lo = ((s - 0x10000) % 0x400) + 0xDC00; return (String.fromCharCode(hi) + String.fromCharCode(lo)); } else { return String.fromCharCode(s); } } };
这适用于JavaScript,但如果将JS输出返回给ruby则不起作用。