summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAran85 <zhangzengran@h3c.com>2015-08-06 11:45:43 +0200
committerAran85 <zhangzengran@h3c.com>2015-08-06 11:49:58 +0200
commitb34363ac0fd40e2d1a2b311e566f3db5e2f30da8 (patch)
tree576b8d865cd019ee09b5d03fe8657eb642f495ef
parentMerge pull request #4394 from majianpeng/tools-copyget-flags (diff)
downloadceph-b34363ac0fd40e2d1a2b311e566f3db5e2f30da8.tar.xz
ceph-b34363ac0fd40e2d1a2b311e566f3db5e2f30da8.zip
cleanup: fix the eol dumping in JSONFormatter flush & close_section
Signed-off-by: Aran85 zhangzengran@h3c.com
-rw-r--r--src/common/Formatter.cc4
-rw-r--r--src/test/crush/CrushWrapper.cc4
2 files changed, 5 insertions, 3 deletions
diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc
index 7c166ef0986..32588750997 100644
--- a/src/common/Formatter.cc
+++ b/src/common/Formatter.cc
@@ -126,8 +126,6 @@ void JSONFormatter::flush(std::ostream& os)
{
finish_pending_string();
os << m_ss.str();
- if (m_pretty)
- os << "\n";
m_ss.clear();
m_ss.str("");
}
@@ -238,6 +236,8 @@ void JSONFormatter::close_section()
}
m_ss << (entry.is_array ? ']' : '}');
m_stack.pop_back();
+ if (m_pretty && m_stack.empty())
+ m_ss << "\n";
}
void JSONFormatter::finish_pending_string()
diff --git a/src/test/crush/CrushWrapper.cc b/src/test/crush/CrushWrapper.cc
index c690ada4f16..bbf40ec6d63 100644
--- a/src/test/crush/CrushWrapper.cc
+++ b/src/test/crush/CrushWrapper.cc
@@ -686,11 +686,13 @@ TEST(CrushWrapper, dump_rules) {
// no ruleset by default
{
Formatter *f = Formatter::create("json-pretty");
+ f->open_array_section("rules");
c->dump_rules(f);
+ f->close_section();
stringstream ss;
f->flush(ss);
delete f;
- EXPECT_EQ("\n", ss.str());
+ EXPECT_EQ("[]\n", ss.str());
}
string name("NAME");