diff --git a/simplecpp.cpp b/simplecpp.cpp index 25d0d3c3..e14b9779 100644 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -205,29 +206,29 @@ bool simplecpp::Token::endsWithOneOf(const char c[]) const return std::strchr(c, string[string.size() - 1U]) != nullptr; } -void simplecpp::Token::printAll() const +void simplecpp::Token::printAll(std::ostream& ostr) const { const Token *tok = this; while (tok->previous) tok = tok->previous; for (; tok; tok = tok->next) { if (tok->previous) { - std::cout << (sameline(tok, tok->previous) ? ' ' : '\n'); + ostr << (sameline(tok, tok->previous) ? ' ' : '\n'); } - std::cout << tok->str(); + ostr << tok->str(); } - std::cout << std::endl; + ostr << std::endl; } -void simplecpp::Token::printOut() const +void simplecpp::Token::printOut(std::ostream& ostr) const { for (const Token *tok = this; tok; tok = tok->next) { if (tok != this) { - std::cout << (sameline(tok, tok->previous) ? ' ' : '\n'); + ostr << (sameline(tok, tok->previous) ? ' ' : '\n'); } - std::cout << tok->str(); + ostr << tok->str(); } - std::cout << std::endl; + ostr << std::endl; } // cppcheck-suppress noConstructor - we call init() in the inherited to initialize the private members @@ -553,9 +554,9 @@ void simplecpp::TokenList::push_back(Token *tok) backToken = tok; } -void simplecpp::TokenList::dump() const +void simplecpp::TokenList::dump(std::ostream& ostr) const { - std::cout << stringify() << std::endl; + ostr << stringify() << std::endl; } std::string simplecpp::TokenList::stringify() const diff --git a/simplecpp.h b/simplecpp.h index 76487d6c..0d11513a 100644 --- a/simplecpp.h +++ b/simplecpp.h @@ -176,8 +176,8 @@ namespace simplecpp { return mExpandedFrom.find(m) != mExpandedFrom.end(); } - void printAll() const; - void printOut() const; + void printAll(std::ostream& ostr) const; + void printOut(std::ostream& ostr) const; private: TokenString string; @@ -235,7 +235,7 @@ namespace simplecpp { } void push_back(Token *tok); - void dump() const; + void dump(std::ostream& ostr) const; std::string stringify() const; void readfile(Stream &stream, const std::string &filename=std::string(), OutputList *outputList = nullptr);