This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH] New wcwidth/wcswidth implementation
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Corinna Vinschen on 5/13/2009 3:03 AM:
> + /* First half of a surrogate pair? */
> + if (sizeof (wchar_t) == 2 && wi >= 0xd800 && wi <= 0xdbff)
> + {
> + wint_t wi2;
> +
> + /* Extract second half and check for validity. */
> + if (--n == 0 || (wi2 = *++pwcs) < 0xdc00 || wi2 > 0xdfff)
> + return -1;
Should we also set errno = EILSEQ here? Although POSIX doesn't require
it, it also doesn't forbid it (after all, using UTF16 is already a POSIX
violation).
> + /* Compute actual unicode value to use in call to __wcwidth. */
> + wi = (((wi & 0x3ff) << 10) | (wi2 & 0x3ff)) + 0x10000;
> + }
> + if ((w = __wcwidth (wi)) < 0)
> return -1;
Whereas here we intentionally leave errno alone; that way the user can
distinguish between invalid UTF16 sequence vs. a sequence with valid but
non-printable characters.
- --
Don't work too hard, make some time for fun as well!
Eric Blake ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkoKtsQACgkQ84KuGfSFAYAvvgCfa1M/+dVGHsUoFEIspSbw5BCC
SSMAn1gEjRw5ucOYYFFIk3e2vsOYZqR1
=Uet6
-----END PGP SIGNATURE-----