mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Added comments, not entirely correct
This commit is contained in:
@@ -18,11 +18,13 @@ namespace YAML
|
|||||||
|
|
||||||
void reserve(unsigned size);
|
void reserve(unsigned size);
|
||||||
void put(char ch);
|
void put(char ch);
|
||||||
|
void set_comment() { m_comment = true; }
|
||||||
const char *str() const { return m_buffer; }
|
const char *str() const { return m_buffer; }
|
||||||
|
|
||||||
unsigned row() const { return m_row; }
|
unsigned row() const { return m_row; }
|
||||||
unsigned col() const { return m_col; }
|
unsigned col() const { return m_col; }
|
||||||
unsigned pos() const { return m_pos; }
|
unsigned pos() const { return m_pos; }
|
||||||
|
bool comment() const { return m_comment; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char *m_buffer;
|
char *m_buffer;
|
||||||
@@ -30,6 +32,7 @@ namespace YAML
|
|||||||
unsigned m_size;
|
unsigned m_size;
|
||||||
|
|
||||||
unsigned m_row, m_col;
|
unsigned m_row, m_col;
|
||||||
|
bool m_comment;
|
||||||
};
|
};
|
||||||
|
|
||||||
ostream& operator << (ostream& out, const char *str);
|
ostream& operator << (ostream& out, const char *str);
|
||||||
|
@@ -589,7 +589,13 @@ namespace YAML
|
|||||||
if(!good())
|
if(!good())
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
m_pState->StartedScalar();
|
PrepareNode(EmitterNodeType::None);
|
||||||
|
|
||||||
|
if(m_stream.col() > 0)
|
||||||
|
m_stream << Indentation(m_pState->GetPreCommentIndent());
|
||||||
|
Utils::WriteComment(m_stream, comment.content, m_pState->GetPostCommentIndent());
|
||||||
|
|
||||||
|
m_pState->SetNonContent();
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@@ -333,15 +333,18 @@ namespace YAML
|
|||||||
{
|
{
|
||||||
const unsigned curIndent = out.col();
|
const unsigned curIndent = out.col();
|
||||||
out << "#" << Indentation(postCommentIndent);
|
out << "#" << Indentation(postCommentIndent);
|
||||||
|
out.set_comment();
|
||||||
int codePoint;
|
int codePoint;
|
||||||
for(std::string::const_iterator i = str.begin();
|
for(std::string::const_iterator i = str.begin();
|
||||||
GetNextCodePointAndAdvance(codePoint, i, str.end());
|
GetNextCodePointAndAdvance(codePoint, i, str.end());
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if(codePoint == '\n')
|
if(codePoint == '\n') {
|
||||||
out << "\n" << IndentTo(curIndent) << "#" << Indentation(postCommentIndent);
|
out << "\n" << IndentTo(curIndent) << "#" << Indentation(postCommentIndent);
|
||||||
else
|
out.set_comment();
|
||||||
|
} else {
|
||||||
WriteCodePoint(out, codePoint);
|
WriteCodePoint(out, codePoint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
ostream::ostream(): m_buffer(0), m_pos(0), m_size(0), m_row(0), m_col(0)
|
ostream::ostream(): m_buffer(0), m_pos(0), m_size(0), m_row(0), m_col(0), m_comment(false)
|
||||||
{
|
{
|
||||||
reserve(1024);
|
reserve(1024);
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,7 @@ namespace YAML
|
|||||||
if(ch == '\n') {
|
if(ch == '\n') {
|
||||||
m_row++;
|
m_row++;
|
||||||
m_col = 0;
|
m_col = 0;
|
||||||
|
m_comment = false;
|
||||||
} else
|
} else
|
||||||
m_col++;
|
m_col++;
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
YAML::Emitter out;
|
YAML::Emitter out;
|
||||||
|
out << YAML::Comment("Hello");
|
||||||
out << YAML::BeginSeq;
|
out << YAML::BeginSeq;
|
||||||
out << "item 1";
|
out << "item 1";
|
||||||
out << YAML::BeginMap;
|
out << YAML::BeginMap;
|
||||||
|
Reference in New Issue
Block a user