From b8a87c43bce1017c0710a706343c647210197c88 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Tue, 22 May 2012 15:42:45 -0500 Subject: [PATCH] Added flow seq --- src/emitter.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/emitterstate.cpp | 8 ++++++++ src/emitterstate.h | 1 + util/sandbox.cpp | 7 +++---- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/emitter.cpp b/src/emitter.cpp index 0a72545..a639e9e 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -221,6 +221,15 @@ namespace YAML if(!good()) return; + if(m_pState->CurGroupFlowType() == FlowType::Flow) { + if(m_stream.comment()) + m_stream << "\n"; + m_stream << IndentTo(m_pState->CurIndent()); + if(m_pState->CurGroupChildCount() == 0) + m_stream << "["; + m_stream << "]"; + } + m_pState->EndedGroup(GroupType::Seq); } @@ -315,6 +324,33 @@ namespace YAML void Emitter::FlowSeqPrepareNode(EmitterNodeType::value child) { + const unsigned curIndent = m_pState->CurIndent(); + const unsigned lastIndent = m_pState->LastIndent(); + + if(!m_pState->HasBegunNode()) { + if(m_stream.comment()) + m_stream << "\n"; + m_stream << IndentTo(lastIndent); + if(m_pState->CurGroupChildCount() == 0) + m_stream << "["; + else + m_stream << ","; + } + + switch(child) { + case EmitterNodeType::None: + break; + case EmitterNodeType::Property: + case EmitterNodeType::Scalar: + case EmitterNodeType::FlowSeq: + case EmitterNodeType::FlowMap: + SpaceOrIndentTo(m_pState->HasBegunContent() || m_pState->CurGroupChildCount() > 0, curIndent); + break; + case EmitterNodeType::BlockSeq: + case EmitterNodeType::BlockMap: + assert(false); + break; + } } void Emitter::BlockSeqPrepareNode(EmitterNodeType::value child) diff --git a/src/emitterstate.cpp b/src/emitterstate.cpp index 8eed776..14b2535 100644 --- a/src/emitterstate.cpp +++ b/src/emitterstate.cpp @@ -188,6 +188,14 @@ namespace YAML return m_groups.empty() ? false : m_groups.top().longKey; } + int EmitterState::LastIndent() const + { + if(m_groups.size() <= 1) + return 0; + + return m_curIndent - m_groups.top(-1).indent; + } + void EmitterState::ClearModifiedSettings() { m_modifiedSettings.clear(); diff --git a/src/emitterstate.h b/src/emitterstate.h index 6125bb5..d533dae 100644 --- a/src/emitterstate.h +++ b/src/emitterstate.h @@ -51,6 +51,7 @@ namespace YAML std::size_t CurGroupChildCount() const; bool CurGroupLongKey() const; + int LastIndent() 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 972d954..83956d2 100644 --- a/util/sandbox.cpp +++ b/util/sandbox.cpp @@ -4,11 +4,10 @@ int main() { YAML::Emitter out; - out << YAML::BeginMap; - out << YAML::LongKey << "a" << "b"; + out << YAML::Flow; + out << YAML::BeginSeq; out << "a" << "b"; - out << YAML::EndMap; - out << YAML::EndMap; + out << YAML::EndSeq; std::cout << out.c_str() << "\n"; return 0;