public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Thomas Wolff <towo@towo.net>
To: cygwin@cygwin.com
Subject: Re: Unicode width data inconsistent/outdated
Date: Thu, 03 Aug 2017 19:44:00 -0000	[thread overview]
Message-ID: <1244bd24-bb27-d185-1f24-61beae02c2cd@towo.net> (raw)
In-Reply-To: <20170728195826.GI24013@calimero.vinschen.de>

Am 28.07.2017 um 21:58 schrieb Corinna Vinschen:
> On Jul 26 23:43, Thomas Wolff wrote:
>> Am 26.07.2017 um 11:50 schrieb Corinna Vinschen:
>>> On Jul 26 03:16, Yaakov Selkowitz wrote:
>>>> On 2017-07-26 03:08, Corinna Vinschen wrote:
>>>>> On Jul 26 08:49, Thomas Wolff wrote:
>>>>>> It would be good to keep wcwidth/wcswidth in sync with the installed
>>>>>> Unicode data version (package unicode-ucd).
>>>>>> Currently it seems to be hard-coded (in newlib/libc/string/wcwidth.c);
>>>>>> it refers to Unicode 5.0 while installed Unicode data suggest 9.0 would
>>>>>> be used.
>>>>>> I can provide some scripts to generate the respective tables if desired.
>>>>>> Thomas
>>>>> If you can update the newlib files this way and send matching patches
>>>>> to the newlib list, this would be highly appreciated.
>>>> Thomas, I just updated unicode-ucd to 10.0 for this purpose.
>> Thanks.
>>> Oh, and, btw, the comment in wcwidth.c isn't quite correct.  The
>>> cwstate in newlib is on Unicode 5.2, see newlib/libc/ctype/towupper.c.
>> Oh, a number of other embedded tables. To make the tow* and isw* functions
>> more easily adaptable to Unicode updates, there will be some revisions to do
>> here. And the to* and is* ones (without 'w') even refer to locales in a way
>> I do not understand. Maybe I'll restrict my effort to wcwidth first...
> The to* and is* ones (without 'w') don't matter at all and you don't
> have to touch them.
>
> The Unicode stuff only affects the tow and isw functions.
>
> As for how to fetch the data, you may want to have a look into
> newlib/libc/ctype/utf8alpha.h and newlib/libc/ctype/utf8print.h.  The
> header comments contain the awk scripts used to collect the data.
But there are no instructions to adapt the embedded conditional 
statements referring to those data...
My attempt would be to base the functions on a common table of character 
categories instead.

> All other isw* files like iswblank.c contain comments explaining
> what Unicode character categories are covered.
I'm comparing results based on Unicode 5.2 data. There will be some 
deviations and maybe some things to discuss.
For example, I wonder why in the current implementation currency symbols 
are considered as punctuation (which can be easily reproduced).

Also, there are 3 other issues:


Issue 1 is about handling non-BMP characters by wcwidth.
This has been discussed before.

On Mon, 31 Jan 2011 09:58:19 -0700 
(https://sourceware.org/ml/cygwin/2011-01/msg00453.html)
Erik Blake wrote:
> POSIX requires that 1 wchar_t corresponds to 1 character; so any use 
> of surrogates to get the full benefit of UTF-16 falls outside the 
> bounds of POSIX.
> At which point, the POSIX definition of those functions no longer 
> apply, and we can (try) to make the various wc* functions try to 
> behave as smartly as possible (as is the case with Cygwin); where 
> those smarts are only needed when you use surrogate pairs.

On Wed, 2 Feb 2011 12:29:03 +0100 
(https://sourceware.org/ml/cygwin/2011-02/msg00037.html)
Bruno Haible wrote:
> Code that uses <wctype.h> and wcwidth() is written precisely according 
> to POSIX.
> The problem is that this code cannot work correctly when wchar_t[] is 
> in UTF-16 encoding.
> There simply is no way to define these functions in a reasonable way 
> for surrogates.
I don’t agree with this, see below.

On Wed, 2 Feb 2011 13:21:02 +0100 
(https://sourceware.org/ml/cygwin/2011-02/msg00040.html)
Corinna Vinschen wrote:
> And, please note the wording in SUSv4, for instance in 
> http://calimero.vinschen.de/susv4/functions/iswalpha.html
(not found)
>   The wc argument is a wint_t, the value of which the application shall
>                        ^^^^^^                         ^^^^^^^^^^^
>   ensure is a wide-character code corresponding to a valid character 
> in the current locale, or equal to the value of the macro WEOF. If the 
> argument has any other value, the behavior is undefined.
> I don't see any words in that which would disallow to convert UTF-16 
> wchar_t surrogates to a wint_t UTF-32 value before calling one of the 
> wctype functions.  Just like you have to be careful not to call the 
> ctype functions with a signed char.

While wcswidth works already (using internal __wcwidth), and the isw* 
and tow* functions work as well because they use wint_t, wcwidth is the 
only function (inconsistently insisting on wchar_t) that does not work.
But note https://linux.die.net/man/3/wcwidth which says
> Note that glibc before 2.2.5 used the prototype
> int wcwidth(wint_t c);
Why not revert to wcwidth(wint_t)?
I think for cygwin it is the only solution that makes wcwidth work for 
non-BMP characters and is also compatible (unlike some proposals 
discussed later in the quoted thread).


Issue 2 is the handling of titlecase characters (e.g. "Nj" as one 
Unicode character U+01CB). The current implementation considers them to 
be both upper and lower (iswupper: return towlower (c) != c); I'd rather 
consider them as neither upper nor lower (iswalpha (c) && towupper (c) 
== c).
https://linux.die.net/man/3/iswupper allows both interpretations:
> The wide-character class "upper" contains *at least* those characters 
> wc which are equal to towupper(wc) and different from towlower(wc).


Issue 3 is the special conversion jp2uc which seems to be half-bred; 
there is no such handling for Chinese or Korean.
If by definition the arguments of isw* functions are not Unicode but 
wide characters according of the current locale (not sure where that is 
defined), they must be transformed for all locales (CJK and also 8-bit 
ones);
also in towupper and towlower the result must be transformed back to the 
current locale encoding (now missing).


Thomas

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

  reply	other threads:[~2017-08-03 19:44 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-26 14:23 Thomas Wolff
2017-07-26 14:59 ` Corinna Vinschen
2017-07-26 17:03   ` Yaakov Selkowitz
2017-07-26 17:06     ` Corinna Vinschen
2017-07-27 17:09       ` Thomas Wolff
2017-07-29 15:23         ` Corinna Vinschen
2017-08-03 19:44           ` Thomas Wolff [this message]
2017-08-04 17:02             ` Corinna Vinschen
2017-08-05 19:06               ` Thomas Wolff
2017-08-05 20:24                 ` Brian Inglis
2017-08-05 20:53                   ` Thomas Wolff
2017-08-07  9:28                 ` Corinna Vinschen
2017-08-07 10:41                   ` Corinna Vinschen
2017-08-07 19:07                   ` Brian Inglis
2017-08-07 19:31                     ` Thomas Wolff
2017-08-07 21:29                       ` Brian Inglis
2017-08-08  0:29                         ` Thomas Wolff
2017-08-07 19:27                   ` Thomas Wolff
2017-08-08  8:22                     ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1244bd24-bb27-d185-1f24-61beae02c2cd@towo.net \
    --to=towo@towo.net \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).