diff --git a/lib/unicode.js b/lib/unicode.js index 25fc24a..886e7c0 100644 --- a/lib/unicode.js +++ b/lib/unicode.js @@ -460,6 +460,9 @@ exports.codePointAt = function(str, position) { throw TypeError(); } var string = String(str); + if (string.codePointAt) { + return string.codePointAt(position); + } var size = string.length; // `ToInteger` var index = position ? Number(position) : 0; @@ -501,6 +504,9 @@ exports.codePointAt = function(str, position) { // }; exports.fromCodePoint = function() { + if (String.fromCodePoint) { + return String.fromCodePoint.apply(String, arguments); + } var MAX_SIZE = 0x4000; var codeUnits = []; var highSurrogate; diff --git a/test/widget-eaw.js b/test/widget-eaw.js index 8d5a825..a516336 100644 --- a/test/widget-eaw.js +++ b/test/widget-eaw.js @@ -18,48 +18,37 @@ screen = blessed.screen({ // screen.tput.strings.enter_alt_charset_mode = false; // du juan (dou gyun?) -var DU = '杜'; -// NOTE: {bold} breaks JUAN in rxvt-unicode!! -// BREAKS: console.log('\x1b[1m杜鹃\x1b[m'); -var JUAN = '鹃'; // var DU = '杜'; -// var DU = String.fromCodePoint -// ? String.fromCodePoint(0x675C) -// : String.fromCharCode(0x675C); +var DU = unicode.fromCodePoint(0x675C); + +// NOTE: {bold} breaks JUAN in rxvt-unicode!! +// BREAKS: console.log('\x1b[1m杜鹃\x1b[m'); // var JUAN = '鹃'; -// var JUAN = String.fromCodePoint -// ? String.fromCodePoint(0x9E43) -// : String.fromCharCode(0x9E43); +var JUAN = unicode.fromCodePoint(0x9E43); // one flew over the 杜鹃's nest. // var DOUBLE = '杜鹃'; var DOUBLE = DU + JUAN; // var SURROGATE_DOUBLE = '𰀀'; -var SURROGATE_DOUBLE = String.fromCodePoint - ? String.fromCodePoint(0x30000) - : String.fromCharCode(0xD880, 0xDC00); +// var SURROGATE_DOUBLE = String.fromCharCode(0xD880, 0xDC00); +var SURROGATE_DOUBLE = unicode.fromCodePoint(0x30000); // var SURROGATE_DOUBLE_OTHER = '🉐'; -var SURROGATE_DOUBLE_OTHER = String.fromCodePoint - ? String.fromCodePoint(0x1F250) - : String.fromCharCode(0xD83C, 0xDE50); +// var SURROGATE_DOUBLE_OTHER = String.fromCharCode(0xD83C, 0xDE50); +var SURROGATE_DOUBLE_OTHER = unicode.fromCodePoint(0x1F250); // var SURROGATE_SINGLE = '𝌆'; -var SURROGATE_SINGLE = String.fromCodePoint - ? String.fromCodePoint(0x1D306) - : String.fromCharCode(0xD834, 0xDF06); +// var SURROGATE_SINGLE = String.fromCharCode(0xD834, 0xDF06); +var SURROGATE_SINGLE = unicode.fromCodePoint(0x1D306); // var COMBINE_NONSURROGATE = 's̀'.substring(1); // s + combining -var COMBINE_NONSURROGATE = String.fromCodePoint - ? String.fromCodePoint(0x0300) - : String.fromCharCode(0x0300); +var COMBINE_NONSURROGATE = unicode.fromCodePoint(0x0300); // var COMBINE = 's𐨁'.substring(1); // s + combining -var COMBINE = String.fromCodePoint - ? String.fromCodePoint(0x10A01) - : String.fromCharCode(0xD802, 0xDE01); +// var COMBINE = String.fromCharCode(0xD802, 0xDE01); +var COMBINE = unicode.fromCodePoint(0x10A01); // At cols=44, the bug that is avoided by this occurs: // || angles[line[x + 1][1]]) {