Commit 37a6bb5b authored by Milian Wolff's avatar Milian Wolff
Browse files

Check for word boundaries when looking for operators in ParamIterator

As found by Igor Kushnir during code review, the old code didn't
handle custom identifiers that ended with the string 'operator'.
parent 8db6b62d
......@@ -76,6 +76,15 @@ int rStrip_impl(const T& str, T& from)
return s - from.length();
}
bool endsWithWordBoundary(QStringView str)
{
if (str.isEmpty()) {
return true;
}
const auto boundary = str.last();
return !boundary.isLetterOrNumber() && boundary != QLatin1Char('_');
}
bool isOperator(const QString& str, int pos)
{
const auto c = str[pos];
......@@ -93,7 +102,14 @@ bool isOperator(const QString& str, int pos)
--pos;
}
return QStringView(str).mid(0, pos + 1).endsWith(QLatin1String("operator"));
auto prefix = QStringView(str).left(pos + 1);
const auto op = QLatin1String("operator");
if (!prefix.endsWith(op)) {
return false;
}
prefix.chop(op.size());
return endsWithWordBoundary(prefix);
}
int skipStringOrCharLiteral(const QString& str, int pos)
......
......@@ -157,6 +157,7 @@ void TestStringHelpers::testParamIterator_data()
{"_Tp", "foo<bar>", "__void_t<decltype(std::declval<_Tp>().operator->(std::declval<_Up>()))>"});
addTest("A<\">\\\">\">", {"\">\\\">\""});
addTest("A<'>'>", {"'>'"});
addTest("myoperator<anoperator<anotheroperator>, my_operator>", {"anoperator<anotheroperator>", "my_operator"});
}
void TestStringHelpers::testParamIterator()
......
Supports Markdown
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