Split the block map prepare into key/value

This commit is contained in:
Jesse Beder
2012-05-22 12:56:40 -05:00
parent 80823583a0
commit a626424baa
2 changed files with 53 additions and 43 deletions

View File

@@ -92,6 +92,8 @@ namespace YAML
void BlockSeqPrepareNode(EmitterNodeType::value child);
void FlowMapPrepareNode(EmitterNodeType::value child);
void BlockMapPrepareNode(EmitterNodeType::value child);
void BlockMapPrepareKey(EmitterNodeType::value child);
void BlockMapPrepareValue(EmitterNodeType::value child);
void SpaceOrIndentTo(bool requireSpace, unsigned indent);

View File

@@ -357,59 +357,67 @@ namespace YAML
}
void Emitter::BlockMapPrepareNode(EmitterNodeType::value child)
{
const std::size_t childCount = m_pState->CurGroupChildCount();
if(childCount % 2 == 0)
BlockMapPrepareKey(child);
else
BlockMapPrepareValue(child);
}
void Emitter::BlockMapPrepareKey(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->HasBegunNode()) {
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 > 0) {
m_stream << "\n";
}
if(false /* long key */) {
}
}
if(childCount % 2 == 0) {
// key
switch(child) {
case EmitterNodeType::None:
break;
case EmitterNodeType::Property:
case EmitterNodeType::Scalar:
case EmitterNodeType::FlowSeq:
case EmitterNodeType::FlowMap:
SpaceOrIndentTo(m_pState->HasBegunContent(), curIndent);
break;
case EmitterNodeType::BlockSeq:
case EmitterNodeType::BlockMap:
break;
}
switch(child) {
case EmitterNodeType::None:
break;
case EmitterNodeType::Property:
case EmitterNodeType::Scalar:
case EmitterNodeType::FlowSeq:
case EmitterNodeType::FlowMap:
SpaceOrIndentTo(m_pState->HasBegunContent(), curIndent);
break;
case EmitterNodeType::BlockSeq:
case EmitterNodeType::BlockMap:
break;
}
}
void Emitter::BlockMapPrepareValue(EmitterNodeType::value child)
{
const unsigned curIndent = m_pState->CurIndent();
const unsigned nextIndent = curIndent + m_pState->CurGroupIndent();
if(false /* was long key */) {
} else {
// value
switch(child) {
case EmitterNodeType::None:
break;
case EmitterNodeType::Property:
case EmitterNodeType::Scalar:
case EmitterNodeType::FlowSeq:
case EmitterNodeType::FlowMap:
SpaceOrIndentTo(true, nextIndent);
break;
case EmitterNodeType::BlockSeq:
case EmitterNodeType::BlockMap:
m_stream << "\n";
break;
}
m_stream << ":";
}
switch(child) {
case EmitterNodeType::None:
break;
case EmitterNodeType::Property:
case EmitterNodeType::Scalar:
case EmitterNodeType::FlowSeq:
case EmitterNodeType::FlowMap:
SpaceOrIndentTo(true, nextIndent);
break;
case EmitterNodeType::BlockSeq:
case EmitterNodeType::BlockMap:
m_stream << "\n";
break;
}
}