mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-25 07:19:42 -05:00
Make wildcard matcher case insensitive.
This commit is contained in:
parent
4f78c32461
commit
7bd080760e
@ -20,6 +20,7 @@
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
const QString WildcardMatcher::Wildcard = "*";
|
||||
const Qt::CaseSensitivity WildcardMatcher::Sensitivity = Qt::CaseInsensitive;
|
||||
|
||||
WildcardMatcher::WildcardMatcher(QString text, QObject* parent) :
|
||||
QObject(parent)
|
||||
@ -46,7 +47,7 @@ bool WildcardMatcher::patternContainsWildcard()
|
||||
|
||||
bool WildcardMatcher::patternEqualsText()
|
||||
{
|
||||
return m_text.compare(m_pattern) == 0;
|
||||
return m_text.compare(m_pattern, Sensitivity) == 0;
|
||||
}
|
||||
|
||||
bool WildcardMatcher::matchWithWildcards()
|
||||
@ -63,7 +64,8 @@ bool WildcardMatcher::matchWithWildcards()
|
||||
|
||||
bool WildcardMatcher::startOrEndDoesNotMatch(QStringList parts)
|
||||
{
|
||||
return !m_text.startsWith(parts.first()) || !m_text.endsWith(parts.last());
|
||||
return !m_text.startsWith(parts.first(), Sensitivity) ||
|
||||
!m_text.endsWith(parts.last(), Sensitivity);
|
||||
}
|
||||
|
||||
bool WildcardMatcher::partsMatch(QStringList parts)
|
||||
@ -82,7 +84,7 @@ bool WildcardMatcher::partsMatch(QStringList parts)
|
||||
|
||||
int WildcardMatcher::getMatchIndex(QString part, int startIndex)
|
||||
{
|
||||
return m_text.indexOf(part, startIndex);
|
||||
return m_text.indexOf(part, startIndex, Sensitivity);
|
||||
}
|
||||
|
||||
bool WildcardMatcher::noMatchFound(int index)
|
||||
|
@ -34,6 +34,8 @@ public:
|
||||
bool match(QString pattern);
|
||||
|
||||
private:
|
||||
static const Qt::CaseSensitivity Sensitivity;
|
||||
|
||||
QString m_text;
|
||||
QString m_pattern;
|
||||
bool patternEqualsText();
|
||||
|
@ -109,6 +109,13 @@ void TestWildcardMatcher::testMatchFollowingWildcards()
|
||||
verifyMatch(pattern);
|
||||
}
|
||||
|
||||
void TestWildcardMatcher::testCaseSensitivity()
|
||||
{
|
||||
initMatcher(DefaultText.toUpper());
|
||||
QString pattern("some t**t");
|
||||
verifyMatch(pattern);
|
||||
}
|
||||
|
||||
void TestWildcardMatcher::initMatcher(QString text)
|
||||
{
|
||||
m_matcher = new WildcardMatcher(text);
|
||||
|
@ -39,6 +39,7 @@ private Q_SLOTS:
|
||||
void testNoMatchWithMultipleWildcards();
|
||||
void testMatchJustWildcard();
|
||||
void testMatchFollowingWildcards();
|
||||
void testCaseSensitivity();
|
||||
|
||||
private:
|
||||
static const QString DefaultText;
|
||||
|
Loading…
Reference in New Issue
Block a user