Refactor Token::findClosingBracket()
This commit is contained in:
parent
3b6fbd067e
commit
03b0b35a9d
|
@ -822,30 +822,28 @@ Token* Token::nextTemplateArgument() const
|
||||||
|
|
||||||
const Token * Token::findClosingBracket() const
|
const Token * Token::findClosingBracket() const
|
||||||
{
|
{
|
||||||
|
if (_str != "<")
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
const Token *closing = nullptr;
|
const Token *closing = nullptr;
|
||||||
|
|
||||||
if (_str == "<") {
|
|
||||||
unsigned int depth = 0;
|
unsigned int depth = 0;
|
||||||
for (closing = this; closing != nullptr; closing = closing->next()) {
|
for (closing = this; closing != nullptr; closing = closing->next()) {
|
||||||
if (Token::Match(closing, "{|[|(")) {
|
if (Token::Match(closing, "{|[|(")) {
|
||||||
closing = closing->link();
|
closing = closing->link();
|
||||||
if (!closing)
|
if (!closing)
|
||||||
return nullptr; // #6803
|
return nullptr; // #6803
|
||||||
} else if (Token::Match(closing, "}|]|)|;")) {
|
} else if (Token::Match(closing, "}|]|)|;"))
|
||||||
if (depth > 0)
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
break;
|
else if (closing->str() == "<")
|
||||||
} else if (closing->str() == "<")
|
|
||||||
++depth;
|
++depth;
|
||||||
else if (closing->str() == ">") {
|
else if (closing->str() == ">") {
|
||||||
if (--depth == 0)
|
if (--depth == 0)
|
||||||
break;
|
return closing;
|
||||||
} else if (closing->str() == ">>") {
|
} else if (closing->str() == ">>") {
|
||||||
if (--depth == 0)
|
if (depth <= 2)
|
||||||
break;
|
return closing;
|
||||||
if (--depth == 0)
|
depth -= 2;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue