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

A comment about "slurp" and -o multibyte



On Sun, Jan 14, 2024 at 2:34 AM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
>     function slurp() {
>       emulate -L zsh -o no_multibyte
> [...]
>       typeset -g REPLY=${(j::)content}
>     }

Although the function faithfully reads the input stream into $REPLY,
later references to $REPLY with the multibyte option back in effect
will (re-)interpret the content as multibyte characters.  This may not
be what's desired.

% slurp < =zsh
% () {
print $#REPLY
print ${(m)#REPLY}
print ${(mm)#REPLY}
setopt localoptions nomultibyte
print $#REPLY
}
872903  <-- number of characters
873259  <-- width of printable characters
872383  <-- number of glyphs
878288  <-- actual number of bytes

(Of course those first three numbers are all garbage because it's just
interpreting an executable as wide character text.)

Unfortunately there's no parameter flag to toggle multibyte for a
single expansion.




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