Boost logo

Boost-Build :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-03-31 19:19:21


On Monday 31 March 2003 09:31 am, Vladimir Prus wrote:
> 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 )
> {
> .....
> }
>
> ?

Picky, picky :). But, of course, you're right. Refactored & retested code
below; okay?

Doug

Index: print.jam
===================================================================
RCS file: /cvsroot/boost/boost/tools/build/new/print.jam,v
retrieving revision 1.14
diff -c -3 -p -r1.14 print.jam
*** print.jam 30 Mar 2003 15:17:52 -0000 1.14
--- print.jam 1 Apr 2003 00:17:36 -0000
*************** rule text (
*** 243,250 ****
while $(strings)
{
local line-v = $(output-target).line.$($(output-target).line) ;
! local echo-string = [ regex.split $(strings[1]) "\"" ] ;
! echo-string = $(echo-string:J="\\\"") ;
$(line-v) on $(output-target) = $(echo-string) ;
NOCARE $(line-v) ;
NOTFILE $(line-v) ;
--- 243,249 ----
while $(strings)
{
local line-v = $(output-target).line.$($(output-target).line) ;
! local echo-string = [ escape $(strings[1]) ] ;
$(line-v) on $(output-target) = $(echo-string) ;
NOCARE $(line-v) ;
NOTFILE $(line-v) ;
*************** rule wrapped-text ( text + )
*** 275,287 ****
#
actions quietly text-action
{
! echo "$($(>))" >> $(<)
}

# Writes a single line to target file (overwriting or creating the
# file as necessary)
actions quietly text-overwrite-action {
! echo "$($(>))" > $(<)
}

local rule __test__ ( )
--- 274,302 ----
#
actions quietly text-action
{
! echo $($(>)) >> $(<)
}

# Writes a single line to target file (overwriting or creating the
# file as necessary)
actions quietly text-overwrite-action {
! echo $($(>)) > $(<)
! }
!
! if [ modules.peek : NT ]
! {
! rule escape ( string )
! {
! return [ regex.escape $(string) : "&|()<>^" : "^" ] ;
! }
! }
! else
! {
! rule escape ( string )
! {
! local escaped = [ regex.escape $(string) : "\\\"" : "\\" ] ;
! return "\"$(escaped)\"" ;
! }
}

local rule __test__ ( )
Index: regex.jam
===================================================================
RCS file: /cvsroot/boost/boost/tools/build/new/regex.jam,v
retrieving revision 1.6
diff -c -3 -p -r1.6 regex.jam
*** regex.jam 1 Oct 2002 14:50:25 -0000 1.6
--- regex.jam 1 Apr 2003 00:17:36 -0000
*************** rule transform ( list * : pattern )
*** 58,63 ****
--- 58,83 ----
return $(result) ;
}

+ # Escapes all of the characters in symbols using the escape symbol
+ # escape-symbol for the given string, and returns the escaped string
+ rule escape ( string : symbols : escape-symbol )
+ {
+ local result = "" ;
+ local m = 1 ;
+ while $(m)
+ {
+ m = [ MATCH ^([^$(symbols)]*)([$(symbols)])(.*) : $(string) ] ;
+ if $(m)
+ {
+ m += "" ; # Supposedly a bug fix; borrowed from regex.split
+ result = "$(result)$(m[1])$(escape-symbol)$(m[2])" ;
+ string = $(m[3]) ;
+ }
+ }
+ string ?= "" ;
+ result = "$(result)$(string)" ;
+ return $(result) ;
+ }

rule __test__ ( )
{
*************** rule __test__ ( )
*** 81,84 ****
--- 101,110 ----

assert.result a.h c.h
: transform <a.h> \"b.h\" <c.h> : <(.*)> ;
+
+ assert.result "^<?xml version=\"1.0\"^>"
+ : escape "<?xml version=\"1.0\">" : "&|()<>^" : "^" ;
+
+ assert.result "<?xml version=\\\"1.0\\\">"
+ : escape "<?xml version=\"1.0\">" : "\\\"" : "\\" ;
}

 


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