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

Function stringFromTokenRange

lib/token.cpp:1596–1630  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1594}
1595
1596static std::string stringFromTokenRange(const Token* start, const Token* end)
1597{
1598 std::string ret;
1599 if (end)
1600 end = end->next();
1601 for (const Token *tok = start; tok && tok != end; tok = tok->next()) {
1602 if (tok->isUnsigned())
1603 ret += "unsigned ";
1604 if (tok->isLong() && !tok->isLiteral())
1605 ret += "long ";
1606 if (tok->tokType() == Token::eString) {
1607 for (const unsigned char c: tok->str()) {
1608 if (c == '\n')
1609 ret += "\\n";
1610 else if (c == '\r')
1611 ret += "\\r";
1612 else if (c == '\t')
1613 ret += "\\t";
1614 else if (c >= ' ' && c <= 126)
1615 ret += c;
1616 else {
1617 char str[5];
1618 snprintf(str, sizeof(str), "\\x%02x", c);
1619 ret += str;
1620 }
1621 }
1622 } else if (tok->originalName().empty() || tok->isUnsigned() || tok->isLong()) {
1623 ret += tok->str();
1624 } else
1625 ret += tok->originalName();
1626 if (Token::Match(tok, "%name%|%num% %name%|%num%"))
1627 ret += ' ';
1628 }
1629 return ret;
1630}
1631
1632std::string Token::expressionString() const
1633{

Callers 1

expressionStringMethod · 0.85

Calls 4

nextMethod · 0.80
isUnsignedMethod · 0.80
strMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected