Commit 50581683 authored by Andre Hartmann's avatar Andre Hartmann Committed by André Hartmann

CamelHumpMatcher: Support uppercase snake matching

Often used for macro names, e.g. TEST_ASSERT_EQUAL_FLOAT(),
which can now be matched by "TAEF".

Change-Id: I0626a60e2be68c1514c28769c679212075227281
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 2a945fc5
......@@ -72,6 +72,7 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp(
const QLatin1String lowercaseWordFirst("(?<=\\b|[A-Z0-9_])");
const QLatin1String uppercaseWordContinuation("[a-z0-9_]*");
const QLatin1String lowercaseWordContinuation("(?:[a-zA-Z0-9]*_)?");
const QLatin1String upperSnakeWordContinuation("[A-Z0-9]*_");
for (const QChar &c : pattern) {
if (!c.isLetter()) {
if (c == question)
......@@ -90,7 +91,9 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp(
keyRegExp += '|' + lowercaseWordFirst + QRegularExpression::escape(c.toLower()) + ')';
} else {
keyRegExp += ")|" + lowercaseWordContinuation;
keyRegExp += '(' + QRegularExpression::escape(c.toLower()) + ')';
keyRegExp += '(' + QRegularExpression::escape(c.toLower()) + ")|";
keyRegExp += upperSnakeWordContinuation;
keyRegExp += '(' + QRegularExpression::escape(c.toUpper()) + ')';
}
keyRegExp += ')';
} else {
......
......@@ -57,6 +57,7 @@ void tst_CamelHumpMatcher::camelHumpMatcher_data()
QTest::addColumn<int>("expectedIndex");
QTest::newRow("underscore") << "vl" << "very_long_camel_hump" << 0;
QTest::newRow("underscore-uppercase") << "vl" << "VERY_LONG_CAMEL_HUMP" << 0;
QTest::newRow("exact") << "VeryLongCamelHump" << "VeryLongCamelHump" << 0;
QTest::newRow("prefix-segments") << "velo" << "very_long_Camel_hump" << 0;
QTest::newRow("humps") << "vlc" << "VeryLongCamelHump" << 0;
......@@ -74,6 +75,7 @@ void tst_CamelHumpMatcher::camelHumpMatcher_data()
QTest::newRow("no-partial") << "NCH" << "LongCamelHump" << -1;
QTest::newRow("middle-after-number") << "CH" << "Long1CamelHump" << 5;
QTest::newRow("middle-after-underscore") << "CH" << "long_camel_hump" << 5;
QTest::newRow("middle-after-underscore-uppercase") << "CH" << "LONG_CAMEL_HUMP" << 5;
QTest::newRow("middle-continued") << "cahu" << "LongCamelHump" << 4;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment