Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <limits>
#include <list>
#include <map>
#include <ostream>
#include <set>
#include <sstream>
#include <stack>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions simplecpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void printOut(std::ostream& ostr) const;
void printOut(std::ostream& ostr) const;
void printAll() const {
this->printAll(std::cout);
}
void printOut() const {
this->printOut(std::cout);
}

private:
TokenString string;

Expand Down Expand Up @@ -235,7 +235,7 @@ namespace simplecpp {
}
void push_back(Token *tok);

void dump() const;
void dump(std::ostream& ostr) const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void dump(std::ostream& ostr) const;
void dump(std::ostream& ostr) const;
void dump() const {
this->dump(std::cout);
}

std::string stringify() const;

void readfile(Stream &stream, const std::string &filename=std::string(), OutputList *outputList = nullptr);
Expand Down
Loading