[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#842191: ITP: node-is-fullwidth-code-point -- Check if the character represented by a given Unicode code point is fullwidth



On Thu, Oct 27, 2016 at 10:00:37AM +0530, Pirate Praveen wrote:
> On Thursday 27 October 2016 02:21 AM, Adam Borowski wrote:
> > On Thu, Oct 27, 2016 at 12:49:31AM +0530, suhail_p wrote:
> >> * Package name    : node-is-fullwidth-code-point
> >>   Upstream Author : Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com
> >> )
> >> * URL             :
> >> https://github.com/sindresorhus/is-fullwidth-code-point#readme
> >>   Description     : Check if a given Unicode point is fullwidth
> >>
> >>  A Nodejs modeule to check if the character represented by a given Unicode
> >> code point is fullwidth
> > 
> > Wouldn't it be better to replace this with full wcwidth()?  That'd give you
> > not only double-width chars but also controls ("width" -1), combining and
> > non-spacing (width 0).
> 
> It is a dependency for https://github.com/sindresorhus/string-width you
> can suggest upstream to use this.

Well, but why would you use code that's so buggy?  If it has literally one
job, it should at least do that job right.

I see string-width ignores controls (0..0x1f, 0x7f..0x9f) on its own, so
that's handled.  It reacts to them differently than POSIX wcswidth()
(silently ignores instead of returning an error for the whole string) but
as there's no good answer that's acceptable.

But, without having a case for width 0, string-width fails to handle any
non-spacing or combining characters.  The former happen quite often in text
produced by some software, sometimes even in surprising cases as plain
German words like "Auflage" -- without a ZWNJ between f and l they'd be
combined into a ligature.  The latter are required for a number of
languages, such as Vietnamese which tends to decorate every letter with two
or more combining characters.

Thus, I recommend scrapping this ITP, and instead packaging one of many
implementations without these problems.  One for these that looks rightish
is https://github.com/mycoboco/wcwidth.js

You would then patch string-width:
-		if (isFullwidthCodePoint(code)) {
-			width += 2;
-		} else {
-			width++;
-		}
+		width += wcwidth(code);

-- 
A MAP07 (Dead Simple) raspberry tincture recipe: 0.5l 95% alcohol, 1kg
raspberries, 0.4kg sugar; put into a big jar for 1 month.  Filter out and
throw away the fruits (can dump them into a cake, etc), let the drink age
at least 3-6 months.


Reply to: