* @brief Capture or capture-and-replace depending on whether a replacement string is specified. * @see replace() * @see capture() * @param subject PCRE subject string * @param result vector of strings where the result of captures or the replacements will be returned. * @return true if there was a match and capture or replacement succeeded, false if failure. */
| 167 | * @return true if there was a match and capture or replacement succeeded, false if failure. |
| 168 | */ |
| 169 | bool |
| 170 | Pattern::process(const String &subject, StringVector &result) |
| 171 | { |
| 172 | if (_replace) { |
| 173 | /* Replacement pattern was provided in the configuration - capture and replace. */ |
| 174 | String element; |
| 175 | if (replace(subject, element)) { |
| 176 | result.push_back(element); |
| 177 | } else { |
| 178 | return false; |
| 179 | } |
| 180 | } else { |
| 181 | /* Replacement was not provided so return all capturing groups except the group zero. */ |
| 182 | StringVector captures; |
| 183 | if (capture(subject, captures)) { |
| 184 | if (captures.size() == 1) { |
| 185 | result.push_back(captures[0]); |
| 186 | } else { |
| 187 | StringVector::iterator it = captures.begin() + 1; |
| 188 | for (; it != captures.end(); it++) { |
| 189 | result.push_back(*it); |
| 190 | } |
| 191 | } |
| 192 | } else { |
| 193 | return false; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | return true; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * @brief PCRE matches a subject string against the regex pattern. |
no test coverage detected