diff --git a/src/emitter.cpp b/src/emitter.cpp index bec348c..176a21c 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -299,7 +299,7 @@ namespace YAML case EmitterNodeType::FlowMap: // TODO: if we were writing null, and // we wanted it blank, we wouldn't want a space - if(m_pState->HasBegunNode()) + if(m_pState->HasBegunContent()) m_stream << " "; break; case EmitterNodeType::BlockSeq: @@ -332,16 +332,16 @@ namespace YAML case EmitterNodeType::Scalar: case EmitterNodeType::FlowSeq: case EmitterNodeType::FlowMap: - if(m_stream.col() < nextIndent) - m_stream << IndentTo(nextIndent); - else + if(m_pState->HasBegunContent()) m_stream << " "; + else + m_stream << IndentTo(nextIndent); break; case EmitterNodeType::BlockSeq: m_stream << "\n"; break; case EmitterNodeType::BlockMap: - if(m_pState->HasBegunNode()) + if(m_pState->HasBegunContent()) m_stream << "\n"; break; } @@ -381,10 +381,10 @@ namespace YAML case EmitterNodeType::Scalar: case EmitterNodeType::FlowSeq: case EmitterNodeType::FlowMap: - if(m_stream.col() < curIndent) - m_stream << IndentTo(curIndent); - else + if(m_pState->HasBegunContent()) m_stream << " "; + else + m_stream << IndentTo(curIndent); break; case EmitterNodeType::BlockSeq: case EmitterNodeType::BlockMap: @@ -397,10 +397,7 @@ namespace YAML case EmitterNodeType::Scalar: case EmitterNodeType::FlowSeq: case EmitterNodeType::FlowMap: - if(m_stream.col() < nextIndent) - m_stream << IndentTo(nextIndent); - else - m_stream << " "; + m_stream << " "; break; case EmitterNodeType::BlockSeq: case EmitterNodeType::BlockMap: diff --git a/src/emitterstate.h b/src/emitterstate.h index 8305b3d..6c630f2 100644 --- a/src/emitterstate.h +++ b/src/emitterstate.h @@ -31,7 +31,7 @@ namespace YAML // basic state checking bool good() const { return m_isGood; } const std::string GetLastError() const { return m_lastError; } - void SetError(const std::string& error) { throw std::runtime_error(error); m_isGood = false; m_lastError = error; } + void SetError(const std::string& error) { m_isGood = false; m_lastError = error; } // node handling void SetAnchor(); @@ -53,6 +53,7 @@ namespace YAML bool HasAnchor() const { return m_hasAnchor; } bool HasTag() const { return m_hasTag; } bool HasBegunNode() const { return m_hasAnchor || m_hasTag || m_hasNonContent; } + bool HasBegunContent() const { return m_hasAnchor || m_hasTag; } void ClearModifiedSettings(); diff --git a/util/sandbox.cpp b/util/sandbox.cpp index e40504f..8c3ccd2 100644 --- a/util/sandbox.cpp +++ b/util/sandbox.cpp @@ -4,19 +4,13 @@ int main() { YAML::Emitter out; - out << YAML::Anchor("monkey") << YAML::LocalTag("a"); out << YAML::BeginSeq; - out << "foo"; - out << YAML::LocalTag("hi") << "bar"; - out << YAML::Anchor("asdf") << YAML::BeginMap; - out << "a" << "b" << "c"; - out << YAML::Anchor("a") << YAML::BeginMap; - out << YAML::Anchor("d") << "a" << "b"; + out << "item 1"; + out << YAML::BeginMap; + out << "pens" << "a"; + out << "pencils" << "b"; out << YAML::EndMap; - out << YAML::EndMap; - out << YAML::LocalTag("hi") << YAML::BeginSeq; - out << "a" << "b" << YAML::Alias("monkey"); - out << YAML::EndSeq; + out << "item 2"; out << YAML::EndSeq; std::cout << out.c_str() << "\n";