44 static inline bool fullMatch(
const regmatch_t& m,
const regoff_t len)
46 return (m.rm_so == 0 && m.rm_eo == len);
54 bool Foam::regExpPosix::set_pattern
63 const char* pat = pattern;
64 bool doNegate =
false;
67 if (len > 2 && pat[0] ==
'(' && pat[1] ==
'?')
72 for (
bool done =
false; !done && len; ++pat, --len)
101 int flags = REG_EXTENDED;
109 int err = regcomp(preg_, pat, flags);
113 ctrl_ = (doNegate ? ctrlType::NEGATED : ctrlType::NORMAL);
119 regerror(err, preg_, errbuf,
sizeof(errbuf));
122 <<
"Failed to compile regular expression '" 123 << pattern <<
"'\n" << errbuf
154 if (!preg_ || !ctrl_)
157 return std::string::npos;
159 else if (text.empty())
161 if (ctrl_ == ctrlType::NEGATED)
167 return std::string::npos;
172 const size_t nmatch = 1;
173 regmatch_t pmatch[1];
175 const bool ok = (regexec(preg_, text.c_str(), nmatch, pmatch, 0) == 0);
177 if (ctrl_ == ctrlType::NEGATED)
186 return pmatch[0].rm_so;
190 return std::string::npos;
198 if (!preg_ || !ctrl_)
204 const auto len = text.length();
208 const size_t nmatch = 1;
209 regmatch_t pmatch[1];
215 regexec(preg_, text.c_str(), nmatch, pmatch, 0) == 0
216 && fullMatch(pmatch[0], len)
220 return (ctrl_ == ctrlType::NEGATED ? !ok : ok);
226 const std::string& text,
227 SubStrings<std::string>& matches
238 const auto len = text.size();
241 const size_t nmatch = ngroups() + 1;
242 regmatch_t pmatch[nmatch];
249 regexec(preg_, text.c_str(), nmatch, pmatch, 0) != 0
250 || !fullMatch(pmatch[0], len)
256 matches.reserve(nmatch);
258 for (
size_t matchi = 0; matchi < nmatch; ++matchi)
260 const auto& mat = pmatch[matchi];
262 if (mat.rm_so != -1 && mat.rm_eo != -1)
266 text.cbegin() + mat.rm_so,
267 text.cbegin() + mat.rm_eo
273 matches.append(text.cbegin(), text.cbegin());
bool match(const UList< wordRe > &patterns, const std::string &text)
Return true if text matches one of the regular expressions.
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static int grammar
Grammar (unused) - for compatibility with Foam::regExpCxx.
graph_traits< Graph >::vertices_size_type size_type
bool match(const std::string &text) const
True if the regex matches the entire text.
bool clear()
Clear expression.
std::string::size_type find(const std::string &text) const
Find position within the text.