Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/yaml-cpp/emittermanip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down
7 changes: 6 additions & 1 deletion src/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down