Make wildcard matcher case insensitive.

This commit is contained in:
Florian Geyer 2012-07-22 14:58:15 +02:00
parent 4f78c32461
commit 7bd080760e
4 changed files with 15 additions and 3 deletions

View File

@ -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)

View File

@ -34,6 +34,8 @@ public:
bool match(QString pattern);
private:
static const Qt::CaseSensitivity Sensitivity;
QString m_text;
QString m_pattern;
bool patternEqualsText();

View File

@ -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);

View File

@ -39,6 +39,7 @@ private Q_SLOTS:
void testNoMatchWithMultipleWildcards();
void testMatchJustWildcard();
void testMatchFollowingWildcards();
void testCaseSensitivity();
private:
static const QString DefaultText;