mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Fix formatting when writing " as a character.
This commit is contained in:
@@ -375,14 +375,16 @@ bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
|
|||||||
bool WriteChar(ostream_wrapper& out, char ch) {
|
bool WriteChar(ostream_wrapper& out, char ch) {
|
||||||
if (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')) {
|
if (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')) {
|
||||||
out << ch;
|
out << ch;
|
||||||
} else if ((0x20 <= ch && ch <= 0x7e) || ch == ' ') {
|
} else if (ch == '\"') {
|
||||||
out << "\"" << ch << "\"";
|
out << "\"\\\"\"";
|
||||||
} else if (ch == '\t') {
|
} else if (ch == '\t') {
|
||||||
out << "\"\\t\"";
|
out << "\"\\t\"";
|
||||||
} else if (ch == '\n') {
|
} else if (ch == '\n') {
|
||||||
out << "\"\\n\"";
|
out << "\"\\n\"";
|
||||||
} else if (ch == '\b') {
|
} else if (ch == '\b') {
|
||||||
out << "\"\\b\"";
|
out << "\"\\b\"";
|
||||||
|
} else if ((0x20 <= ch && ch <= 0x7e) || ch == ' ') {
|
||||||
|
out << "\"" << ch << "\"";
|
||||||
} else {
|
} else {
|
||||||
out << "\"";
|
out << "\"";
|
||||||
WriteDoubleQuoteEscapeSequence(out, ch);
|
WriteDoubleQuoteEscapeSequence(out, ch);
|
||||||
|
@@ -962,6 +962,14 @@ TEST_F(EmitterTest, QuoteNull) {
|
|||||||
ExpectEmit("\"null\"");
|
ExpectEmit("\"null\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(EmitterTest, ValueOfDoubleQuote) {
|
||||||
|
out << YAML::BeginMap;
|
||||||
|
out << YAML::Key << "foo" << YAML::Value << '"';
|
||||||
|
out << YAML::EndMap;
|
||||||
|
|
||||||
|
ExpectEmit("foo: \"\\\"\"");
|
||||||
|
}
|
||||||
|
|
||||||
class EmitterErrorTest : public ::testing::Test {
|
class EmitterErrorTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
void ExpectEmitError(const std::string& expectedError) {
|
void ExpectEmitError(const std::string& expectedError) {
|
||||||
|
Reference in New Issue
Block a user