diff --git a/src/emitter.cpp b/src/emitter.cpp index 55752f3..7afcfa0 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -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 diff --git a/src/emitterstate.cpp b/src/emitterstate.cpp index b3bb07b..bc15b1b 100644 --- a/src/emitterstate.cpp +++ b/src/emitterstate.cpp @@ -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 diff --git a/src/emitterstate.h b/src/emitterstate.h index 989f61f..68e96af 100644 --- a/src/emitterstate.h +++ b/src/emitterstate.h @@ -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 diff --git a/util/sandbox.cpp b/util/sandbox.cpp index f306573..32ee902 100644 --- a/util/sandbox.cpp +++ b/util/sandbox.cpp @@ -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";