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, "}|]|)|;")) {
|
return nullptr;
|
||||||
if (depth > 0)
|
else if (closing->str() == "<")
|
||||||
return nullptr;
|
++depth;
|
||||||
break;
|
else if (closing->str() == ">") {
|
||||||
} else if (closing->str() == "<")
|
if (--depth == 0)
|
||||||
++depth;
|
return closing;
|
||||||
else if (closing->str() == ">") {
|
} else if (closing->str() == ">>") {
|
||||||
if (--depth == 0)
|
if (depth <= 2)
|
||||||
break;
|
return closing;
|
||||||
} else if (closing->str() == ">>") {
|
depth -= 2;
|
||||||
if (--depth == 0)
|
|
||||||
break;
|
|
||||||
if (--depth == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue