reworked regExp + wordRe a bit, minor change to keyType

regExp:
- added optional ignoreCase for constructor.
- the compile() methods is now exposed as set(...) method with an optional
  ignoreCase argument.  Not currently much use for the other regex compile
  flags though. The set() method can be used directly instead of the
  operator=() assignment.

keyType + wordRe:
- it's not clear that any particular characters are valid/invalid (compared
  to string or word), so just drop the valid(char) method for now

wordRe:
- a bool doesn't suffice, added enum compOption (compile-option)
- most constructors now have a compOption. In *all* cases it defaults to
  LITERAL - ie, the same behaviour for std::string and Foam::string
- added set(...) methods that do much the same as operator=(...), but the
  compOption can be specified.  In all cases, it defaults to DETECT.

 In Summary
    By default the constructors will generally preserve the argument as
    string literal and the assignment operators will use the wordRe::DETECT
    compOption to scan the string for regular expression meta characters
    and/or invalid word characters and react accordingly.

    The exceptions are when constructing/assigning from another
    Foam::wordRe (preserve the same type) or from a Foam::word (always
    literal).
This commit is contained in:
Mark Olesen
2009-01-05 17:02:58 +01:00
parent 19503c93e1
commit 3c5852ebfc
9 changed files with 218 additions and 174 deletions

View File

@ -12,7 +12,8 @@
(
( "a.*" "abc" )
( "a.*" "bac" )
( "a.*" "abcd" )
( "A.*" "abcd" )
( "a.*" "ABCD" )
( "a.*" "def" )
( "d(.*)f" "def" )
( "plain" "def" )

View File

@ -45,36 +45,42 @@ int main(int argc, char *argv[])
Foam::string s2("this .* file");
const char * s3 = "this .* file";
Info<< wordRe(s1).info() << endl;
Info<< wordRe(s2, false).info() << endl;
Info<< wordRe(s2).info() << endl;
Info<< wordRe(s3, true).info() << endl;
wordRe(s1, wordRe::DETECT).info(Info) << endl;
wordRe(s2).info(Info) << endl;
wordRe(s2, wordRe::DETECT).info(Info) << endl;
wordRe(s3, wordRe::REGEXP).info(Info) << endl;
wre = "this .* file";
Info<< wre.info() << endl;
wre.info(Info) << endl;
wre = s1;
Info<< wre.info() << endl;
wre.info(Info) << endl;
wre.uncompile();
Info<< wre.info() << " uncompiled" << endl;
wre.info(Info) << endl;
wre = "something";
Info<< wre.info() << " before" << endl;
wre.info(Info) << " before" << endl;
wre.uncompile();
Info<< wre.info() << " uncompiled" << endl;
wre.compile(true);
Info<< wre.info() << " after auto-detect" << endl;
wre.info(Info) << " uncompiled" << endl;
wre.compile(wordRe::DETECT);
wre.info(Info) << " after DETECT" << endl;
wre.compile(wordRe::NOCASE);
wre.info(Info) << " after NOCASE" << endl;
wre.compile(wordRe::DETECT_NOCASE);
wre.info(Info) << " after DETECT_NOCASE" << endl;
wre = "something .* value";
Info<< wre.info() << " before" << endl;
wre.info(Info) << " before" << endl;
wre.uncompile();
Info<< wre.info() << " uncompiled" << endl;
wre.compile(true);
Info<< wre.info() << " after auto-detect" << endl;
wre.info(Info) << " uncompiled" << endl;
wre.compile(wordRe::DETECT);
wre.info(Info) << " after DETECT" << endl;
wre.uncompile();
Info<< wre.info() << " uncompiled" << endl;
wre.info(Info) << " uncompiled" << endl;
wre.recompile();
Info<< wre.info() << " recompiled" << endl;
wre.info(Info) << " recompiled" << endl;
wre.set("something .* value", wordRe::LITERAL);
wre.info(Info) << " set as LITERAL" << endl;
IOobject::writeDivider(Info);
@ -88,12 +94,21 @@ int main(int argc, char *argv[])
const wordRe& wre = rawList[elemI].first();
const string& str = rawList[elemI].second();
Info<< wre.info()
wre.info(Info)
<< " equals:" << (wre == str)
<< "(" << wre.match(str, true) << ")"
<< " match:" << wre.match(str)
<< " str=" << str
<< endl;
wordRe wre2;
wre2.set(wre, wordRe::NOCASE);
wre2.info(Info)
<< " match:" << wre2.match(str)
<< " str=" << str
<< endl;
}
Info<< endl;