* PATCH: (#m) broken for pure string matches
@ 2006-08-01 11:46 Peter Stephenson
0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2006-08-01 11:46 UTC (permalink / raw)
To: Zsh hackers list
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@csr.com> 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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-08-01 11:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-01 11:46 PATCH: (#m) broken for pure string matches 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).