MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / skipTernaryOp

Function skipTernaryOp

lib/tokenize.cpp:4029–4050  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4027}
4028
4029static Token *skipTernaryOp(Token *tok)
4030{
4031 int colonLevel = 1;
4032 while (nullptr != (tok = tok->next())) {
4033 if (tok->str() == "?") {
4034 ++colonLevel;
4035 } else if (tok->str() == ":") {
4036 --colonLevel;
4037 if (colonLevel == 0) {
4038 tok = tok->next();
4039 break;
4040 }
4041 }
4042 if (tok->link() && Token::Match(tok, "[(<]"))
4043 tok = tok->link();
4044 else if (Token::Match(tok->next(), "[{};)]"))
4045 break;
4046 }
4047 if (colonLevel > 0) // Ticket #5214: Make sure the ':' matches the proper '?'
4048 return nullptr;
4049 return tok;
4050}
4051
4052// Skips until the colon at the end of the case label, the argument must point to the "case" token.
4053// In case of success returns the colon token.

Callers 1

skipCaseLabelFunction · 0.70

Calls 2

nextMethod · 0.80
strMethod · 0.45

Tested by

no test coverage detected