On Tue, 24 Oct 2006 at 11:10am, Nikolai Weibull wrote:
> > > There should really be a third, optional, parameter to escape() where
> > > you can specify what character to use for escaping.
>
> > That wouldn't be real solution because to escape ' you still (in most
> > situations) would need two escape() calls. One for escape ' with ' and
> > second for rest of characters with \. The best solution is providing
> > info about context.
>
> I don't follow.  When would you need to escape both ' with '' and
> other characters with \?  The only "active" character in a
> single-quoted string is the single-quote itself.
>
> Oh, I see.  You're thinking of creating a string for passing to
> substitute() inside an :execute, or something like that.  Ah, true,
> then you'd need to escape the single-quotes for the string, and, e.g.,
> "." with "\.".  Escaping is a lot more difficult than one often
> thinks, I suppose.

I don't this this is a valid case either. The problem is only when you
need to use such strings with the :exec command (as that involves
concatenating strings), but if you are just passing on the string to
Vim functions, you don't have to worry about escaping single quotes.
Even when you need to concatenate and use a regex, you still need to
only escape the single-quotes and backslashes and use it in the \V mode,
something like:

'\V'.escape(substitute(regex, "'", "''", 'g'), '\')

-- 
Hari

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to