STYLE: support wordRe ICASE enum

- better naming consistency with std::regex_constants::icase

- deprecate older NOCASE, but leave supported
This commit is contained in:
Mark Olesen
2018-04-13 10:42:42 +02:00
parent b29a0119de
commit a8da75d27e
3 changed files with 26 additions and 25 deletions

View File

@ -139,10 +139,10 @@ int main(int argc, char *argv[])
wre.info(Info) << " uncompiled" << endl; wre.info(Info) << " uncompiled" << endl;
wre.compile(wordRe::DETECT); wre.compile(wordRe::DETECT);
wre.info(Info) << " after DETECT" << endl; wre.info(Info) << " after DETECT" << endl;
wre.compile(wordRe::NOCASE); wre.compile(wordRe::ICASE);
wre.info(Info) << " after NOCASE" << endl; wre.info(Info) << " after ICASE" << endl;
wre.compile(wordRe::DETECT_NOCASE); wre.compile(wordRe::DETECT_ICASE);
wre.info(Info) << " after DETECT_NOCASE" << endl; wre.info(Info) << " after DETECT_ICASE" << endl;
wre = "something .* value"; wre = "something .* value";
wre.info(Info) << " before" << endl; wre.info(Info) << " before" << endl;
@ -177,7 +177,7 @@ int main(int argc, char *argv[])
<< endl; << endl;
wordRe wre2; wordRe wre2;
wre2.set(wre, wordRe::NOCASE); wre2.set(wre, wordRe::ICASE);
wre2.info(Info) wre2.info(Info)
<< " match:" << wre2.match(str) << " match:" << wre2.match(str)

View File

@ -92,15 +92,16 @@ public:
// Public data types // Public data types
//- Enumeration with compile options //- Enumeration with compile options
// Note that 'REGEX' is implicit if 'NOCASE' is specified alone. // Note that 'REGEX' is implicit if 'ICASE' is specified alone.
enum compOption enum compOption
{ {
LITERAL = 0, //!< Treat as a string literal LITERAL = 0, //!< Treat as a string literal
DETECT = 1, //!< Detect if the string contains meta-characters DETECT = 1, //!< Detect if the string contains meta-characters
REGEX = 2, //!< Treat as regular expression REGEX = 2, //!< Treat as regular expression
NOCASE = 4, //!< Ignore case in regular expression ICASE = 4, //!< Ignore case in regular expression
DETECT_NOCASE = DETECT|NOCASE, //!< Combined DETECT and NOCASE NOCASE = 4, //!< \deprecated Alias for ICASE (deprecated APR-2018)
REGEX_NOCASE = REGEX|NOCASE //!< Combined REGEX and NOCASE DETECT_ICASE = (DETECT|ICASE), //!< Combined DETECT and ICASE
REGEX_ICASE = (REGEX|ICASE) //!< Combined REGEX and ICASE
}; };
@ -140,19 +141,19 @@ public:
inline explicit wordRe(const word& str); inline explicit wordRe(const word& str);
//- Construct from keyType, use specified compile option //- Construct from keyType, use specified compile option
inline wordRe(const keyType& str, const compOption); inline wordRe(const keyType& str, const compOption opt);
//- Construct as copy of character array, use specified compile option //- Construct as copy of character array, use specified compile option
inline wordRe(const char* str, const compOption); inline wordRe(const char* str, const compOption opt);
//- Construct as copy of std::string, use specified compile option //- Construct as copy of std::string, use specified compile option
inline wordRe(const std::string& str, const compOption); inline wordRe(const std::string& str, const compOption opt);
//- Construct as copy of string, use specified compile option //- Construct as copy of string, use specified compile option
inline wordRe(const string& str, const compOption); inline wordRe(const string& str, const compOption opt);
//- Construct as copy of word, use specified compile option //- Construct as copy of word, use specified compile option
inline wordRe(const word& str, const compOption); inline wordRe(const word& str, const compOption opt);
//- Move construct //- Move construct
inline wordRe(wordRe&& str); inline wordRe(wordRe&& str);
@ -164,32 +165,32 @@ public:
// Member functions // Member functions
// Access // Access
//- Treat as a pattern rather than a literal string? //- Treat as a pattern rather than a literal string?
inline bool isPattern() const; inline bool isPattern() const;
// Infrastructure // Infrastructure
//- Compile the regular expression //- Compile the regular expression
inline bool compile() const; inline bool compile() const;
//- Possibly compile the regular expression, with greater control //- Possibly compile the regular expression, with greater control
inline bool compile(const compOption) const; inline bool compile(const compOption opt) const;
//- Make wordRe a literal again, instead of a regular expression. //- Make wordRe a literal again, instead of a regular expression.
// Optionally strip invalid word characters. // Optionally strip invalid word characters.
inline void uncompile(const bool doStripInvalid = false) const; inline void uncompile(const bool doStripInvalid = false) const;
// Editing // Editing
//- Copy string, auto-test for regular expression or other options //- Copy string, auto-test for regular expression or other options
inline void set(const std::string& str, const compOption = DETECT); inline void set(const std::string& str, const compOption opt = DETECT);
//- Copy string, auto-test for regular expression or other options //- Copy string, auto-test for regular expression or other options
inline void set(const char* str, const compOption = DETECT); inline void set(const char* str, const compOption opt = DETECT);
//- Clear string and regular expression //- Clear string and regular expression
inline void clear(); inline void clear();
@ -198,14 +199,14 @@ public:
inline void swap(wordRe& str); inline void swap(wordRe& str);
// Matching/Searching // Matching/Searching
//- Smart match as regular expression or as a string. //- Smart match as regular expression or as a string.
// Optionally force a literal match only // Optionally force a literal match only
inline bool match(const std::string& text, bool literal=false) const; inline bool match(const std::string& text, bool literal=false) const;
// Miscellaneous // Miscellaneous
//- Return a string with quoted meta-characters //- Return a string with quoted meta-characters
inline string quotemeta() const; inline string quotemeta() const;
@ -214,7 +215,7 @@ public:
Ostream& info(Ostream& os) const; Ostream& info(Ostream& os) const;
// Member operators // Member Operators
//- Perform smart match on text, as per match() //- Perform smart match on text, as per match()
// Allows use as a predicate. // Allows use as a predicate.

View File

@ -177,14 +177,14 @@ inline bool Foam::wordRe::compile(const compOption opt) const
{ {
comp = string::meta<regExp>(*this) || !string::valid<word>(*this); comp = string::meta<regExp>(*this) || !string::valid<word>(*this);
} }
else if (opt & wordRe::NOCASE) else if (opt & wordRe::ICASE)
{ {
comp = true; comp = true;
} }
if (comp) if (comp)
{ {
return re_.set(*this, (opt & wordRe::NOCASE)); return re_.set(*this, (opt & wordRe::ICASE));
} }
} }