diff --git a/include/yaml-cpp/emittermanip.h b/include/yaml-cpp/emittermanip.h index 89f7256..97c9894 100644 --- a/include/yaml-cpp/emittermanip.h +++ b/include/yaml-cpp/emittermanip.h @@ -113,11 +113,13 @@ inline _Tag SecondaryTag(const std::string content) { } struct _Comment { - _Comment(const std::string& content_) : content(content_) {} + _Comment(const std::string& content_, int col = -1) : content(content_), indent_col(col), indent_to(col > 0) {} std::string content; + size_t indent_col; + bool indent_to; }; -inline _Comment Comment(const std::string content) { return _Comment(content); } +inline _Comment Comment(const std::string content, int col = -1) { return _Comment(content, col); } struct _Precision { _Precision(int floatPrecision_, int doublePrecision_) diff --git a/src/emitter.cpp b/src/emitter.cpp index 016beb1..0310edc 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -872,7 +872,12 @@ Emitter& Emitter::Write(const _Comment& comment) { PrepareNode(EmitterNodeType::NoType); if (m_stream.col() > 0) - m_stream << Indentation(m_pState->GetPreCommentIndent()); + { + if(comment.indent_to && comment.indent_col > m_stream.col()) + m_stream << IndentTo(comment.indent_col); + else + m_stream << Indentation(m_pState->GetPreCommentIndent()); + } Utils::WriteComment(m_stream, comment.content, m_pState->GetPostCommentIndent());