Adapt Token::strAt() to return a const reference like Token::str() does

Saves us a complete conversion from string.c_str() back to std::string.
This commit is contained in:
Thomas Jarosch 2011-11-14 09:16:47 +01:00
parent 527236b321
commit a645235d5a
2 changed files with 5 additions and 3 deletions

View File

@ -233,10 +233,12 @@ Token *Token::linkAt(int index)
return tok->link();
}
std::string Token::strAt(int index) const
const std::string &Token::strAt(int index) const
{
static const std::string empty_str;
const Token *tok = this->tokAt(index);
return tok ? tok->_str.c_str() : "";
return tok ? tok->_str : empty_str;
}
static bool strisop(const char str[])

View File

@ -78,7 +78,7 @@ public:
const Token *linkAt(int index) const;
Token *linkAt(int index);
std::string strAt(int index) const;
const std::string &strAt(int index) const;
/**
* Match given token (or list of tokens) to a pattern list.