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

Re: bug report : printf %.1s outputting more than 1 character

On Wed, Mar 15, 2023 at 4:32 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Tue, Mar 14, 2023 at 9:56 PM Jason C. Kwan <jasonckwan@xxxxxxxxx> wrote:
> >
> > does the following ( below the "====" line ) behavior look even reasonable at all, regardless of your spec ? Because what the spec ends up doing is treating the rest of the input string as 1 byte and printing everything out, even though there are valid code points further down the input string.
> I'm not the resident expert on multibyte character sets, so I'm just
> reporting the situation and waiting for e.g. PWS to respond.  However,
> as far as my understanding of the multibyte library goes, once you've
> "desynchronized" the input by encountering an invalid byte, you're not
> guaranteed that anything further that you see can be correctly
> interpreted as a code point.  I agree that it's not ideal to just dump
> everything else "raw".

UTF-8 has a nice property that you can jump to an arbitrary byte
position in the stream and quickly find the start of the next
character. A byte is the start of a character if it has the most
significant bit equal to 0 or two most significant bits equal to 1.
This can also be used to recover after an invalid character.


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