From 054518f002e8589f93c29bf9db3a4c8453368777 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Tue, 3 Mar 2009 19:45:58 +0000 Subject: [PATCH] Refactoring: Combined printOut() and stringifyList() in Token class --- src/token.cpp | 30 +++++------------------------- src/token.h | 2 +- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/token.cpp b/src/token.cpp index 76afb7a59..5c866a090 100644 --- a/src/token.cpp +++ b/src/token.cpp @@ -465,35 +465,15 @@ void Token::linenr(unsigned int linenr) void Token::printOut(const char *title) const { - std::cout << std::endl << "###"; - if (title) - std::cout << " " << title << " "; - else - std::cout << "########"; - - std::cout << "###" << std::endl; - unsigned int lineNum = 0; - for (const Token *t = this; t; t = t->next()) - { - if (lineNum != t->linenr()) - { - std::cout << std::endl << t->linenr() << ": "; - lineNum = t->linenr(); - } - - std::cout << t->str(); - if (t->varId()) - std::cout << " (" << t->varId() << ")"; - - std::cout << " "; - } - std::cout << std::endl; + std::cout << stringifyList(true, title) << std::endl; } - -std::string Token::stringifyList(const bool varid) const +std::string Token::stringifyList(const bool varid, const char *title) const { std::ostringstream ret; + if (title) + ret << "\n### " << title << " ###\n"; + unsigned int linenr = 0; for (const Token *tok = this; tok; tok = tok->next()) { diff --git a/src/token.h b/src/token.h index 0e97a4371..9251d5401 100644 --- a/src/token.h +++ b/src/token.h @@ -186,7 +186,7 @@ public: static void replace(Token *replaceThis, Token *start, Token *end); /** Stringify a token list (with or without varId) */ - std::string stringifyList(const bool varid) const; + std::string stringifyList(const bool varid = true, const char *title = 0) const; private: void next(Token *next);