44 static inline bool fullMatch(
const regmatch_t& m,
const regoff_t len)
46 return (m.rm_so == 0 && m.rm_eo == len);
74 if (pattern && *pattern)
76 int cflags = REG_EXTENDED;
82 const char* pat = pattern;
87 if (!strncmp(pattern,
"(?i)", 4))
100 int err = regcomp(preg_, pat, cflags);
105 regerror(err, preg_, errbuf,
sizeof(errbuf));
108 <<
"Failed to compile regular expression '" << pattern <<
"'"
122 return set(pattern.c_str(), ignoreCase);
128 if (preg_ && !text.empty())
130 const size_t nmatch = 1;
131 regmatch_t pmatch[1];
133 if (regexec(preg_, text.c_str(), nmatch, pmatch, 0) == 0)
135 return pmatch[0].rm_so;
139 return std::string::npos;
145 const auto len = text.size();
149 const size_t nmatch = 1;
150 regmatch_t pmatch[1];
156 regexec(preg_, text.c_str(), nmatch, pmatch, 0) == 0
157 && fullMatch(pmatch[0], len)
167 const std::string& text,
173 const auto len = text.size();
176 const size_t nmatch = ngroups() + 1;
177 regmatch_t pmatch[nmatch];
184 regexec(preg_, text.c_str(), nmatch, pmatch, 0) != 0
185 || !fullMatch(pmatch[0], len)
191 matches.reserve(nmatch);
193 for (
size_t matchi = 0; matchi < nmatch; ++matchi)
195 const auto& mat = pmatch[matchi];
197 if (mat.rm_so != -1 && mat.rm_eo != -1)
201 text.cbegin() + mat.rm_so,
202 text.cbegin() + mat.rm_eo
208 matches.
append(text.cbegin(), text.cbegin());