diff --git a/lib/token.cpp b/lib/token.cpp index bdca266e4..42097422e 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -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[]) diff --git a/lib/token.h b/lib/token.h index 03032cd47..bb5614910 100644 --- a/lib/token.h +++ b/lib/token.h @@ -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.