MCPcopy Create free account
hub / github.com/apache/trafficserver / capture

Method capture

plugins/prefetch/pattern.cc:230–261  ·  view source on GitHub ↗

* @brief Return all PCRE capture groups that matched in the subject string * @param subject PCRE subject string * @param result reference to vector of strings containing all capture groups */

Source from the content-addressed store, hash-verified

228 * @param result reference to vector of strings containing all capture groups
229 */
230bool
231Pattern::capture(const String &subject, StringVector &result)
232{
233 int matchCount;
234 int ovector[OVECOUNT];
235
236 PrefetchDebug("matching '%s' to '%s'", _pattern.c_str(), subject.c_str());
237
238 if (!_re) {
239 return false;
240 }
241
242 matchCount = pcre_exec(_re, nullptr, subject.c_str(), subject.length(), 0, PCRE_NOTEMPTY, ovector, OVECOUNT);
243 if (matchCount < 0) {
244 if (matchCount != PCRE_ERROR_NOMATCH) {
245 PrefetchError("matching error %d", matchCount);
246 }
247 return false;
248 }
249
250 for (int i = 0; i < matchCount; i++) {
251 int start = ovector[2 * i];
252 int length = ovector[2 * i + 1] - ovector[2 * i];
253
254 String dst(subject, start, length);
255
256 PrefetchDebug("capturing '%s' %d[%d,%d]", dst.c_str(), i, ovector[2 * i], ovector[2 * i + 1]);
257 result.push_back(dst);
258 }
259
260 return true;
261}
262
263/**
264 * @brief Replaces all replacements found in the replacement string with what matched in the PCRE capturing groups.

Callers

nothing calls this directly

Calls 4

pcre_execFunction · 0.85
c_strMethod · 0.45
lengthMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected