summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2019-07-11 09:31:30 -0400
committerMichaël Zasso <targos@protonmail.com>2019-07-20 11:10:24 +0200
commite0c5e7a9395042df5198fb75b13bbbbeb63f1a03 (patch)
tree1816ce143f757c16360d2d9b5271920e749f3cad /lib
parentf688122dff4f0726cd4fc89f2551b6949f86d23a (diff)
downloadandroid-node-v8-e0c5e7a9395042df5198fb75b13bbbbeb63f1a03.tar.gz
android-node-v8-e0c5e7a9395042df5198fb75b13bbbbeb63f1a03.tar.bz2
android-node-v8-e0c5e7a9395042df5198fb75b13bbbbeb63f1a03.zip
readline: use named constant for surrogate checks
This commit defines a named constant instead of using a mix of 2 ** 16 and 0x10000 throughout the code. PR-URL: https://github.com/nodejs/node/pull/28638 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/readline.js5
-rw-r--r--lib/readline.js9
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/internal/readline.js b/lib/internal/readline.js
index a561194297..c3f40c4fc4 100644
--- a/lib/internal/readline.js
+++ b/lib/internal/readline.js
@@ -8,7 +8,7 @@
const ansi =
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
/* eslint-enable no-control-regex */
-
+const kUTF16SurrogateThreshold = 0x10000; // 2 ** 16
const kEscape = '\x1b';
let getStringWidth;
@@ -63,7 +63,7 @@ if (internalBinding('config').hasIntl) {
for (var i = 0; i < str.length; i++) {
const code = str.codePointAt(i);
- if (code >= 0x10000) { // surrogates
+ if (code >= kUTF16SurrogateThreshold) { // Surrogates.
i++;
}
@@ -434,6 +434,7 @@ module.exports = {
emitKeys,
getStringWidth,
isFullWidthCodePoint,
+ kUTF16SurrogateThreshold,
stripVTControlCharacters,
CSI
};
diff --git a/lib/readline.js b/lib/readline.js
index 2c29eafc94..670559f82b 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -41,6 +41,7 @@ const {
emitKeys,
getStringWidth,
isFullWidthCodePoint,
+ kUTF16SurrogateThreshold,
stripVTControlCharacters
} = require('internal/readline');
@@ -600,8 +601,8 @@ Interface.prototype._wordRight = function() {
function charLengthLeft(str, i) {
if (i <= 0)
return 0;
- if (i > 1 && str.codePointAt(i - 2) >= 2 ** 16 ||
- str.codePointAt(i - 1) >= 2 ** 16) {
+ if (i > 1 && str.codePointAt(i - 2) >= kUTF16SurrogateThreshold ||
+ str.codePointAt(i - 1) >= kUTF16SurrogateThreshold) {
return 2;
}
return 1;
@@ -610,7 +611,7 @@ function charLengthLeft(str, i) {
function charLengthAt(str, i) {
if (str.length <= i)
return 0;
- return str.codePointAt(i) >= 2 ** 16 ? 2 : 1;
+ return str.codePointAt(i) >= kUTF16SurrogateThreshold ? 2 : 1;
}
Interface.prototype._deleteLeft = function() {
@@ -728,7 +729,7 @@ Interface.prototype._getDisplayPos = function(str) {
str = stripVTControlCharacters(str);
for (var i = 0, len = str.length; i < len; i++) {
code = str.codePointAt(i);
- if (code >= 0x10000) { // surrogates
+ if (code >= kUTF16SurrogateThreshold) { // Surrogates.
i++;
}
if (code === 0x0a) { // new line \n