Rewrote the output so that it emits correct YAML.

Fixed a bug in the last newline of a block folded scalar.
This commit is contained in:
Jesse Beder
2008-07-05 05:28:23 +00:00
parent d98007b0be
commit dacc631968
12 changed files with 98 additions and 145 deletions

View File

@@ -112,28 +112,30 @@ namespace YAML
pScanner->PopNextToken();
}
void Node::Write(std::ostream& out, int indent)
void Node::Write(std::ostream& out, int indent, bool startedLine, bool onlyOneCharOnLine) const
{
if(m_tag != "") {
for(int i=0;i<indent;i++)
out << " ";
out << "{tag: " << m_tag << "}\n";
}
// write anchor/alias
if(m_anchor != "") {
for(int i=0;i<indent;i++)
out << " ";
if(m_alias)
out << "{alias: " << m_anchor << "}\n";
out << "*";
else
out << "{anchor: " << m_anchor << "}\n";
out << "&";
out << m_anchor << " ";
startedLine = true;
onlyOneCharOnLine = false;
}
// write tag
if(m_tag != "") {
out << "!<" << m_tag << "> ";
startedLine = true;
onlyOneCharOnLine = false;
}
if(!m_pContent) {
for(int i=0;i<indent;i++)
out << " ";
out << "{no content}\n";
out << std::endl;
} else {
m_pContent->Write(out, indent);
m_pContent->Write(out, indent, startedLine, onlyOneCharOnLine);
}
}
@@ -266,4 +268,10 @@ namespace YAML
node.m_pContent->Read(c);
}
std::ostream& operator << (std::ostream& out, const Node& node)
{
node.Write(out, 0, false, false);
return out;
}
}