* bug in 'b' array parameter subscript flag
@ 2009-09-04 23:13 Greg Klanderman
2009-09-05 19:07 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Greg Klanderman @ 2009-09-04 23:13 UTC (permalink / raw)
To: Zsh list
when the 'b' flag is used with the 'i' flag, and there are no elements
to be searched, '0' is incorrectly returned rather than one plus the
array length:
[~] phl| zsh -f
phl% echo $ZSH_VERSION
4.3.10-dev-1
phl% echo $ZSH_PATCHLEVEL
1.4718
phl% unsetopt ksharrays
phl% a=(bar)
phl% echo $#a
1
phl% echo ${a[(ib:2:)foo]} ## BUG: this should return 2
0
phl% echo ${a[(i)foo]} ## just like this
2
the 'b' flag works correctly when the number of elements to be
searched is non-zero:
phl% a=(bar baz)
phl% echo $#a
2
phl% echo ${a[(ib:2:)foo]}
3
also, the 'i' flag alone, with no elements to search works correctly:
phl% a=()
phl% echo $#a
0
phl% echo ${a[(i)foo]}
1
cheers,
greg
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: bug in 'b' array parameter subscript flag
2009-09-04 23:13 bug in 'b' array parameter subscript flag Greg Klanderman
@ 2009-09-05 19:07 ` Peter Stephenson
2009-09-10 3:42 ` Greg Klanderman
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2009-09-05 19:07 UTC (permalink / raw)
To: Zsh list
On Fri, 4 Sep 2009 19:13:54 -0400
Greg Klanderman <gak@klanderman.net> wrote:
> when the 'b' flag is used with the 'i' flag, and there are no elements
> to be searched, '0' is incorrectly returned rather than one plus the
> array length:
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.156
diff -u -r1.156 params.c
--- Src/params.c 8 May 2009 14:30:35 -0000 1.156
+++ Src/params.c 5 Sep 2009 19:05:21 -0000
@@ -1345,6 +1345,11 @@
len = arrlen(ta);
if (beg < 0)
beg += len;
+ if (down) {
+ if (beg < 0)
+ return 0;
+ } else if (beg >= len)
+ return len + 1;
if (beg >= 0 && beg < len) {
if (down) {
if (!hasbeg)
@@ -1363,6 +1368,11 @@
len = arrlen(ta);
if (beg < 0)
beg += len;
+ if (down) {
+ if (beg < 0)
+ return 0;
+ } else if (beg >= len)
+ return len + 1;
if (beg >= 0 && beg < len) {
if (down) {
if (!hasbeg)
Index: Test/D04parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v
retrieving revision 1.37
diff -u -r1.37 D04parameter.ztst
--- Test/D04parameter.ztst 5 Jun 2009 11:15:53 -0000 1.37
+++ Test/D04parameter.ztst 5 Sep 2009 19:05:21 -0000
@@ -998,6 +998,34 @@
>sunny
>day
+# ' emacs likes this close quote
+
+ a=(sping spang spong bumble)
+ print ${a[(i)spong]}
+ print ${a[(i)spung]}
+ print ${a[(ib.1.)spong]}
+ print ${a[(ib.4.)spong]}
+ print ${a[(ib.10.)spong]}
+0:In and out of range reverse matched indices without and with b: arrays
+>3
+>5
+>3
+>5
+>5
+
+ a="thrimblewuddlefrong"
+ print ${a[(i)w]}
+ print ${a[(i)x]}
+ print ${a[(ib.3.)w]}
+ print ${a[(ib.10.)w]}
+ print ${a[(ib.30.)w]}
+0:In and out of range reverse matched indices without and with b: strings
+>9
+>20
+>9
+>20
+>20
+
foo="line:with::missing::fields:in:it"
print -l ${(s.:.)foo}
0:Removal of empty fields in unquoted splitting
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: bug in 'b' array parameter subscript flag
2009-09-05 19:07 ` Peter Stephenson
@ 2009-09-10 3:42 ` Greg Klanderman
0 siblings, 0 replies; 3+ messages in thread
From: Greg Klanderman @ 2009-09-10 3:42 UTC (permalink / raw)
To: zsh-workers
Thank you Peter!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-09-10 3:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-04 23:13 bug in 'b' array parameter subscript flag Greg Klanderman
2009-09-05 19:07 ` Peter Stephenson
2009-09-10 3:42 ` Greg Klanderman
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).