diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 67accc942..6d8a62fb6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -106,7 +106,6 @@ set(keepassx_MOC autotype/AutoTypeSelectDialog.h autotype/AutoTypeSelectView.h autotype/ShortcutWidget.h - autotype/WildcardMatcher.h autotype/WindowSelectComboBox.h core/AutoTypeAssociations.h core/Config.h diff --git a/src/autotype/WildcardMatcher.cpp b/src/autotype/WildcardMatcher.cpp index 9031e6b1d..d7e01a50a 100644 --- a/src/autotype/WildcardMatcher.cpp +++ b/src/autotype/WildcardMatcher.cpp @@ -19,16 +19,15 @@ #include -const QString WildcardMatcher::Wildcard = "*"; +const QChar WildcardMatcher::Wildcard = '*'; const Qt::CaseSensitivity WildcardMatcher::Sensitivity = Qt::CaseInsensitive; -WildcardMatcher::WildcardMatcher(QString text, QObject* parent) : - QObject(parent) +WildcardMatcher::WildcardMatcher(const QString& text) + : m_text(text) { - m_text = text; } -bool WildcardMatcher::match(QString pattern) +bool WildcardMatcher::match(const QString& pattern) { m_pattern = pattern; @@ -62,16 +61,16 @@ bool WildcardMatcher::matchWithWildcards() return partsMatch(parts); } -bool WildcardMatcher::startOrEndDoesNotMatch(QStringList parts) +bool WildcardMatcher::startOrEndDoesNotMatch(const QStringList& parts) { return !m_text.startsWith(parts.first(), Sensitivity) || !m_text.endsWith(parts.last(), Sensitivity); } -bool WildcardMatcher::partsMatch(QStringList parts) +bool WildcardMatcher::partsMatch(const QStringList& parts) { int index = 0; - Q_FOREACH (QString part, parts) { + Q_FOREACH (const QString& part, parts) { int matchIndex = getMatchIndex(part, index); if (noMatchFound(matchIndex)) { return false; @@ -82,14 +81,14 @@ bool WildcardMatcher::partsMatch(QStringList parts) return true; } -int WildcardMatcher::getMatchIndex(QString part, int startIndex) +int WildcardMatcher::getMatchIndex(const QString& part, int startIndex) { return m_text.indexOf(part, startIndex, Sensitivity); } bool WildcardMatcher::noMatchFound(int index) { - return index < 0; + return index == -1; } int WildcardMatcher::calculateNewIndex(int matchIndex, int partLength) diff --git a/src/autotype/WildcardMatcher.h b/src/autotype/WildcardMatcher.h index a78536eff..8fe85eeac 100644 --- a/src/autotype/WildcardMatcher.h +++ b/src/autotype/WildcardMatcher.h @@ -18,34 +18,29 @@ #ifndef KEEPASSX_WILDCARDMATCHER_H #define KEEPASSX_WILDCARDMATCHER_H -#include +#include -#include "core/Global.h" - -class WildcardMatcher : public QObject +class WildcardMatcher { - Q_OBJECT - public: - explicit WildcardMatcher(QString text, QObject* parent = Q_NULLPTR); + explicit WildcardMatcher(const QString& text); + bool match(const QString& pattern); - static const QString Wildcard; - - bool match(QString pattern); + static const QChar Wildcard; private: - static const Qt::CaseSensitivity Sensitivity; - - QString m_text; - QString m_pattern; bool patternEqualsText(); bool patternContainsWildcard(); bool matchWithWildcards(); - bool startOrEndDoesNotMatch(QStringList parts); - bool partsMatch(QStringList parts); - int getMatchIndex(QString part, int startIndex); + bool startOrEndDoesNotMatch(const QStringList& parts); + bool partsMatch(const QStringList& parts); + int getMatchIndex(const QString& part, int startIndex); bool noMatchFound(int index); int calculateNewIndex(int matchIndex, int partLength); + + static const Qt::CaseSensitivity Sensitivity; + const QString m_text; + QString m_pattern; }; #endif // KEEPASSX_WILDCARDMATCHER_H