Skip to content

Commit 0383947

Browse files
cjihrigtargos
authored andcommitted
readline: simplify isFullWidthCodePoint()
The non-ICU-based isFullWidthCodePoint() can be simplified to a single `return` statement. This commit removes the extra branching logic. PR-URL: #28640 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent dc73403 commit 0383947

File tree

1 file changed

+30
-40
lines changed

1 file changed

+30
-40
lines changed

lib/internal/readline.js

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -82,48 +82,38 @@ if (internalBinding('config').hasIntl) {
8282
* Unicode code point is full-width. Otherwise returns false.
8383
*/
8484
isFullWidthCodePoint = function isFullWidthCodePoint(code) {
85-
if (!Number.isInteger(code)) {
86-
return false;
87-
}
88-
8985
// Code points are derived from:
9086
// http://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt
91-
if (
92-
code >= 0x1100 && (
93-
code <= 0x115f || // Hangul Jamo
94-
code === 0x2329 || // LEFT-POINTING ANGLE BRACKET
95-
code === 0x232a || // RIGHT-POINTING ANGLE BRACKET
96-
// CJK Radicals Supplement .. Enclosed CJK Letters and Months
97-
code >= 0x2e80 && code <= 0x3247 && code !== 0x303f ||
98-
// Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
99-
code >= 0x3250 && code <= 0x4dbf ||
100-
// CJK Unified Ideographs .. Yi Radicals
101-
code >= 0x4e00 && code <= 0xa4c6 ||
102-
// Hangul Jamo Extended-A
103-
code >= 0xa960 && code <= 0xa97c ||
104-
// Hangul Syllables
105-
code >= 0xac00 && code <= 0xd7a3 ||
106-
// CJK Compatibility Ideographs
107-
code >= 0xf900 && code <= 0xfaff ||
108-
// Vertical Forms
109-
code >= 0xfe10 && code <= 0xfe19 ||
110-
// CJK Compatibility Forms .. Small Form Variants
111-
code >= 0xfe30 && code <= 0xfe6b ||
112-
// Halfwidth and Fullwidth Forms
113-
code >= 0xff01 && code <= 0xff60 ||
114-
code >= 0xffe0 && code <= 0xffe6 ||
115-
// Kana Supplement
116-
code >= 0x1b000 && code <= 0x1b001 ||
117-
// Enclosed Ideographic Supplement
118-
code >= 0x1f200 && code <= 0x1f251 ||
119-
// CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
120-
code >= 0x20000 && code <= 0x3fffd
121-
)
122-
) {
123-
return true;
124-
}
125-
126-
return false;
87+
return Number.isInteger(code) && code >= 0x1100 && (
88+
code <= 0x115f || // Hangul Jamo
89+
code === 0x2329 || // LEFT-POINTING ANGLE BRACKET
90+
code === 0x232a || // RIGHT-POINTING ANGLE BRACKET
91+
// CJK Radicals Supplement .. Enclosed CJK Letters and Months
92+
code >= 0x2e80 && code <= 0x3247 && code !== 0x303f ||
93+
// Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
94+
code >= 0x3250 && code <= 0x4dbf ||
95+
// CJK Unified Ideographs .. Yi Radicals
96+
code >= 0x4e00 && code <= 0xa4c6 ||
97+
// Hangul Jamo Extended-A
98+
code >= 0xa960 && code <= 0xa97c ||
99+
// Hangul Syllables
100+
code >= 0xac00 && code <= 0xd7a3 ||
101+
// CJK Compatibility Ideographs
102+
code >= 0xf900 && code <= 0xfaff ||
103+
// Vertical Forms
104+
code >= 0xfe10 && code <= 0xfe19 ||
105+
// CJK Compatibility Forms .. Small Form Variants
106+
code >= 0xfe30 && code <= 0xfe6b ||
107+
// Halfwidth and Fullwidth Forms
108+
code >= 0xff01 && code <= 0xff60 ||
109+
code >= 0xffe0 && code <= 0xffe6 ||
110+
// Kana Supplement
111+
code >= 0x1b000 && code <= 0x1b001 ||
112+
// Enclosed Ideographic Supplement
113+
code >= 0x1f200 && code <= 0x1f251 ||
114+
// CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
115+
code >= 0x20000 && code <= 0x3fffd
116+
);
127117
};
128118
}
129119

0 commit comments

Comments
 (0)