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

PATCH: Re: Beginning of line matching



"Bart Schaefer" wrote:
> On Mar 26, 12:31pm, Ian Lynagh wrote:
> } 
> } I would have expected ${FOO/(#s)/X} and ${${FOO/(#m)(#s)?/X$MATCH}:-X}
> } to be equivalent, but it seems that only the second one has the desired
> } effect when FOO is not empty. Is there a reason the first doesn't behave
> } as I expected?
> 
> AFAICT, it's because "start of string" is considered to begin with the
> first real character, thus after the implicit intial empty substring.
> 
> This should probably be considered a bug.
> 
> Compare ${FOO/()/X}, and also ${FOO//()/X} ...

It seems to be this simple to fix all these problems.  I think the test
for a non-zero-length match was to try and avoid possible problems
caused by infinite loops, but I don't see anything that would cause
infinite loops.  The parameter tests still pass (other forms of pattern
matching aren't affected).

This could probably go in 4.0, I suppose.

Index: Src/glob.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/glob.c,v
retrieving revision 1.25
diff -u -r1.25 glob.c
--- Src/glob.c	22 Feb 2002 17:28:06 -0000	1.25
+++ Src/glob.c	8 Apr 2002 17:38:39 -0000
@@ -2291,7 +2291,7 @@
 		for (; t < s + l; t++, patoffset++) {
 		    /* Find the longest match from this position. */
 		    set_pat_start(p, t-s);
-		    if (pattry(p, t) && patinput > t) {
+		    if (pattry(p, t)) {
 			char *mpos = patinput;
 			if (!(fl & SUB_LONG) && !(p->flags & PAT_PURES)) {
 			    char *ptr;
@@ -2371,7 +2371,7 @@
 		if (t > s && t[-1] == Meta)
 		    t--;
 		set_pat_start(p, t-s);
-		if (pattry(p, t) && patinput > t && !--n) {
+		if (pattry(p, t) && !--n) {
 		    /* Found the longest match */
 		    char *mpos = patinput;
 		    if (!(fl & SUB_LONG) && !(p->flags & PAT_PURES)) {

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



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