From b5d8241dfab626bf1ee66668a1d19846e82b78c5 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Mon, 21 May 2012 21:04:10 -0500 Subject: [PATCH] Added block seq indentation --- src/emitter.cpp | 7 +++++++ src/emitterstate.cpp | 9 +++++++-- src/emitterstate.h | 1 + util/sandbox.cpp | 3 +++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/emitter.cpp b/src/emitter.cpp index 62bf5b9..985f337 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -312,6 +312,13 @@ namespace YAML void Emitter::BlockSeqPrepareNode() { + const unsigned curIndent = m_pState->CurIndent(); + if(m_stream.col() > curIndent) { + m_stream << "\n"; + } + m_stream << IndentTo(curIndent); + m_stream << "-"; + m_stream << IndentTo(curIndent + m_pState->CurGroupIndent()); } void Emitter::FlowMapPrepareNode() diff --git a/src/emitterstate.cpp b/src/emitterstate.cpp index f42e462..60cb5f1 100644 --- a/src/emitterstate.cpp +++ b/src/emitterstate.cpp @@ -61,8 +61,8 @@ namespace YAML { BeginNode(); - unsigned lastIndent = (m_groups.empty() ? 0 : m_groups.top().indent); - m_curIndent += lastIndent; + const int lastGroupIndent = (m_groups.empty() ? 0 : m_groups.top().indent); + m_curIndent += lastGroupIndent; std::auto_ptr pGroup(new Group(type)); @@ -114,6 +114,11 @@ namespace YAML return (m_groups.top().flow == Flow ? FlowType::Flow : FlowType::Block); } + int EmitterState::CurGroupIndent() const + { + return m_groups.empty() ? 0 : m_groups.top().indent; + } + void EmitterState::ClearModifiedSettings() { m_modifiedSettings.clear(); diff --git a/src/emitterstate.h b/src/emitterstate.h index 92eabe8..cd0a5e5 100644 --- a/src/emitterstate.h +++ b/src/emitterstate.h @@ -39,6 +39,7 @@ namespace YAML GroupType::value CurGroupType() const; FlowType::value CurGroupFlowType() const; + int CurGroupIndent() const; int CurIndent() const { return m_curIndent; } bool HasAnchor() const { return m_hasAnchor; } bool HasTag() const { return m_hasTag; } diff --git a/util/sandbox.cpp b/util/sandbox.cpp index 24504d1..9321662 100644 --- a/util/sandbox.cpp +++ b/util/sandbox.cpp @@ -4,7 +4,10 @@ int main() { YAML::Emitter out; + out << YAML::BeginSeq; out << "foo"; + out << "bar"; + out << YAML::EndSeq; std::cout << out.c_str() << "\n"; return 0;