zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: (#m) broken for pure string matches
Date: Tue, 01 Aug 2006 12:46:21 +0100	[thread overview]
Message-ID: <200608011146.k71BkLqk025578@news01.csr.com> (raw)

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


                 reply	other threads:[~2006-08-01 11:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200608011146.k71BkLqk025578@news01.csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).