diff --git a/src/emitter.cpp b/src/emitter.cpp index 802f86a..e399f4a 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -304,6 +304,8 @@ namespace YAML void Emitter::BlockSeqPrepareNode(EmitterNodeType::value child) { const unsigned curIndent = m_pState->CurIndent(); + const unsigned nextIndent = curIndent + m_pState->CurGroupIndent(); + if(!m_pState->HasTag() && !m_pState->HasAnchor()) { if(m_pState->CurGroupChildCount() > 0) { m_stream << "\n"; @@ -311,6 +313,23 @@ namespace YAML m_stream << IndentTo(curIndent); m_stream << "-"; } + + switch(child) { + case EmitterNodeType::None: + case EmitterNodeType::Scalar: + case EmitterNodeType::FlowSeq: + case EmitterNodeType::FlowMap: + if(m_stream.col() < nextIndent) + m_stream << IndentTo(nextIndent); + else + m_stream << " "; + break; + case EmitterNodeType::BlockSeq: + m_stream << "\n"; + break; + case EmitterNodeType::BlockMap: + break; + } } void Emitter::FlowMapPrepareNode(EmitterNodeType::value child) @@ -319,15 +338,59 @@ namespace YAML void Emitter::BlockMapPrepareNode(EmitterNodeType::value child) { + const unsigned curIndent = m_pState->CurIndent(); + const unsigned nextIndent = curIndent + m_pState->CurGroupIndent(); + const std::size_t childCount = m_pState->CurGroupChildCount(); + if(!m_pState->HasTag() && !m_pState->HasAnchor()) { - const std::size_t childCount = m_pState->CurGroupChildCount(); if(childCount % 2 == 0) { // key if(childCount > 0) { m_stream << "\n"; } + if(false /* long key */) { + } } else { // value + if(false /* was long key */) { + } else { + m_stream << ":"; + } + } + } + + if(childCount % 2 == 0) { + // key + switch(child) { + case EmitterNodeType::None: + case EmitterNodeType::Scalar: + case EmitterNodeType::FlowSeq: + case EmitterNodeType::FlowMap: + if(m_stream.col() < curIndent) + m_stream << IndentTo(curIndent); + else + m_stream << " "; + break; + case EmitterNodeType::BlockSeq: + case EmitterNodeType::BlockMap: + break; + } + } else { + // value + switch(child) { + case EmitterNodeType::None: + case EmitterNodeType::Scalar: + case EmitterNodeType::FlowSeq: + case EmitterNodeType::FlowMap: + if(m_stream.col() < nextIndent) + m_stream << IndentTo(nextIndent); + else + m_stream << " "; + break; + case EmitterNodeType::BlockSeq: + case EmitterNodeType::BlockMap: + m_stream << "\n"; + break; } } } diff --git a/util/sandbox.cpp b/util/sandbox.cpp index 9321662..27b3631 100644 --- a/util/sandbox.cpp +++ b/util/sandbox.cpp @@ -7,6 +7,9 @@ int main() out << YAML::BeginSeq; out << "foo"; out << "bar"; + out << YAML::BeginMap; + out << "a" << "b" << "c" << "d"; + out << YAML::EndMap; out << YAML::EndSeq; std::cout << out.c_str() << "\n";