mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Added flow map, simple key/value
This commit is contained in:
@@ -221,6 +221,9 @@ namespace YAML
|
||||
if(!good())
|
||||
return;
|
||||
|
||||
if(m_pState->CurGroupChildCount() == 0)
|
||||
m_pState->ForceFlow();
|
||||
|
||||
if(m_pState->CurGroupFlowType() == FlowType::Flow) {
|
||||
if(m_stream.comment())
|
||||
m_stream << "\n";
|
||||
@@ -250,6 +253,18 @@ namespace YAML
|
||||
if(!good())
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -390,6 +405,87 @@ namespace YAML
|
||||
|
||||
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)
|
||||
|
@@ -65,9 +65,17 @@ namespace YAML
|
||||
return;
|
||||
|
||||
assert(m_groups.top().type == GroupType::Map);
|
||||
assert(m_groups.top().flowType == FlowType::Block);
|
||||
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()
|
||||
{
|
||||
|
@@ -38,6 +38,7 @@ namespace YAML
|
||||
void SetTag();
|
||||
void SetNonContent();
|
||||
void SetLongKey();
|
||||
void ForceFlow();
|
||||
void StartedScalar();
|
||||
void StartedGroup(GroupType::value type);
|
||||
void EndedGroup(GroupType::value type);
|
||||
|
Reference in New Issue
Block a user