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

Re: Question about mb_metastrlen

On Tue, 27 Oct 2015 09:31:02 +0100
Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> Hello,
> the function counts bytes in last incomplete wide character:
>         ret = mbrtowc(&wc, &inchar, 1, &mb_shiftstate);
>         if (ret == MB_INCOMPLETE) {
>             num_in_char++;
>         } else {
> When returning, it makes use of the count:
>     /* If incomplete, treat remainder as trailing single bytes */
>     return num + num_in_char;
> Strings are stored in wchar_t arrays. The incomplete character will
> occupy single index, correct? So maybe the return should be:
>     return num + ( num_in_char > 0 ? 1 : 0 );

The function you're talking about is for a string length, not a
character length.  num_in_char counts the number of trailing bytes that
didn't form a wide character.  Each will be treated as a single byte.
So each counts 1 for the length of the string.

I think your answer would be correct for a function that counts just the
next character (i.e. mb_metacharlenconv()), but I think that's already doing
what you'd expect in that case.

That's the intention of the function, anyway, but if you can see a use
that's inconsistent with it there could be a bug there.


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