From f56b2bfe6d000324ae49060a50542fe551293cb6 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 2 Oct 2017 23:50:10 +0300 Subject: [PATCH] CamelHump: Fix case insensitive matching after the same case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For example: window -> MAINWINDOW. This was broken by the constraint that the first char must follow a non- matching case in 2fb54abd03. It was fixed for pure lowercase in f792475739, but this fix was evidentially partial. Change-Id: I0c29b54768c40d0501f006182f2bd1ae1e94f3bf Reviewed-by: André Hartmann --- src/libs/utils/camelhumpmatcher.cpp | 21 +++++++++++++------ .../camelhumpmatcher/tst_camelhumpmatcher.cpp | 2 ++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/libs/utils/camelhumpmatcher.cpp b/src/libs/utils/camelhumpmatcher.cpp index 51206262d44..b82cd2d8998 100644 --- a/src/libs/utils/camelhumpmatcher.cpp +++ b/src/libs/utils/camelhumpmatcher.cpp @@ -65,6 +65,7 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp( */ QString keyRegExp; + QString plainRegExp; bool first = true; const QChar asterisk = '*'; const QChar question = '?'; @@ -76,12 +77,17 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp( keyRegExp += "(?:"; for (const QChar &c : pattern) { if (!c.isLetter()) { - if (c == question) + if (c == question) { keyRegExp += '.'; - else if (c == asterisk) + plainRegExp += '.'; + } else if (c == asterisk) { keyRegExp += ".*"; - else - keyRegExp += '(' + QRegularExpression::escape(c) + ')'; + plainRegExp += ".*"; + } else { + const QString escaped = QRegularExpression::escape(c); + keyRegExp += '(' + escaped + ')'; + plainRegExp += escaped; + } } else if (caseSensitivity == CaseSensitivity::CaseInsensitive || (caseSensitivity == CaseSensitivity::FirstLetterCaseSensitive && !first)) { @@ -97,6 +103,7 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp( keyRegExp += '|' + upperSnakeWordContinuation + '(' + upper + ')'; } keyRegExp += ')'; + plainRegExp += '[' + upper + lower + ']'; } else { if (!first) { if (c.isUpper()) @@ -104,12 +111,14 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp( else keyRegExp += lowercaseWordContinuation; } - keyRegExp += QRegularExpression::escape(c); + const QString escaped = QRegularExpression::escape(c); + keyRegExp += escaped; + plainRegExp += escaped; } first = false; } - keyRegExp += ")|(" + QRegularExpression::escape(pattern) + ')'; + keyRegExp += ")|(" + plainRegExp + ')'; return QRegularExpression(keyRegExp); } diff --git a/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp b/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp index 0b5774ee63b..d9b54743411 100644 --- a/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp +++ b/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp @@ -79,6 +79,8 @@ void tst_CamelHumpMatcher::camelHumpMatcher_data() QTest::newRow("middle-after-underscore-uppercase") << "CH" << "LONG_CAMEL_HUMP" << 5; QTest::newRow("middle-continued") << "cahu" << "LongCamelHump" << 4; QTest::newRow("middle-no-hump") << "window" << "mainwindow.cpp" << 4; + QTest::newRow("case-insensitive") << "window" << "MAINWINDOW.cpp" << 4; + QTest::newRow("case-insensitive-2") << "wINDow" << "MainwiNdow.cpp" << 4; } typedef QVector MatchStart;