rename unicode regexes.

This commit is contained in:
Christopher Jeffrey 2015-04-26 04:29:52 -07:00
parent ccca1092e7
commit dafe95d900
3 changed files with 12 additions and 10 deletions

View File

@ -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'

View File

@ -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);

View File

@ -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]]) {