Skip to content

added option to FastWriter which omits the trailing new line character #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/json/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class JSON_API FastWriter : public Writer {
*/
void dropNullPlaceholders();

void omitEndingLineFeed();

public: // overridden from Writer
virtual std::string write(const Value &root);

Expand All @@ -63,6 +65,7 @@ class JSON_API FastWriter : public Writer {
std::string document_;
bool yamlCompatiblityEnabled_;
bool dropNullPlaceholders_;
bool omitEndingLineFeed_;
};

/** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a
Expand Down
7 changes: 5 additions & 2 deletions src/lib_json/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,19 @@ Writer::~Writer() {}
// //////////////////////////////////////////////////////////////////

FastWriter::FastWriter()
: yamlCompatiblityEnabled_(false), dropNullPlaceholders_(false) {}
: yamlCompatiblityEnabled_(false), dropNullPlaceholders_(false), omitEndingLineFeed_(false) {}

void FastWriter::enableYAMLCompatibility() { yamlCompatiblityEnabled_ = true; }

void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; }

void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; }

std::string FastWriter::write(const Value &root) {
document_ = "";
writeValue(root);
document_ += "\n";
if (!omitEndingLineFeed_)
document_ += "\n";
return document_;
}

Expand Down