| 224 | } |
| 225 | |
| 226 | std::string PcreRegex::match(const std::string& str, const MatchFn& matchFn) const |
| 227 | { |
| 228 | if (!mRe) |
| 229 | return "regular expression has not been compiled yet"; |
| 230 | |
| 231 | int pos = 0; |
| 232 | int ovector[30]= {0}; |
| 233 | while (pos < static_cast<int>(str.size())) { |
| 234 | const int pcreExecRet = pcre_exec(mRe, mExtra, str.c_str(), static_cast<int>(str.size()), pos, 0, ovector, 30); |
| 235 | if (pcreExecRet == PCRE_ERROR_NOMATCH) |
| 236 | return ""; |
| 237 | if (pcreExecRet < 0) { |
| 238 | return pcreErrorCodeToString(pcreExecRet) + " (pos: " + std::to_string(pos) + ")"; |
| 239 | } |
| 240 | const auto pos1 = static_cast<unsigned int>(ovector[0]); |
| 241 | const auto pos2 = static_cast<unsigned int>(ovector[1]); |
| 242 | |
| 243 | matchFn(pos1, pos2); |
| 244 | |
| 245 | // jump to the end of the match for the next pcre_exec |
| 246 | pos = static_cast<int>(pos2); |
| 247 | } |
| 248 | |
| 249 | return ""; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | template<typename T> |
no test coverage detected