mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 04:41:16 +00:00
Tweaked spacing for comments
This commit is contained in:
@@ -93,6 +93,8 @@ namespace YAML
|
|||||||
void FlowMapPrepareNode(EmitterNodeType::value child);
|
void FlowMapPrepareNode(EmitterNodeType::value child);
|
||||||
void BlockMapPrepareNode(EmitterNodeType::value child);
|
void BlockMapPrepareNode(EmitterNodeType::value child);
|
||||||
|
|
||||||
|
void SpaceOrIndentTo(bool requireSpace, unsigned indent);
|
||||||
|
|
||||||
const char *ComputeFullBoolName(bool b) const;
|
const char *ComputeFullBoolName(bool b) const;
|
||||||
bool CanEmitNewline() const;
|
bool CanEmitNewline() const;
|
||||||
|
|
||||||
|
@@ -322,8 +322,11 @@ namespace YAML
|
|||||||
const unsigned curIndent = m_pState->CurIndent();
|
const unsigned curIndent = m_pState->CurIndent();
|
||||||
const unsigned nextIndent = curIndent + m_pState->CurGroupIndent();
|
const unsigned nextIndent = curIndent + m_pState->CurGroupIndent();
|
||||||
|
|
||||||
if(!m_pState->HasBegunNode()) {
|
if(child == EmitterNodeType::None)
|
||||||
if(m_pState->CurGroupChildCount() > 0) {
|
return;
|
||||||
|
|
||||||
|
if(!m_pState->HasBegunContent()) {
|
||||||
|
if(m_pState->CurGroupChildCount() > 0 || m_stream.comment()) {
|
||||||
m_stream << "\n";
|
m_stream << "\n";
|
||||||
}
|
}
|
||||||
m_stream << IndentTo(curIndent);
|
m_stream << IndentTo(curIndent);
|
||||||
@@ -332,20 +335,18 @@ namespace YAML
|
|||||||
|
|
||||||
switch(child) {
|
switch(child) {
|
||||||
case EmitterNodeType::None:
|
case EmitterNodeType::None:
|
||||||
|
break;
|
||||||
case EmitterNodeType::Property:
|
case EmitterNodeType::Property:
|
||||||
case EmitterNodeType::Scalar:
|
case EmitterNodeType::Scalar:
|
||||||
case EmitterNodeType::FlowSeq:
|
case EmitterNodeType::FlowSeq:
|
||||||
case EmitterNodeType::FlowMap:
|
case EmitterNodeType::FlowMap:
|
||||||
if(m_pState->HasBegunContent())
|
SpaceOrIndentTo(m_pState->HasBegunContent(), nextIndent);
|
||||||
m_stream << " ";
|
|
||||||
else
|
|
||||||
m_stream << IndentTo(nextIndent);
|
|
||||||
break;
|
break;
|
||||||
case EmitterNodeType::BlockSeq:
|
case EmitterNodeType::BlockSeq:
|
||||||
m_stream << "\n";
|
m_stream << "\n";
|
||||||
break;
|
break;
|
||||||
case EmitterNodeType::BlockMap:
|
case EmitterNodeType::BlockMap:
|
||||||
if(m_pState->HasBegunContent())
|
if(m_pState->HasBegunContent() || m_stream.comment())
|
||||||
m_stream << "\n";
|
m_stream << "\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -382,14 +383,12 @@ namespace YAML
|
|||||||
// key
|
// key
|
||||||
switch(child) {
|
switch(child) {
|
||||||
case EmitterNodeType::None:
|
case EmitterNodeType::None:
|
||||||
|
break;
|
||||||
case EmitterNodeType::Property:
|
case EmitterNodeType::Property:
|
||||||
case EmitterNodeType::Scalar:
|
case EmitterNodeType::Scalar:
|
||||||
case EmitterNodeType::FlowSeq:
|
case EmitterNodeType::FlowSeq:
|
||||||
case EmitterNodeType::FlowMap:
|
case EmitterNodeType::FlowMap:
|
||||||
if(m_pState->HasBegunContent())
|
SpaceOrIndentTo(m_pState->HasBegunContent(), curIndent);
|
||||||
m_stream << " ";
|
|
||||||
else
|
|
||||||
m_stream << IndentTo(curIndent);
|
|
||||||
break;
|
break;
|
||||||
case EmitterNodeType::BlockSeq:
|
case EmitterNodeType::BlockSeq:
|
||||||
case EmitterNodeType::BlockMap:
|
case EmitterNodeType::BlockMap:
|
||||||
@@ -399,11 +398,12 @@ namespace YAML
|
|||||||
// value
|
// value
|
||||||
switch(child) {
|
switch(child) {
|
||||||
case EmitterNodeType::None:
|
case EmitterNodeType::None:
|
||||||
|
break;
|
||||||
case EmitterNodeType::Property:
|
case EmitterNodeType::Property:
|
||||||
case EmitterNodeType::Scalar:
|
case EmitterNodeType::Scalar:
|
||||||
case EmitterNodeType::FlowSeq:
|
case EmitterNodeType::FlowSeq:
|
||||||
case EmitterNodeType::FlowMap:
|
case EmitterNodeType::FlowMap:
|
||||||
m_stream << " ";
|
SpaceOrIndentTo(true, nextIndent);
|
||||||
break;
|
break;
|
||||||
case EmitterNodeType::BlockSeq:
|
case EmitterNodeType::BlockSeq:
|
||||||
case EmitterNodeType::BlockMap:
|
case EmitterNodeType::BlockMap:
|
||||||
@@ -413,6 +413,17 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SpaceOrIndentTo
|
||||||
|
// . Prepares for some more content by proper spacing
|
||||||
|
void Emitter::SpaceOrIndentTo(bool requireSpace, unsigned indent)
|
||||||
|
{
|
||||||
|
if(m_stream.comment())
|
||||||
|
m_stream << "\n";
|
||||||
|
if(m_stream.col() > 0 && requireSpace)
|
||||||
|
m_stream << " ";
|
||||||
|
m_stream << IndentTo(indent);
|
||||||
|
}
|
||||||
|
|
||||||
// *******************************************************************************************
|
// *******************************************************************************************
|
||||||
// overloads of Write
|
// overloads of Write
|
||||||
|
|
||||||
|
@@ -6,9 +6,10 @@ int main()
|
|||||||
YAML::Emitter out;
|
YAML::Emitter out;
|
||||||
out << YAML::Comment("Hello");
|
out << YAML::Comment("Hello");
|
||||||
out << YAML::BeginSeq;
|
out << YAML::BeginSeq;
|
||||||
out << "item 1";
|
out << YAML::Comment("Hello");
|
||||||
out << YAML::BeginMap;
|
out << YAML::Anchor("a") << YAML::Comment("anchor") << "item 1" << YAML::Comment("a");
|
||||||
out << "pens" << "a";
|
out << YAML::BeginMap << YAML::Comment("b");
|
||||||
|
out << "pens" << YAML::Comment("foo") << "a" << YAML::Comment("bar");
|
||||||
out << "pencils" << "b";
|
out << "pencils" << "b";
|
||||||
out << YAML::EndMap;
|
out << YAML::EndMap;
|
||||||
out << "item 2";
|
out << "item 2";
|
||||||
|
Reference in New Issue
Block a user