From dafe95d90049f3b0c8fe320da020cc5b05fc2df1 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 26 Apr 2015 04:29:52 -0700 Subject: [PATCH] rename unicode regexes. --- lib/unicode.js | 11 ++++++----- lib/widget.js | 8 ++++---- test/widget-eaw.js | 3 ++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/unicode.js b/lib/unicode.js index b21ae77..21bae12 100644 --- a/lib/unicode.js +++ b/lib/unicode.js @@ -549,7 +549,8 @@ exports.wideChars = new RegExp('([' + '\\uffe0-\\uffe6' + '])', 'g'); -exports.allWide = new RegExp('(' +// All wide chars including surrogate pairs. +exports.allWideChars = new RegExp('(' // 0x20000 - 0x2fffd: + '[\\ud840-\\ud87f][\\udc00-\\udffd]' + '|' @@ -560,10 +561,10 @@ exports.allWide = new RegExp('(' + ')', 'g'); // Regex to detect a surrogate pair. -exports.surrogate = /[\ud800-\udbff][\udc00-\udfff]/g; +exports.surrogateChars = /[\ud800-\udbff][\udc00-\udfff]/g; // Regex to find combining characters. -exports.combiningRegex = exports.combiningTable.reduce(function(out, row) { +exports.combiningChars = exports.combiningTable.reduce(function(out, row) { var low, high, range; if (row[0] > 0x00ffff) { low = exports.fromCodePoint(row[0]); @@ -590,7 +591,7 @@ exports.combiningRegex = exports.combiningTable.reduce(function(out, row) { return out; }, '['); -exports.combiningRegex = new RegExp(exports.combiningRegex, 'g'); +exports.combiningChars = new RegExp(exports.combiningChars, 'g'); function hexify(n) { n = n.toString(16); @@ -599,7 +600,7 @@ function hexify(n) { } /* -exports.combiningRegex = new RegExp( +exports.combiningChars = new RegExp( '[' + '\\u0300-\\u036f' + '\\u0483-\\u0486' diff --git a/lib/widget.js b/lib/widget.js index f1f7f5e..df097b0 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -2427,14 +2427,14 @@ Element.prototype.parseContent = function(noTags) { content = content.replace(unicode.wideChars, '$1_'); } else { // no double-width: replace them with question-marks. - content = content.replace(unicode.allWide, '??'); + content = content.replace(unicode.allWideChars, '??'); // delete combining characters since they're 0-width anyway. // NOTE: We could drop this, the non-surrogates would get changed to ? by // the unicode filter, and surrogates changed to ? by the surrogate // regex. however, the user might expect them to be 0-width. - content = content.replace(unicode.combiningRegex, ''); + content = content.replace(unicode.combiningChars, ''); // no surrogate pairs: replace them with question-marks. - content = content.replace(unicode.surrogate, '?'); + content = content.replace(unicode.surrogateChars, '?'); } if (!noTags) { @@ -2769,7 +2769,7 @@ main: } // Pad the end of the lines if the surrogate is not a double-width char. // var surrogates = out[i].length - punycode.ucs2.decode(out[i]).length; - var surrogates = out[i].match(unicode.surrogate); + var surrogates = out[i].match(unicode.surrogateChars); if (surrogates && surrogates.length) { for (var j = 0; j < surrogates.length; j++) { var cwid = unicode.charWidth(surrogates[j], 0); diff --git a/test/widget-eaw.js b/test/widget-eaw.js index 4495bbe..67c2f6f 100644 --- a/test/widget-eaw.js +++ b/test/widget-eaw.js @@ -1,4 +1,5 @@ var blessed = require('../') + , unicode = blessed.unicode , screen; screen = blessed.screen({ @@ -44,7 +45,7 @@ var COMBINE = String.fromCodePoint ? String.fromCodePoint(0x0300) : String.fromCharCode(0x0300); -var COMBINE = blessed.unicode.fromCodePoint(0x10A01); +var COMBINE = unicode.fromCodePoint(0x10A01); // At cols=44, the bug that is avoided by this occurs: // || angles[line[x + 1][1]]) {