zsh-users
 help / color / mirror / code / Atom feed
* A comment about "slurp" and -o multibyte
@ 2024-01-17  3:45 Bart Schaefer
  2024-01-17  6:07 ` Roman Perepelitsa
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2024-01-17  3:45 UTC (permalink / raw)
  To: Zsh Users

On Sun, Jan 14, 2024 at 2:34 AM Roman Perepelitsa
<roman.perepelitsa@gmail.com> 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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-17  7:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-17  3:45 A comment about "slurp" and -o multibyte Bart Schaefer
2024-01-17  6:07 ` Roman Perepelitsa
2024-01-17  7:06   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).