Skip to content

Commit

Permalink
cleanup: fix the eol dumping in JSONFormatter flush & close_section
Browse files Browse the repository at this point in the history
Signed-off-by: Aran85 zhangzengran@h3c.com
  • Loading branch information
Aran85 committed Aug 6, 2015
1 parent 5c6075f commit b34363a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/common/Formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
}
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion src/test/crush/CrushWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit b34363a

Please sign in to comment.