new wordRe class - a word that holds a regExp

- a possible future replacement for keyType, but the immediate use is the
    wordReList for grepping through other lists.
  - note that the argList treatment of '(' ... ')' yields quoted strings,
    which we can use for building a wordReList

minor cleanup of regExp class

  - constructor from std::string, match std::string and
    operator=(std::string&)
    rely on automatic conversion to Foam::string
  - ditch partialMatch with sub-groups, it doesn't make much sense
This commit is contained in:
Mark Olesen
2009-01-04 00:33:27 +01:00
parent 1d866d7fe8
commit 2717aa5c7d
19 changed files with 1036 additions and 182 deletions

View File

@ -62,9 +62,9 @@ inline Foam::string::string(const char c)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class String>
inline bool Foam::string::valid(const string& s)
inline bool Foam::string::valid(const string& str)
{
for (const_iterator iter = s.begin(); iter != s.end(); iter++)
for (const_iterator iter = str.begin(); iter != str.end(); iter++)
{
if (!String::valid(*iter))
{
@ -76,17 +76,17 @@ inline bool Foam::string::valid(const string& s)
template<class String>
inline bool Foam::string::stripInvalid(string& s)
inline bool Foam::string::stripInvalid(string& str)
{
if (!valid<String>(s))
if (!valid<String>(str))
{
register size_type nValid=0;
iterator iter2 = s.begin();
register size_type nValid = 0;
iterator iter2 = str.begin();
for
(
const_iterator iter1 = iter2;
iter1 != const_cast<const string&>(s).end();
iter1 != const_cast<const string&>(str).end();
iter1++
)
{
@ -100,7 +100,7 @@ inline bool Foam::string::stripInvalid(string& s)
}
}
s.resize(nValid);
str.resize(nValid);
return true;
}
@ -109,6 +109,66 @@ inline bool Foam::string::stripInvalid(string& s)
}
template<class String>
inline bool Foam::string::meta(const string& str, const char quote)
{
int escaped = 0;
for (const_iterator iter = str.begin(); iter != str.end(); iter++)
{
if (quote && *iter == quote)
{
escaped ^= 1; // toggle state
}
else if (escaped)
{
escaped = false;
}
else if (String::meta(*iter))
{
return true;
}
}
return false;
}
template<class String>
inline Foam::string
Foam::string::quotemeta(const string& str, const char quote)
{
if (!quote)
{
return str;
}
string sQuoted;
sQuoted.reserve(2*str.length());
int escaped = 0;
for (const_iterator iter = str.begin(); iter != str.end(); iter++)
{
if (*iter == quote)
{
escaped ^= 1; // toggle state
}
else if (escaped)
{
escaped = 0;
}
else if (String::meta(*iter))
{
sQuoted += quote;
}
sQuoted += *iter;
}
sQuoted.resize(sQuoted.length());
return sQuoted;
}
template<class String>
inline String Foam::string::validate(const string& str)
{