|
17 | 17 | */ |
18 | 18 | #include "regex_helper.h" |
19 | 19 | #include "lulu.h" |
| 20 | +#include "ts/ts.h" |
| 21 | +#include "tsutil/Regex.h" |
20 | 22 |
|
21 | 23 | bool |
22 | 24 | regexHelper::setRegexMatch(const std::string &s, bool nocase) |
23 | 25 | { |
24 | | - const char *errorComp = nullptr; |
25 | | - const char *errorStudy = nullptr; |
26 | | - int erroffset; |
| 26 | + std::string error; |
| 27 | + int errorOffset; |
27 | 28 |
|
28 | 29 | regexString = s; |
29 | | - regex = pcre_compile(regexString.c_str(), nocase ? PCRE_CASELESS : 0, &errorComp, &erroffset, nullptr); |
30 | 30 |
|
31 | | - if (regex == nullptr) { |
32 | | - return false; |
33 | | - } |
34 | | - regexExtra = pcre_study(regex, 0, &errorStudy); |
35 | | - if ((regexExtra == nullptr) && (errorStudy != nullptr)) { |
36 | | - return false; |
37 | | - } |
38 | | - if (pcre_fullinfo(regex, regexExtra, PCRE_INFO_CAPTURECOUNT, ®exCcount) != 0) { |
| 31 | + if (!regex.compile(regexString, error, errorOffset, nocase ? static_cast<int>(RE_CASE_INSENSITIVE) : 0)) { |
| 32 | + TSError("[%s] Invalid regex: failed to precompile: %s (%s at %d)", PLUGIN_NAME, s.c_str(), error.c_str(), errorOffset); |
| 33 | + Dbg(pi_dbg_ctl, "Invalid regex: failed to precompile: %s (%s at %d)", s.c_str(), error.c_str(), errorOffset); |
39 | 34 | return false; |
40 | 35 | } |
41 | 36 | return true; |
42 | 37 | } |
43 | 38 |
|
44 | 39 | int |
45 | | -regexHelper::regexMatch(const char *str, int len, int ovector[]) const |
| 40 | +regexHelper::regexMatch(std::string_view subject, RegexMatches &matches) const |
46 | 41 | { |
47 | | - return pcre_exec(regex, // the compiled pattern |
48 | | - regexExtra, // Extra data from study (maybe) |
49 | | - str, // the subject std::string |
50 | | - len, // the length of the subject |
51 | | - 0, // start at offset 0 in the subject |
52 | | - 0, // default options |
53 | | - ovector, // output vector for substring information |
54 | | - OVECCOUNT); // number of elements in the output vector |
| 42 | + return regex.exec(subject, matches); |
55 | 43 | }; |
0 commit comments