Refactor Token::findClosingBracket()

This commit is contained in:
Daniel Marjamäki 2018-01-01 12:22:04 +01:00
parent 3b6fbd067e
commit 03b0b35a9d
1 changed files with 20 additions and 22 deletions

View File

@ -822,30 +822,28 @@ Token* Token::nextTemplateArgument() const
const Token * Token::findClosingBracket() const
{
if (_str != "<")
return nullptr;
const Token *closing = nullptr;
if (_str == "<") {
unsigned int depth = 0;
for (closing = this; closing != nullptr; closing = closing->next()) {
if (Token::Match(closing, "{|[|(")) {
closing = closing->link();
if (!closing)
return nullptr; // #6803
} else if (Token::Match(closing, "}|]|)|;")) {
if (depth > 0)
} else if (Token::Match(closing, "}|]|)|;"))
return nullptr;
break;
} else if (closing->str() == "<")
else if (closing->str() == "<")
++depth;
else if (closing->str() == ">") {
if (--depth == 0)
break;
return closing;
} else if (closing->str() == ">>") {
if (--depth == 0)
break;
if (--depth == 0)
break;
}
if (depth <= 2)
return closing;
depth -= 2;
}
}