Christian Brabandt wrote:
> On Fr, 12 M=E4r 2010, Christian Brabandt wrote:
>
> > I just found out, that submatch eats my backslashes. Consider this
> > example:
> > ~$ gvim -u NONE -N -c ":put ='foo\bar'" -c ":%s/.\+/\=submatch(0)/"
> >
> > which gives you foobar instead of foo\bar.
> >
> >
> > Is there an easy way to prevent this without having me to remember, that
> > I need to escape submatch, just because it could contain backslashes?
> >
> > I know that \0 works correctly, but I need to call a function in the
> > replacement part.
>
> I believe this bug is also mentioned in the todo list:
> submatch() may remove backslash. (Sergey Goldgaber, 2009 Jul 6)
>
> So here is a patch, that fixes it, I believe. I don't know the source
> well enough to judge, whether this is the correct solution. But at
> least, this works for me™
>
> chrisbra t41:~/vim/src [1093]% hg diff
> diff -r 907cf09fbb32 src/regexp.c
> --- a/src/regexp.c Tue Mar 02 18:16:09 2010 +0100
> +++ b/src/regexp.c Mon Mar 22 10:13:51 2010 +0100
> @@ -7329,6 +7329,8 @@
> retval = vim_strnsave(s, (int)(submatch_match->endp[no] - s));
> }
>
> - return retval;
> + /* Parsing the \= expression in the substitution part will later on
> + * remove all backslashes. Therefore, we need to protect them here */
> + return vim_strsave_escaped(retval, (char_u *)"\\");
> }
> #endif
That will break substitute(). I'll make another solution.
--
ROBIN: (warily) And if you get a question wrong?
ARTHUR: You are cast into the Gorge of Eternal Peril.
ROBIN: Oh ... wacho!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ download, build and distribute -- http://www.A-A-P.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
To unsubscribe from this group, send email to
vim_use+unsubscribegooglegroups.com or reply to this email with the words
"REMOVE ME" as the subject.