diff --git a/v2/util/numbers.jam b/v2/util/numbers.jam index ec546689e..6f4680336 100644 --- a/v2/util/numbers.jam +++ b/v2/util/numbers.jam @@ -187,7 +187,7 @@ rule __test__ ( ) assert.result 10000123456 : trim-leading-zeroes 10000123456 ; assert.result 10000 : trim-leading-zeroes 10000 ; assert.result 10000 : trim-leading-zeroes 00010000 ; - + assert.true less 1 2 ; assert.true less 1 12 ; assert.true less 1 21 ; diff --git a/v2/util/regex.jam b/v2/util/regex.jam index 1b59f86a8..234c36f62 100644 --- a/v2/util/regex.jam +++ b/v2/util/regex.jam @@ -1,17 +1,18 @@ -# Copyright 2001, 2002 Dave Abrahams -# Copyright 2003 Douglas Gregor -# Copyright 2003 Rene Rivera -# Copyright 2002, 2003, 2004, 2005 Vladimir Prus -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) +# Copyright 2001, 2002 Dave Abrahams +# Copyright 2003 Douglas Gregor +# Copyright 2003 Rene Rivera +# Copyright 2002, 2003, 2004, 2005 Vladimir Prus +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) # # Returns a list of the following substrings: -# 1) from beginning till the first occurence of 'separator' or till the end, -# 2) between each occurence of 'separator' and the next occurence, -# 3) from the last occurence of 'separator' till the end. +# 1) from beginning till the first occurrence of 'separator' or till the end, +# 2) between each occurrence of 'separator' and the next occurrence, +# 3) from the last occurrence of 'separator' till the end. # If no separator is present, the result will contain only one element. # + rule split ( string separator ) { local result ; @@ -22,20 +23,23 @@ rule split ( string separator ) while $(match) { match = [ MATCH ^(.*)($(separator))(.*) : $(s) ] ; - if $(match) { - match += "" ; # in case 3rd item was empty - works around MATCH bug + if $(match) + { + match += "" ; # in case 3rd item was empty - works around MATCH bug result = $(match[3]) $(result) ; s = $(match[1]) ; } } # Combine the remaining part at the beginning, which does not have - # separators, with the pieces broken off. - # Note that rule's signature does not allow initial s to be empty. + # separators, with the pieces broken off. Note that the rule's signature + # does not allow the initial s to be empty. return $(s) $(result) ; } -# Returns the concatenated results of Applying regex.split to every -# element of list using the separator pattern. + +# Returns the concatenated results of Applying regex.split to every element of +# the list using the separator pattern. +# rule split-list ( list * : separator ) { local result ; @@ -45,9 +49,10 @@ rule split-list ( list * : separator ) } return $(result) ; } - -# Match string against pattern, and return the elements indicated by -# indices. + + +# Match string against pattern, and return the elements indicated by indices. +# rule match ( pattern : string : indices * ) { indices ?= 1 2 3 4 5 6 7 8 9 ; @@ -55,10 +60,10 @@ rule match ( pattern : string : indices * ) return $(x[$(indices)]) ; } -# Matches all elements of 'list' agains the 'pattern' -# and returns a list of the elements indicated by indices of -# all successfull matches. If 'indices' is omitted returns -# a list of first paranthethised groups of all successfull + +# Matches all elements of 'list' agains the 'pattern' and returns a list of +# elements indicated by indices of all successful matches. If 'indices' is +# omitted returns a list of first paranthethised groups of all successful # matches. # rule transform ( list * : pattern : indices * ) @@ -71,41 +76,44 @@ rule transform ( list * : pattern : indices * ) if $(m) { result += $(m[$(indices)]) ; - } + } } return $(result) ; } NATIVE_RULE regex : transform ; -# Escapes all of the characters in symbols using the escape symbol -# escape-symbol for the given string, and returns the escaped string + +# 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) + local result = "" ; + local m = 1 ; + while $(m) { - m += "" ; # Supposedly a bug fix; borrowed from regex.split - result = "$(result)$(m[1])$(escape-symbol)$(m[2])" ; - string = $(m[3]) ; + 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) ; + string ?= "" ; + result = "$(result)$(string)" ; + return $(result) ; } -# Replaces occurances of a match string in a given string. Returns the -# new string. The match string can be a regex expression. + +# Replaces occurrences of a match string in a given string and returns the new +# string. The match string can be a regex expression. # rule replace ( - string # The string to modify. - match # The characters to replace. - replacement # The string to replace with. + string # The string to modify. + match # The characters to replace. + replacement # The string to replace with. ) { local result = "" ; @@ -125,9 +133,9 @@ rule replace ( return $(result) ; } -# Replaces occurances of a match string in a given list of strings. -# Returns the list of new strings. The match string can be a regex -# expression. + +# Replaces occurrences of a match string in a given list of strings and returns +# a list of new strings. The match string can be a regex expression. # # list - the list of strings to modify. # match - the search expression. @@ -143,6 +151,7 @@ rule replace-list ( list * : match : replacement ) return $(result) ; } + rule __test__ ( ) { import assert ; @@ -153,28 +162,28 @@ rule __test__ ( ) assert.result "" a "" b c : split "/a//b/c" / ; assert.result "" a "" b c "" : split "/a//b/c/" / ; assert.result "" a "" b c "" "" : split "/a//b/c//" / ; - + assert.result a c b d - : match (.)(.)(.)(.) : abcd : 1 3 2 4 ; - + : match (.)(.)(.)(.) : abcd : 1 3 2 4 ; + assert.result a b c d - : match (.)(.)(.)(.) : abcd ; - + : match (.)(.)(.)(.) : abcd ; + assert.result ababab cddc - : match ((ab)*)([cd]+) : abababcddc : 1 3 ; + : match ((ab)*)([cd]+) : abababcddc : 1 3 ; - assert.result a.h c.h - : transform \"b.h\" : <(.*)> ; + assert.result a.h c.h + : transform \"b.h\" : <(.*)> ; - assert.result a.h b.h c.h - : transform \"b.h\" : <([^>]*)>|\"([^\"]*)\" : 1 2 ; + assert.result a.h b.h c.h + : transform \"b.h\" : <([^>]*)>|\"([^\"]*)\" : 1 2 ; assert.result "^" - : escape "" : "&|()<>^" : "^" ; - + : escape "" : "&|()<>^" : "^" ; + assert.result "" - : escape "" : "\\\"" : "\\" ; - + : escape "" : "\\\"" : "\\" ; + assert.result "string string " : replace "string string " " " " " ; assert.result " string string" : replace " string string" " " " " ; assert.result "string  string" : replace "string string" " " " " ; diff --git a/v2/util/sequence.jam b/v2/util/sequence.jam index b190b8928..73919a65d 100644 --- a/v2/util/sequence.jam +++ b/v2/util/sequence.jam @@ -204,8 +204,8 @@ rule unique ( list * : stable ? ) } -# Returns the maximum number in 'elements'. Uses 'ordered' for comparisons, or -# 'numbers.less' is none is provided. +# Returns the maximum number in 'elements'. Uses 'ordered' for comparisons or +# 'numbers.less' if none is provided. # rule max-element ( elements + : ordered ? ) {