diff options
Diffstat (limited to 'src/functionregexp.cpp')
-rw-r--r-- | src/functionregexp.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/functionregexp.cpp b/src/functionregexp.cpp index 74c19ee..27fdbbd 100644 --- a/src/functionregexp.cpp +++ b/src/functionregexp.cpp | |||
@@ -39,6 +39,41 @@ void FunctionRegexp::execute( Build *bld, const StringList &lInput, StringList & | |||
39 | } | 39 | } |
40 | else | 40 | else |
41 | { | 41 | { |
42 | if( !bld ) | ||
43 | { | ||
44 | throw BuildException("You apparently can't use regexp with two params here. Isn't that odd?"); | ||
45 | } | ||
46 | |||
47 | RegExp re( lParams.front().c_str() ); | ||
48 | lParams.pop_front(); | ||
49 | std::string p2 = lParams.front(); | ||
50 | |||
51 | for( StringList::const_iterator i = lInput.begin(); | ||
52 | i != lInput.end(); i++ ) | ||
53 | { | ||
54 | if( re.execute( (*i).c_str() ) ) | ||
55 | { | ||
56 | VarMap ext; | ||
57 | int jmax = re.getNumSubStrings(); | ||
58 | for( int j = 0; j < jmax; j++ ) | ||
59 | { | ||
60 | char buf[30]; | ||
61 | sprintf( buf, "re:%d", j ); | ||
62 | ext[buf] = re.getSubString( j ); | ||
63 | } | ||
64 | |||
65 | std::string sNew = bld->replVars( p2, NULL, &ext ); | ||
66 | lOutput.push_back( sNew ); | ||
67 | |||
68 | for( int j = 0; j < jmax; j++ ) | ||
69 | { | ||
70 | char buf[30]; | ||
71 | sprintf( buf, "re:%d", j ); | ||
72 | bld->set( sNew, buf, re.getSubString( j ) ); | ||
73 | } | ||
74 | bld->copyContext( *i, sNew ); | ||
75 | } | ||
76 | } | ||
42 | } | 77 | } |
43 | } | 78 | } |
44 | 79 | ||