Boost logo

Boost-Build :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-03-31 09:31:47


Douglas Gregor wrote:

> The patch below properly escapes strings for use with the "echo" command.
> Tested with the BoostBook XML catalog (lots of escaped characters there)
> under Windows XP cmd.exe, Cygwin, and Linux (bash); no problems. Okay to
> commit?
>
> Doug
>
> Index: print.jam

[...]

> ! if [ modules.peek : NT ]
> ! {
> ! rule escape ( string )
> ! {
> ! local result = "" ;
> ! local m = [ MATCH ^([^&|()<>^]*)([&|()<>^])(.*) : $(string) ] ;
> ! while $(m)
> ! {
> ! m += "" ; # Supposedly a bug fix; borrowed from regex.split
> ! result = "$(result)$(m[1])^$(m[2])" ;
> ! string = $(m[3]) ;
> ! m = [ MATCH ^([^&|()<>^]*)([&|()<>^])(.*) : $(string) ] ;
> ! }
> ! string ?= "" ;
> ! result = "$(result)$(string)" ;
> ! return $(result) ;
> ! }
> ! }
> ! else
> ! {
> ! rule escape ( string )
> ! {
> ! local result = "" ;
> ! local m = [ MATCH ^([^\\\"]*)([\\\"])(.*) : $(string) ] ;
> ! while $(m)
> ! {
> ! m += "" ; # Supposedly a bug fix; borrowed from regex.split
> ! result = "$(result)$(m[1])\\$(m[2])" ;
> ! string = $(m[3]) ;
> ! m = [ MATCH ^([^\\\"]*)([\\\"])(.*) : $(string) ] ;
> ! }
> ! string ?= "" ;
> ! result = "\"$(result)$(string)\"" ;
> ! return $(result) ;
> ! }
> }

Doug, if you allow me some nitpicking, I think there are some problems with
this. Both definitions 'escape' are very similiar. I think it would be better
to factor out common code. Probably, a rule in the regex module:

rule escape ( string : symbols : escape-symbol )
{
.....
}

?

- Volodya

 


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk