mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Implemented block seq and block map indentation/newlines
This commit is contained in:
@@ -304,6 +304,8 @@ namespace YAML
|
|||||||
void Emitter::BlockSeqPrepareNode(EmitterNodeType::value child)
|
void Emitter::BlockSeqPrepareNode(EmitterNodeType::value child)
|
||||||
{
|
{
|
||||||
const unsigned curIndent = m_pState->CurIndent();
|
const unsigned curIndent = m_pState->CurIndent();
|
||||||
|
const unsigned nextIndent = curIndent + m_pState->CurGroupIndent();
|
||||||
|
|
||||||
if(!m_pState->HasTag() && !m_pState->HasAnchor()) {
|
if(!m_pState->HasTag() && !m_pState->HasAnchor()) {
|
||||||
if(m_pState->CurGroupChildCount() > 0) {
|
if(m_pState->CurGroupChildCount() > 0) {
|
||||||
m_stream << "\n";
|
m_stream << "\n";
|
||||||
@@ -311,6 +313,23 @@ namespace YAML
|
|||||||
m_stream << IndentTo(curIndent);
|
m_stream << IndentTo(curIndent);
|
||||||
m_stream << "-";
|
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)
|
void Emitter::FlowMapPrepareNode(EmitterNodeType::value child)
|
||||||
@@ -319,15 +338,59 @@ namespace YAML
|
|||||||
|
|
||||||
void Emitter::BlockMapPrepareNode(EmitterNodeType::value child)
|
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()) {
|
if(!m_pState->HasTag() && !m_pState->HasAnchor()) {
|
||||||
const std::size_t childCount = m_pState->CurGroupChildCount();
|
|
||||||
if(childCount % 2 == 0) {
|
if(childCount % 2 == 0) {
|
||||||
// key
|
// key
|
||||||
if(childCount > 0) {
|
if(childCount > 0) {
|
||||||
m_stream << "\n";
|
m_stream << "\n";
|
||||||
}
|
}
|
||||||
|
if(false /* long key */) {
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// value
|
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,9 @@ int main()
|
|||||||
out << YAML::BeginSeq;
|
out << YAML::BeginSeq;
|
||||||
out << "foo";
|
out << "foo";
|
||||||
out << "bar";
|
out << "bar";
|
||||||
|
out << YAML::BeginMap;
|
||||||
|
out << "a" << "b" << "c" << "d";
|
||||||
|
out << YAML::EndMap;
|
||||||
out << YAML::EndSeq;
|
out << YAML::EndSeq;
|
||||||
|
|
||||||
std::cout << out.c_str() << "\n";
|
std::cout << out.c_str() << "\n";
|
||||||
|
Reference in New Issue
Block a user