Added newlines, fixed map/map

This commit is contained in:
Jesse Beder 2012-05-21 23:29:59 -05:00
parent b0dd0f862a
commit d3801b7482
4 changed files with 19 additions and 4 deletions

View File

@ -249,11 +249,15 @@ namespace YAML
{
if(!good())
return;
PrepareNode(m_pState->NextGroupType(GroupType::None));
m_stream << "\n";
m_pState->SetNonContent();
}
bool Emitter::CanEmitNewline() const
{
return false;
return true;
}
// Put the stream in a state so we can simply write the next node

View File

@ -4,7 +4,7 @@
namespace YAML
{
EmitterState::EmitterState(): m_isGood(true), m_curIndent(0), m_hasAnchor(false), m_hasTag(false)
EmitterState::EmitterState(): m_isGood(true), m_curIndent(0), m_hasAnchor(false), m_hasTag(false), m_hasNonContent(false)
{
// set default global manipulators
m_charset.set(EmitNonAscii);
@ -53,6 +53,11 @@ namespace YAML
m_hasTag = true;
}
void EmitterState::SetNonContent()
{
m_hasNonContent = true;
}
void EmitterState::BeginNode()
{
if(!m_groups.empty())
@ -60,6 +65,7 @@ namespace YAML
m_hasAnchor = false;
m_hasTag = false;
m_hasNonContent = false;
}
EmitterNodeType::value EmitterState::NextGroupType(GroupType::value type) const

View File

@ -36,6 +36,7 @@ namespace YAML
// node handling
void SetAnchor();
void SetTag();
void SetNonContent();
void BeginScalar();
void BeginGroup(GroupType::value type);
void EndGroup(GroupType::value type);
@ -51,7 +52,7 @@ namespace YAML
int CurIndent() const { return m_curIndent; }
bool HasAnchor() const { return m_hasAnchor; }
bool HasTag() const { return m_hasTag; }
bool HasBegunNode() const { return m_hasAnchor || m_hasTag; }
bool HasBegunNode() const { return m_hasAnchor || m_hasTag || m_hasNonContent; }
void ClearModifiedSettings();
@ -157,6 +158,7 @@ namespace YAML
unsigned m_curIndent;
bool m_hasAnchor;
bool m_hasTag;
bool m_hasNonContent;
};
template <typename T>

View File

@ -9,7 +9,10 @@ int main()
out << "foo";
out << YAML::LocalTag("hi") << "bar";
out << YAML::Anchor("asdf") << YAML::BeginMap;
out << "a" << "b" << "c" << "d";
out << "a" << "b" << "c" << YAML::Newline;
out << YAML::Anchor("a") << YAML::BeginMap;
out << "a" << "b";
out << YAML::EndMap;
out << YAML::EndMap;
out << YAML::LocalTag("hi") << YAML::BeginSeq;
out << "a" << "b";