mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: disentangle testing and quoting of regex characters
- originally had tests for regex meta characters strewn across regExp classes as well as wordRe, keyType, string. And had special-purpose quotemeta static function within string that relied on special naming convention for testing the meta characters. The regex meta character testing/handling now relegated entirely to the regExp class(es). Relocate quotemeta to stringOps, with a predicate. - avoid code duplication. Reuse some regExpCxx methods in regExpPosix
This commit is contained in:
committed by
Andrew Heather
parent
cdbc3e2de6
commit
57c1fceabf
@ -172,68 +172,6 @@ inline bool Foam::string::stripInvalid(std::string& str)
|
||||
}
|
||||
|
||||
|
||||
template<class String>
|
||||
inline bool Foam::string::meta(const std::string& str, const char quote)
|
||||
{
|
||||
int escaped = 0;
|
||||
for (auto iter = str.cbegin(); iter != str.cend(); ++iter)
|
||||
{
|
||||
const char c = *iter;
|
||||
if (quote && c == quote)
|
||||
{
|
||||
escaped ^= 1; // toggle state
|
||||
}
|
||||
else if (escaped)
|
||||
{
|
||||
escaped = 0;
|
||||
}
|
||||
else if (String::meta(c))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<class String>
|
||||
inline Foam::string
|
||||
Foam::string::quotemeta(const std::string& str, const char quote)
|
||||
{
|
||||
if (!quote)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
string sQuoted;
|
||||
sQuoted.reserve(2*str.size());
|
||||
|
||||
int escaped = 0;
|
||||
for (auto iter = str.cbegin(); iter != str.cend(); ++iter)
|
||||
{
|
||||
const char c = *iter;
|
||||
if (c == quote)
|
||||
{
|
||||
escaped ^= 1; // toggle state
|
||||
}
|
||||
else if (escaped)
|
||||
{
|
||||
escaped = 0;
|
||||
}
|
||||
else if (String::meta(c))
|
||||
{
|
||||
sQuoted += quote;
|
||||
}
|
||||
|
||||
sQuoted += c;
|
||||
}
|
||||
|
||||
sQuoted.shrink_to_fit();
|
||||
|
||||
return sQuoted;
|
||||
}
|
||||
|
||||
|
||||
template<class String>
|
||||
inline String Foam::string::validate(const std::string& str)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user