From f8ff3ac8e4bfb041f3911c4ee8faeaf502738d8c Mon Sep 17 00:00:00 2001 From: Ryan Krattiger Date: Fri, 28 Jul 2017 15:08:31 -0400 Subject: [PATCH] Added a parameter to fix the offset column of comments for pretty formatting --- include/yaml-cpp/emittermanip.h | 6 ++++-- src/emitter.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) 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 ebeb059..729e90f 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -874,7 +874,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());