32 template<
class StringType>
33 bool Foam::regExp::matchGrouping
35 const std::string& str,
36 List<StringType>& groups
39 if (preg_ && str.size())
42 regmatch_t pmatch[nmatch];
49 regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0
50 && (pmatch[0].rm_so == 0 && pmatch[0].rm_eo ==
label(str.size()))
56 for (
size_t matchI = 1; matchI < nmatch; matchI++)
58 if (pmatch[matchI].rm_so != -1 && pmatch[matchI].rm_eo != -1)
60 groups[groupI] = str.substr
63 pmatch[matchI].rm_eo - pmatch[matchI].rm_so
68 groups[groupI].clear();
94 set(pattern, ignoreCase);
102 set(pattern.c_str(), ignoreCase);
121 if (pattern && *pattern)
123 int cflags = REG_EXTENDED;
129 const char* pat = pattern;
134 if (!strncmp(pattern,
"(?i)", 4))
147 int err = regcomp(preg_, pat, cflags);
152 regerror(err, preg_, errbuf,
sizeof(errbuf));
155 <<
"Failed to compile regular expression '" << pattern <<
"'" 165 return set(pattern.c_str(), ignoreCase);
186 if (preg_ && str.size())
189 regmatch_t pmatch[1];
191 if (regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0)
193 return pmatch[0].rm_so;
203 if (preg_ && str.size())
206 regmatch_t pmatch[1];
212 regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0
213 && (pmatch[0].rm_so == 0 && pmatch[0].rm_eo ==
label(str.size()))
226 const std::string& str,
230 return matchGrouping(str, groups);
236 const std::string& str,
240 return matchGrouping(str, groups);
bool clear() const
Release precompiled expression.
void operator=(const regExp &)=delete
Disallow default bitwise assignment.
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
bool match(const std::string &) const
Return true if it matches the entire string.
errorManipArg< error, int > exit(error &err, const int errNo=1)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
graph_traits< Graph >::vertices_size_type size_type
int ngroups() const
Return the number of (groups)
std::string::size_type find(const std::string &str) const
Find position within string.
void set(const char *, const bool ignoreCase=false) const
Compile pattern into a regular expression,.