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

Re: Patterns quoting in subscript (was: Re: PATCH: Assorted parameter stuff)



On Apr 18,  5:26pm, Bart Schaefer wrote:
}
} [...] So if you want to match 4 backslashes, you need 16 backslashes;
} but if you want to match 4 backslashes followed by a literal question
} mark, you need a whopping 34 backslashes, because you have to double
} all 16 of those backslashes and then add two more to quote the `?'
} itself.
}
} Clearly this is silly; it results because of the extra call to
} parsestr() that happens when the `needtok' loop in getarg() detects an
} ispecial() (the `?' in this example). I'll see if that can't be made
} to behave a bit more intelligibly.

By relocating one remnulargs() call relative to 14008 and removing one
INULL() "optimization", it's possible to get a consistent 4-to-1 ratio
of backslashes in the input subscript to match one backslash in the
array value by pattern match.

That applies only with (i) (I) (r) (R); it's the usual 2-to-1 ratio for
a direct associative-array lookup.

The following goes on top of 14008.

--- current/Src/params.c	Tue Apr 17 23:30:50 2001
+++ ../zsh-4.0/Src/params.c	Wed Apr 18 11:56:33 2001
@@ -919,22 +919,19 @@
 	    i++;
 	else if (c == Outbrack)
 	    i--;
-	if (INULL(c)) {
-	    if (!*++t)
-		break;
-	} else if (ispecial(c))
+	if (ispecial(c))
 	    needtok = 1;
     }
     if (!c)
 	return 0;
     s = dupstrpfx(s, t - s);
-    remnulargs(s);
     *str = tt = t;
     if (needtok) {
 	if (parsestr(s))
 	    return 0;
 	singsub(&s);
     }
+    remnulargs(s);
     if (!rev) {
 	if (ishash) {
 	    HashTable ht = v->pm->gets.hfn(v->pm);
@@ -942,7 +939,6 @@
 		ht = newparamtable(17, v->pm->nam);
 		v->pm->sets.hfn(v->pm, ht);
 	    }
-	    remnulargs(s);
 	    untokenize(s);
 	    if (!(v->pm = (Param) ht->getnode(ht, s))) {
 		HashTable tht = paramtab;

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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