| 131 | { |
| 132 | template<class ReplaceCallback> |
| 133 | std::string regex_replace( |
| 134 | std::string const& _source, |
| 135 | std::regex const& _pattern, |
| 136 | ReplaceCallback _replace, |
| 137 | std::regex_constants::match_flag_type _flags = std::regex_constants::match_default |
| 138 | ) |
| 139 | { |
| 140 | std::sregex_iterator curMatch(_source.begin(), _source.end(), _pattern, _flags); |
| 141 | std::sregex_iterator matchEnd; |
| 142 | std::string::const_iterator lastMatchedPos(_source.cbegin()); |
| 143 | std::string result; |
| 144 | while (curMatch != matchEnd) |
| 145 | { |
| 146 | result.append(curMatch->prefix().first, curMatch->prefix().second); |
| 147 | result.append(_replace(*curMatch)); |
| 148 | lastMatchedPos = (*curMatch)[0].second; |
| 149 | ++curMatch; |
| 150 | } |
| 151 | result.append(lastMatchedPos, _source.cend()); |
| 152 | return result; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | std::string Whiskers::replace( |