| 185 | } |
| 186 | |
| 187 | std::string PatternMatcher::gsub( const char* text, const char* replace ) { |
| 188 | PatternMatcher::Match ms( *this, text ); |
| 189 | std::string res; |
| 190 | while ( ms.subst( res ) ) { |
| 191 | for ( const char* ptr = replace; *ptr; ++ptr ) { |
| 192 | if ( *ptr == '%' ) { |
| 193 | ++ptr; |
| 194 | int ngroup = (int)*ptr - (int)'0'; |
| 195 | res += ms.group( ngroup ); |
| 196 | } else { |
| 197 | res += *ptr; |
| 198 | } |
| 199 | } |
| 200 | ms.next(); |
| 201 | } |
| 202 | return res; |
| 203 | } |
| 204 | |
| 205 | std::string PatternMatcher::gsub( const std::string& text, const std::string& replace ) { |
| 206 | return gsub( text.c_str(), replace.c_str() ); |
no test coverage detected