aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-17 10:26:44 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-17 10:26:44 +0000
commit002d3254c72abe62e0f2c04b4ce7ee6bf0dc3587 (patch)
treefb88a5c1fa4a7f64df3a4e99905b082ea3dd13dd
parent5d300fffb9d7e236946ed9c39d411e857c3860c4 (diff)
downloadpaludis-002d3254c72abe62e0f2c04b4ce7ee6bf0dc3587.tar.gz
paludis-002d3254c72abe62e0f2c04b4ce7ee6bf0dc3587.tar.xz
Allow single line pretty printing
-rw-r--r--paludis/dep_atom_pretty_printer.cc32
-rw-r--r--paludis/dep_atom_pretty_printer.hh10
2 files changed, 30 insertions, 12 deletions
diff --git a/paludis/dep_atom_pretty_printer.cc b/paludis/dep_atom_pretty_printer.cc
index 8bc05f1..bda808f 100644
--- a/paludis/dep_atom_pretty_printer.cc
+++ b/paludis/dep_atom_pretty_printer.cc
@@ -40,52 +40,64 @@ paludis::operator<< (std::ostream & s, const DepAtomPrettyPrinter & p)
void
DepAtomPrettyPrinter::visit(const AllDepAtom * const a)
{
- _s << std::string(_indent, ' ') << "(" << std::endl;
+ _s << indent() << "(" << newline();
{
Save<unsigned> old_indent(&_indent, _indent + 4);
std::for_each(a->begin(), a->end(), accept_visitor(this));
}
- _s << std::string(_indent, ' ') << ")" << std::endl;
+ _s << indent() << ")" << newline();
}
void
DepAtomPrettyPrinter::visit(const AnyDepAtom * const a)
{
- _s << std::string(_indent, ' ') << "|| (" << std::endl;
+ _s << indent() << "|| (" << newline();
{
Save<unsigned> old_indent(&_indent, _indent + 4);
std::for_each(a->begin(), a->end(), accept_visitor(this));
}
- _s << std::string(_indent, ' ') << ")" << std::endl;
+ _s << indent() << ")" << newline();
}
void
DepAtomPrettyPrinter::visit(const UseDepAtom * const a)
{
- _s << std::string(_indent, ' ') << (a->inverse() ? "!" : "") <<
- a->flag() << "? (" << std::endl;
+ _s << indent() << (a->inverse() ? "!" : "") <<
+ a->flag() << "? (" << newline();
{
Save<unsigned> old_indent(&_indent, _indent + 4);
std::for_each(a->begin(), a->end(), accept_visitor(this));
}
- _s << std::string(_indent, ' ') << ")" << std::endl;
+ _s << indent() << ")" << newline();
}
void
DepAtomPrettyPrinter::visit(const PackageDepAtom * const p)
{
- _s << std::string(_indent, ' ') << *p << std::endl;
+ _s << indent() << *p << newline();
}
void
DepAtomPrettyPrinter::visit(const PlainTextDepAtom * const p)
{
- _s << std::string(_indent, ' ') << p->text() << std::endl;
+ _s << indent() << p->text() << newline();
}
void
DepAtomPrettyPrinter::visit(const BlockDepAtom * const b)
{
- _s << std::string(_indent, ' ') << "!" << *b->blocked_atom() << std::endl;
+ _s << indent() << "!" << *b->blocked_atom() << newline();
+}
+
+std::string
+DepAtomPrettyPrinter::newline() const
+{
+ return _use_newlines ? "\n" : " ";
+}
+
+std::string
+DepAtomPrettyPrinter::indent() const
+{
+ return _use_newlines ? std::string(_indent, ' ') : "";
}
diff --git a/paludis/dep_atom_pretty_printer.hh b/paludis/dep_atom_pretty_printer.hh
index 58af9f9..f612e07 100644
--- a/paludis/dep_atom_pretty_printer.hh
+++ b/paludis/dep_atom_pretty_printer.hh
@@ -44,13 +44,19 @@ namespace paludis
private:
std::stringstream _s;
unsigned _indent;
+ bool _use_newlines;
+
+ std::string newline() const;
+ std::string indent() const;
public:
/**
* Constructor.
*/
- DepAtomPrettyPrinter(unsigned initial_indent) :
- _indent(initial_indent)
+ DepAtomPrettyPrinter(unsigned initial_indent,
+ bool use_newlines = true) :
+ _indent(initial_indent),
+ _use_newlines(use_newlines)
{
}