common: Add auto-caching ExpressionMatch class
authorShane Synan <digitalcircuit36939@gmail.com>
Sun, 2 Sep 2018 16:52:12 +0000 (11:52 -0500)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 3 Sep 2018 20:12:02 +0000 (22:12 +0200)
commit09906ed00eb2ba2fa1cc0f5464f166e5a85a2c92
treef6fd7ef426a87f3a4c0695eb2b42de099e7ac6cd
parenta9d4ea84b489f39ccce27196ee8745a543519759
common: Add auto-caching ExpressionMatch class

Add ExpressionMatch class to unify handling of various search
expressions in Quassel, including automatically caching the regular
expression instances and providing Qt 4/5 compatibility.

The source expression depends on the matching mode:
* ExpressionMatch::MatchPhrase
Match the entire phrase, looking for whitespace or beginning/end
around either side of the phrase.  No further processing.
* ExpressionMatch::MatchMultiPhrase
Same as MatchPhrase, but split the expression on newlines ("\n") and
treat as match successful if any phrase is found.  This avoids having
to create multiple ExpressionMatch classes just to match multiple
phrases.
* ExpressionMatch::MatchWildcard
Split on ";" and newlines ("\n"), and apply basic wildcard globbing,
with "*" representing any characters and "?" a single character.
Prefixing a section with "!" turns it into an invert-match, negating
any other matching rules.  If only invert-match rules exist, matching
is true unless an invert-rule applies.  "\[...]" escapes the given
character.
* ExpressionMatch::MatchRegEx
Treat expression as a regular expression, inverting if prefixed with
"!" (and not escaped as "\!").

Cached regular expression objects are updated whenever changing any
parameters.

When Qt 4 support is dropped, the QT_VERSION macros can be adjusted.

This lays the foundation for performance and readibility improvements
in future commits.
src/common/CMakeLists.txt
src/common/expressionmatch.cpp [new file with mode: 0644]
src/common/expressionmatch.h [new file with mode: 0644]