|
| 1 | +From b14e73199bba8165de4bc05ca574c4fd904a42f5 Mon Sep 17 00:00:00 2001 |
| 2 | +From: lizz <lizz@sensetime.com> |
| 3 | +Date: Fri, 10 Apr 2020 23:02:21 +0800 |
| 4 | +Subject: [PATCH 1/1] No trailing space for BuiltStyledStreamWriter |
| 5 | + |
| 6 | +Signed-off-by: lizz <lizz@sensetime.com> |
| 7 | +--- |
| 8 | + lib_json/json_writer.cpp | 10 +++++++++- |
| 9 | + test_lib_json/main.cpp | 4 ++-- |
| 10 | + 2 files changed, 11 insertions(+), 3 deletions(-) |
| 11 | + |
| 12 | +diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp |
| 13 | +index 56195dc15..edefbc5f5 100644 |
| 14 | +--- a/src/lib_json/json_writer.cpp |
| 15 | ++++ b/src/lib_json/json_writer.cpp |
| 16 | +@@ -982,7 +982,15 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) { |
| 17 | + writeCommentBeforeValue(childValue); |
| 18 | + writeWithIndent(valueToQuotedStringN( |
| 19 | + name.data(), static_cast<unsigned>(name.length()), emitUTF8_)); |
| 20 | +- *sout_ << colonSymbol_; |
| 21 | ++ size_t n = colonSymbol_.size(); |
| 22 | ++ if ((childValue.type() == objectValue && !childValue.empty()) || |
| 23 | ++ (childValue.type() == arrayValue && !childValue.empty() && |
| 24 | ++ ((cs_ == CommentStyle::All) || isMultilineArray(childValue)))) { |
| 25 | ++ // Line-ending colon, so trim any trailing space from it |
| 26 | ++ for (; n && colonSymbol_[n - 1] == ' '; --n) |
| 27 | ++ ; |
| 28 | ++ } |
| 29 | ++ sout_->write(colonSymbol_.data(), n); |
| 30 | + writeValue(childValue); |
| 31 | + if (++it == members.end()) { |
| 32 | + writeCommentAfterValueOnSameLine(childValue); |
| 33 | +diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp |
| 34 | +index 7b20e41ec..c18c2ac1e 100644 |
| 35 | +--- a/src/test_lib_json/main.cpp |
| 36 | ++++ b/src/test_lib_json/main.cpp |
| 37 | +@@ -2469,7 +2469,7 @@ JSONTEST_FIXTURE_LOCAL(StreamWriterTest, writeNumericValue) { |
| 38 | + JSONTEST_FIXTURE_LOCAL(StreamWriterTest, writeArrays) { |
| 39 | + Json::StreamWriterBuilder writer; |
| 40 | + const Json::String expected("{\n" |
| 41 | +- "\t\"property1\" : \n" |
| 42 | ++ "\t\"property1\" :\n" |
| 43 | + "\t[\n" |
| 44 | + "\t\t\"value1\",\n" |
| 45 | + "\t\t\"value2\"\n" |
| 46 | +@@ -2489,7 +2489,7 @@ JSONTEST_FIXTURE_LOCAL(StreamWriterTest, writeArrays) { |
| 47 | + JSONTEST_FIXTURE_LOCAL(StreamWriterTest, writeNestedObjects) { |
| 48 | + Json::StreamWriterBuilder writer; |
| 49 | + const Json::String expected("{\n" |
| 50 | +- "\t\"object1\" : \n" |
| 51 | ++ "\t\"object1\" :\n" |
| 52 | + "\t{\n" |
| 53 | + "\t\t\"bool\" : true,\n" |
| 54 | + "\t\t\"nested\" : 123\n" |
0 commit comments