2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-15 13:02:11 +00:00
Files
build/v2/util/string.jam
Dave Abrahams bbb527500b Build request expansion
[SVN r12778]
2002-02-10 00:49:29 +00:00

52 lines
1.4 KiB
Plaintext

# (C) Copyright David Abrahams 2002. Permission to copy, use, modify, sell and
# distribute this software is granted provided this copyright notice appears in
# all copies. This software is provided "as is" without express or implied
# warranty, and with no claim as to its suitability for any purpose.
rule chars ( string )
{
local result ;
while $(string)
{
local s = [ SUBST $(string) (.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.*)
$9 $1 $2 $3 $4 $5 $6 $7 $8 ] ;
string = $(s[1]) ;
result += $(s[2-]) ;
}
# trim off empty strings
while $(result[1]) && ! $(result[-2])
{
result = $(result[1--2]) ;
}
return $(result) ;
}
rule join ( strings * : separator ? )
{
separator ?= "" ;
local result = $(strings[1]) ;
for local x in $(strings[2-])
{
result = $(result)$(separator)$(x) ;
}
return $(result) ;
}
rule __test__ ( )
{
import assert ;
assert.result a b c : chars abc ;
# check boundary cases
assert.result a : chars a ;
assert.result : chars "" ;
assert.result a b c d e f g h : chars abcdefgh ;
assert.result a b c d e f g h i : chars abcdefghi ;
assert.result a b c d e f g h i j : chars abcdefghij ;
assert.result a b c d e f g h i j k : chars abcdefghijk ;
assert.result a//b/c/d : join a "" b c d : / ;
assert.result abcd : join a "" b c d ;
}