Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: num_in_chars incremented after each mbrtowc()



On 6 December 2015 at 16:49, Peter Stephenson
<p.w.stephenson@xxxxxxxxxxxx> wrote:
> On Sun, 6 Dec 2015 10:37:21 +0100
> Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> Somebody complained about this function a couple of months ago and I
> explained, then, too; it suggests it needs some more comments, so I've
> added some.

It was me that complained. I couldn't get through to you with message
that num_in_char should be treated as representing single character.
Now you've written the same:

> +            * "num_in_char" is only used for incomplete characters.  The
> +            * assumption is that we will output this octet as a single
> +            * character (of single width) if we don't get a complete
> +            * character; if we do get a complete character, num_in_char

So, despite having num_in_char arbitrarily large, it represents single
character. The code in mb_metastrlenend() does something else:

    /* If incomplete, treat remainder as trailing single bytes */
    return num + num_in_char;

It should be:
    return num + num_in_char > 0 ? 1 : 0;

Best regards,
Sebastian Gniazdowski



Messages sorted by: Reverse Date, Date, Thread, Author