From 4286fdbabb64014fd6ef968e163257a977400d3e Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 14 Jun 2009 13:55:23 +0700 Subject: [PATCH] Token: introduce str(const std::string &) method. Get rid of useless std::string.c_str() calls. No functional change. --- src/token.cpp | 7 ++++++- src/token.h | 2 ++ src/tokenize.cpp | 12 ++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/token.cpp b/src/token.cpp index 51635a31d..ec9e9df33 100644 --- a/src/token.cpp +++ b/src/token.cpp @@ -44,7 +44,7 @@ Token::~Token() } -void Token::str(const char s[]) +void Token::str(const std::string &s) { _str = s; _isName = bool(_str[0] == '_' || std::isalpha(_str[0])); @@ -57,6 +57,11 @@ void Token::str(const char s[]) _varId = 0; } +void Token::str(const char s[]) +{ + str(std::string(s)); +} + void Token::concatStr(std::string const& b) { _str.erase(_str.length() - 1); diff --git a/src/token.h b/src/token.h index 0a3995175..86934048d 100644 --- a/src/token.h +++ b/src/token.h @@ -26,6 +26,8 @@ class Token public: Token(); ~Token(); + + void str(const std::string &s); void str(const char s[]); void concatStr(std::string const& b); diff --git a/src/tokenize.cpp b/src/tokenize.cpp index ee31c4f34..a01dd8940 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -104,7 +104,7 @@ void Tokenizer::addtoken(const char str[], const unsigned int lineno, const unsi { _tokens = new Token; _tokensBack = _tokens; - _tokensBack->str(str2.str().c_str()); + _tokensBack->str(str2.str()); } _tokensBack->linenr(lineno); @@ -1257,7 +1257,7 @@ void Tokenizer::simplifyTokenList() { std::ostringstream str; str << SizeOfType(tok->strAt(2)); - tok->str(str.str().c_str()); + tok->str(str.str()); for (int i = 0; i < 3; i++) { @@ -1279,7 +1279,7 @@ void Tokenizer::simplifyTokenList() { std::ostringstream str; str << size; - tok->str(str.str().c_str()); + tok->str(str.str()); for (int i = 0; i < 3; i++) { tok->deleteNext(); @@ -1307,7 +1307,7 @@ void Tokenizer::simplifyTokenList() { std::ostringstream ostr; ostr << sz; - tok->str(ostr.str().c_str()); + tok->str(ostr.str()); while (tok->next()->str() != ")") tok->deleteNext(); tok->deleteNext(); @@ -1356,7 +1356,7 @@ void Tokenizer::simplifyTokenList() { std::ostringstream str; str << total_size; - tok2->str(str.str().c_str()); + tok2->str(str.str()); // Delete the other tokens.. for (int i = 0; i < 3; i++) { @@ -2334,7 +2334,7 @@ bool Tokenizer::simplifyIfNot() if (Token::Match(tok, "%var% == 0")) { tok->deleteNext(); - tok->next()->str(tok->str().c_str()); + tok->next()->str(tok->str()); tok->str("!"); ret = true; }