Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: (#m) broken for pure string matches
- X-seq: zsh-workers 22572
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx (Zsh hackers list)
- Subject: PATCH: (#m) broken for pure string matches
- Date: Tue, 01 Aug 2006 12:46:21 +0100
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
Some time in the recent past I've broken the use of (#m) to set $MATCH
to the matched string when the pattern is a pure string. This must be
because it's been optimised to take the pure string branch in more
cases. Hence the fix is to set $MATCH on that branch.
Index: Src/pattern.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/pattern.c,v
retrieving revision 1.38
diff -u -r1.38 pattern.c
--- Src/pattern.c 25 Jul 2006 18:10:38 -0000 1.38
+++ Src/pattern.c 1 Aug 2006 11:45:23 -0000
@@ -1915,6 +1915,32 @@
patinlen = (int)prog->patmlen;
/* if matching files, must update globbing flags */
patglobflags = prog->globend;
+
+ if ((patglobflags & GF_MATCHREF) &&
+ !(patflags & PAT_FILE)) {
+ char *str = ztrduppfx(patinstart, patinlen);
+ char *ptr = patinstart;
+ int mlen = 0;
+
+ /*
+ * Count the characters. We're not using CHARSUB()
+ * because the string is still metafied. We're
+ * not using mb_metastrlen() because that expects
+ * the string to be null terminated.
+ */
+ MB_METACHARINIT();
+ while (ptr < patinstart + patinlen) {
+ mlen++;
+ ptr += MB_METACHARLEN(ptr);
+ }
+
+ setsparam("MATCH", str);
+ setiparam("MBEGIN",
+ (zlong)(patoffset + !isset(KSHARRAYS)));
+ setiparam("MEND",
+ (zlong)(mlen + patoffset +
+ !isset(KSHARRAYS) - 1));
+ }
}
}
Index: Test/D04parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v
retrieving revision 1.18
diff -u -r1.18 D04parameter.ztst
--- Test/D04parameter.ztst 24 Jul 2006 22:00:21 -0000 1.18
+++ Test/D04parameter.ztst 1 Aug 2006 11:45:24 -0000
@@ -824,6 +824,11 @@
>MATCH 16 20 MATCH
>5
+ string='this is a string'
+ print ${string//(#m)s/$MATCH $MBEGIN $MEND}
+0:(#m) flag with pure string
+>this 4 4 is 7 7 a s 11 11tring
+
print -l JAMES${(u)${=:-$(echo yes yes)}}JOYCE
print -l JAMES${(u)${=:-$(echo yes yes she said yes i will yes)}}JOYCE
0:Bug with (u) flag reducing arrays to one element
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
Messages sorted by:
Reverse Date,
Date,
Thread,
Author