zsh-workers
 help / color / mirror / code / Atom feed
* Subscript flag (i) not working correctly on empty strings?
@ 2023-01-06 16:01 Philippe Altherr
  2023-01-06 17:23 ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Philippe Altherr @ 2023-01-06 16:01 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 619 bytes --]

The following script

s=aaa; echo $s[(i)z];
> s=aa; echo $s[(i)z];
> s=a; echo $s[(i)z];

s=; echo $s[(i)z];


prints this

4
> 3
> 2
> 0


Why is the last line 0 and not 1? The documentation of (i) and (r) states
that if the pattern isn't found in the string, the length of the string
plus 1 is returned. I can't find anything that would explain the 0.

For arrays, (i) behaves as expected. The following script

a=(a a a); echo $a[(i)z];
> a=(a a); echo $a[(i)z];
> a=(a); echo $a[(i)z];

a=(); echo $a[(i)z];


prints this

4
> 3
> 2
> 1


Is the empty string behavior a bug or an (undocumented?) feature?

Philippe

[-- Attachment #2: Type: text/html, Size: 1710 bytes --]

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

end of thread, other threads:[~2023-01-08 19:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-06 16:01 Subscript flag (i) not working correctly on empty strings? Philippe Altherr
2023-01-06 17:23 ` Peter Stephenson
2023-01-06 18:12   ` Bart Schaefer
2023-01-07 13:45     ` Philippe Altherr
2023-01-07 13:52       ` Roman Perepelitsa
2023-01-07 13:54         ` Roman Perepelitsa
2023-01-08 19:47     ` Peter Stephenson

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).