diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-12-31 17:14:04 +0300 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2020-01-10 11:11:54 +0300 |
commit | 0da2084d7f0b8878c616642b2f1dd97b763b4035 (patch) | |
tree | d888106b4dfb5c073d95061fd6c43cdec61bdf8b /src/node_i18n.cc | |
parent | 9a1ffa4d7ca5e489179e6ccb2e892086fd23d855 (diff) |
src: change GetStringWidth's expand_emoji_sequence option default
The option is now set to true by default. Most terminals do not have
full emoji support and visualize emojis with zero width joiners as
individual emojis.
Also verify that at least one argument is always passed through to the
function and remove support for passing through code points. Only
accept strings from now on to simplify the API.
PR-URL: https://github.com/nodejs/node/pull/31112
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_i18n.cc')
-rw-r--r-- | src/node_i18n.cc | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/src/node_i18n.cc b/src/node_i18n.cc index 7cb7ab35d50..46c6ef39f86 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -767,18 +767,10 @@ static int GetColumnWidth(UChar32 codepoint, // Returns the column width for the given String. static void GetStringWidth(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); - if (args.Length() < 1) - return; + CHECK(args[0]->IsString()); bool ambiguous_as_full_width = args[1]->IsTrue(); - bool expand_emoji_sequence = args[2]->IsTrue(); - - if (args[0]->IsNumber()) { - uint32_t val; - if (!args[0]->Uint32Value(env->context()).To(&val)) return; - args.GetReturnValue().Set(GetColumnWidth(val, ambiguous_as_full_width)); - return; - } + bool expand_emoji_sequence = !args[2]->IsBoolean() || args[2]->IsTrue(); TwoByteValue value(env->isolate(), args[0]); // reinterpret_cast is required by windows to compile @@ -803,6 +795,7 @@ static void GetStringWidth(const FunctionCallbackInfo<Value>& args) { // in advance if a particular sequence is going to be supported. // The expand_emoji_sequence option allows the caller to skip this // check and count each code within an emoji sequence separately. + // https://www.unicode.org/reports/tr51/tr51-16.html#Emoji_ZWJ_Sequences if (!expand_emoji_sequence && n > 0 && p == 0x200d && // 0x200d == ZWJ (zero width joiner) (u_hasBinaryProperty(c, UCHAR_EMOJI_PRESENTATION) || |