Added flow seq

This commit is contained in:
Jesse Beder
2012-05-22 15:42:45 -05:00
parent 2670ce8aaf
commit b8a87c43bc
4 changed files with 48 additions and 4 deletions

View File

@@ -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)

View File

@@ -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();

View File

@@ -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; }

View File

@@ -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;