mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Added flow map, simple key/value
This commit is contained in:
@@ -93,11 +93,19 @@ namespace YAML
|
|||||||
void PrepareTopNode(EmitterNodeType::value child);
|
void PrepareTopNode(EmitterNodeType::value child);
|
||||||
void FlowSeqPrepareNode(EmitterNodeType::value child);
|
void FlowSeqPrepareNode(EmitterNodeType::value child);
|
||||||
void BlockSeqPrepareNode(EmitterNodeType::value child);
|
void BlockSeqPrepareNode(EmitterNodeType::value child);
|
||||||
|
|
||||||
void FlowMapPrepareNode(EmitterNodeType::value child);
|
void FlowMapPrepareNode(EmitterNodeType::value child);
|
||||||
|
|
||||||
|
void FlowMapPrepareLongKey(EmitterNodeType::value child);
|
||||||
|
void FlowMapPrepareLongKeyValue(EmitterNodeType::value child);
|
||||||
|
void FlowMapPrepareSimpleKey(EmitterNodeType::value child);
|
||||||
|
void FlowMapPrepareSimpleKeyValue(EmitterNodeType::value child);
|
||||||
|
|
||||||
void BlockMapPrepareNode(EmitterNodeType::value child);
|
void BlockMapPrepareNode(EmitterNodeType::value child);
|
||||||
|
|
||||||
void BlockMapPrepareLongKey(EmitterNodeType::value child);
|
void BlockMapPrepareLongKey(EmitterNodeType::value child);
|
||||||
void BlockMapPrepareSimpleKey(EmitterNodeType::value child);
|
|
||||||
void BlockMapPrepareLongKeyValue(EmitterNodeType::value child);
|
void BlockMapPrepareLongKeyValue(EmitterNodeType::value child);
|
||||||
|
void BlockMapPrepareSimpleKey(EmitterNodeType::value child);
|
||||||
void BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child);
|
void BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child);
|
||||||
|
|
||||||
void SpaceOrIndentTo(bool requireSpace, unsigned indent);
|
void SpaceOrIndentTo(bool requireSpace, unsigned indent);
|
||||||
|
@@ -221,6 +221,9 @@ namespace YAML
|
|||||||
if(!good())
|
if(!good())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(m_pState->CurGroupChildCount() == 0)
|
||||||
|
m_pState->ForceFlow();
|
||||||
|
|
||||||
if(m_pState->CurGroupFlowType() == FlowType::Flow) {
|
if(m_pState->CurGroupFlowType() == FlowType::Flow) {
|
||||||
if(m_stream.comment())
|
if(m_stream.comment())
|
||||||
m_stream << "\n";
|
m_stream << "\n";
|
||||||
@@ -250,6 +253,18 @@ namespace YAML
|
|||||||
if(!good())
|
if(!good())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(m_pState->CurGroupChildCount() == 0)
|
||||||
|
m_pState->ForceFlow();
|
||||||
|
|
||||||
|
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::Map);
|
m_pState->EndedGroup(GroupType::Map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,6 +405,87 @@ namespace YAML
|
|||||||
|
|
||||||
void Emitter::FlowMapPrepareNode(EmitterNodeType::value child)
|
void Emitter::FlowMapPrepareNode(EmitterNodeType::value child)
|
||||||
{
|
{
|
||||||
|
if(m_pState->CurGroupChildCount() % 2 == 0) {
|
||||||
|
if(m_pState->GetMapKeyFormat() == LongKey)
|
||||||
|
m_pState->SetLongKey();
|
||||||
|
|
||||||
|
if(m_pState->CurGroupLongKey())
|
||||||
|
FlowMapPrepareLongKey(child);
|
||||||
|
else
|
||||||
|
FlowMapPrepareSimpleKey(child);
|
||||||
|
} else {
|
||||||
|
if(m_pState->CurGroupLongKey())
|
||||||
|
FlowMapPrepareLongKeyValue(child);
|
||||||
|
else
|
||||||
|
FlowMapPrepareSimpleKeyValue(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Emitter::FlowMapPrepareLongKey(EmitterNodeType::value child)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Emitter::FlowMapPrepareLongKeyValue(EmitterNodeType::value child)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Emitter::FlowMapPrepareSimpleKey(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::FlowMapPrepareSimpleKeyValue(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);
|
||||||
|
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::BlockMapPrepareNode(EmitterNodeType::value child)
|
void Emitter::BlockMapPrepareNode(EmitterNodeType::value child)
|
||||||
|
@@ -65,9 +65,17 @@ namespace YAML
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
assert(m_groups.top().type == GroupType::Map);
|
assert(m_groups.top().type == GroupType::Map);
|
||||||
assert(m_groups.top().flowType == FlowType::Block);
|
|
||||||
m_groups.top().longKey = true;
|
m_groups.top().longKey = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EmitterState::ForceFlow()
|
||||||
|
{
|
||||||
|
assert(!m_groups.empty());
|
||||||
|
if(m_groups.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_groups.top().flowType = FlowType::Flow;
|
||||||
|
}
|
||||||
|
|
||||||
void EmitterState::StartedNode()
|
void EmitterState::StartedNode()
|
||||||
{
|
{
|
||||||
|
@@ -38,6 +38,7 @@ namespace YAML
|
|||||||
void SetTag();
|
void SetTag();
|
||||||
void SetNonContent();
|
void SetNonContent();
|
||||||
void SetLongKey();
|
void SetLongKey();
|
||||||
|
void ForceFlow();
|
||||||
void StartedScalar();
|
void StartedScalar();
|
||||||
void StartedGroup(GroupType::value type);
|
void StartedGroup(GroupType::value type);
|
||||||
void EndedGroup(GroupType::value type);
|
void EndedGroup(GroupType::value type);
|
||||||
|
Reference in New Issue
Block a user