mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 04:41:16 +00:00
Prevent trailing spaces when emitting literal strings (#1005)
This commit is contained in:
@@ -366,13 +366,13 @@ bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str,
|
|||||||
bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
|
bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
|
||||||
std::size_t indent) {
|
std::size_t indent) {
|
||||||
out << "|\n";
|
out << "|\n";
|
||||||
out << IndentTo(indent);
|
|
||||||
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(indent);
|
out << "\n";
|
||||||
} else {
|
} else {
|
||||||
|
out<< IndentTo(indent);
|
||||||
WriteCodePoint(out, codePoint);
|
WriteCodePoint(out, codePoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -382,6 +382,20 @@ TEST_F(EmitterTest, ScalarFormat) {
|
|||||||
"crazy\tsymbols that we like");
|
"crazy\tsymbols that we like");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(EmitterTest, LiteralWithoutTrailingSpaces) {
|
||||||
|
out << YAML::BeginMap;
|
||||||
|
out << YAML::Key << "key";
|
||||||
|
out << YAML::Value << YAML::Literal;
|
||||||
|
out << "expect that with two newlines\n\n"
|
||||||
|
"no spaces are emitted in the empty line";
|
||||||
|
out << YAML::EndMap;
|
||||||
|
|
||||||
|
ExpectEmit(
|
||||||
|
"key: |\n"
|
||||||
|
" expect that with two newlines\n\n"
|
||||||
|
" no spaces are emitted in the empty line");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(EmitterTest, AutoLongKeyScalar) {
|
TEST_F(EmitterTest, AutoLongKeyScalar) {
|
||||||
out << BeginMap;
|
out << BeginMap;
|
||||||
out << Key << Literal << "multi-line\nscalar";
|
out << Key << Literal << "multi-line\nscalar";
|
||||||
|
Reference in New Issue
Block a user