Skip to content

Commit 28a2091

Browse files
committed
Move old FastWriter stuff out of new Builder
1 parent 177b7b8 commit 28a2091

File tree

3 files changed

+6
-67
lines changed

3 files changed

+6
-67
lines changed

doc/jsoncpp.dox

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ writer->write( root );
9494
// If you like the defaults, you can insert directly into a stream.
9595
std::cout << root;
9696

97+
// If desired, remember to add a linefeed and flush.
98+
std::cout << std::endl;
99+
97100
// Of course, you can write to `std::ostringstream` if you prefer. Or
98101
// use `writeString()` for convenience.
99102
std::string document = Json::writeString( root, builder );

include/json/writer.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class StreamWriterBuilder;
3636
std::shared_ptr<StreamWriter> writer(
3737
builder.newStreamWriter(&std::cout));
3838
writer->write(value);
39-
std::cout.flush();
39+
std::cout << std::endl; // add lf and flush
4040
\endcode
4141
*/
4242
class JSON_API StreamWriter {
@@ -77,24 +77,6 @@ class JSON_API StreamWriter {
7777
Default: "\t"
7878
*/
7979
Builder& withIndentation(std::string indentation);
80-
/** \brief Drop the "null" string from the writer's output for nullValues.
81-
* Strictly speaking, this is not valid JSON. But when the output is being
82-
* fed to a browser's Javascript, it makes for smaller output and the
83-
* browser can handle the output just fine.
84-
*/
85-
Builder& withDropNullPlaceholders(bool v);
86-
/** \brief Do not add \n at end of document.
87-
* Normally, we add an extra newline, just because.
88-
*/
89-
Builder& withOmitEndingLineFeed(bool v);
90-
/** \brief Add a space after ':'.
91-
* If indentation is non-empty, we surround colon with whitespace,
92-
* e.g. " : "
93-
* This will add back the trailing space when there is no indentation.
94-
* This seems dubious when the entire document is on a single line,
95-
* but we leave this here to repduce the behavior of the old `FastWriter`.
96-
*/
97-
Builder& withEnableYAMLCompatibility(bool v);
9880

9981
/// Do not take ownership of sout, but maintain a reference.
10082
StreamWriter* newStreamWriter(std::ostream* sout) const;

src/lib_json/json_writer.cpp

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -963,25 +963,16 @@ class StreamWriterBuilder {
963963
typedef StreamWriter::CommentStyle CommentStyle;
964964
CommentStyle cs_;
965965
std::string indentation_;
966-
bool dropNullPlaceholders_;
967-
bool omitEndingLineFeed_;
968-
bool enableYAMLCompatibility_;
969966
public:
970967
StreamWriterBuilder();
971968
virtual ~StreamWriterBuilder();
972969
virtual void setCommentStyle(CommentStyle cs);
973970
virtual void setIndentation(std::string indentation);
974-
virtual void setDropNullPlaceholders(bool v);
975-
virtual void setOmitEndingLineFeed(bool v);
976-
virtual void setEnableYAMLCompatibility(bool v);
977971
virtual StreamWriter* newStreamWriter(std::ostream* sout) const;
978972
};
979973
StreamWriterBuilder::StreamWriterBuilder()
980974
: cs_(CommentStyle::All)
981975
, indentation_("\t")
982-
, dropNullPlaceholders_(false)
983-
, omitEndingLineFeed_(false)
984-
, enableYAMLCompatibility_(false)
985976
{
986977
}
987978
StreamWriterBuilder::~StreamWriterBuilder()
@@ -996,36 +987,14 @@ void StreamWriterBuilder::setIndentation(std::string v)
996987
indentation_ = v;
997988
if (indentation_.empty()) cs_ = CommentStyle::None;
998989
}
999-
void StreamWriterBuilder::setDropNullPlaceholders(bool v)
1000-
{
1001-
dropNullPlaceholders_ = v;
1002-
}
1003-
void StreamWriterBuilder::setOmitEndingLineFeed(bool v)
1004-
{
1005-
omitEndingLineFeed_ = v;
1006-
}
1007-
void StreamWriterBuilder::setEnableYAMLCompatibility(bool v)
1008-
{
1009-
enableYAMLCompatibility_ = v;
1010-
}
1011990
StreamWriter* StreamWriterBuilder::newStreamWriter(std::ostream* stream) const
1012991
{
1013992
std::string colonSymbol = " : ";
1014993
if (indentation_.empty()) {
1015-
if (enableYAMLCompatibility_) {
1016-
colonSymbol = ": ";
1017-
} else {
1018-
colonSymbol = ":";
1019-
}
994+
colonSymbol = ":";
1020995
}
1021996
std::string nullSymbol = "null";
1022-
if (dropNullPlaceholders_) {
1023-
nullSymbol = "";
1024-
}
1025-
std::string endingLineFeedSymbol = "\n";
1026-
if (omitEndingLineFeed_) {
1027-
endingLineFeedSymbol = "";
1028-
}
997+
std::string endingLineFeedSymbol = "";
1029998
return new BuiltStyledStreamWriter(stream,
1030999
indentation_, cs_,
10311000
colonSymbol, nullSymbol, endingLineFeedSymbol);
@@ -1068,21 +1037,6 @@ StreamWriter::Builder& StreamWriter::Builder::withIndentation(std::string v)
10681037
own_->setIndentation(v);
10691038
return *this;
10701039
}
1071-
StreamWriter::Builder& StreamWriter::Builder::withDropNullPlaceholders(bool v)
1072-
{
1073-
own_->setDropNullPlaceholders(v);
1074-
return *this;
1075-
}
1076-
StreamWriter::Builder& StreamWriter::Builder::withOmitEndingLineFeed(bool v)
1077-
{
1078-
own_->setOmitEndingLineFeed(v);
1079-
return *this;
1080-
}
1081-
StreamWriter::Builder& StreamWriter::Builder::withEnableYAMLCompatibility(bool v)
1082-
{
1083-
own_->setEnableYAMLCompatibility(v);
1084-
return *this;
1085-
}
10861040
StreamWriter* StreamWriter::Builder::newStreamWriter(
10871041
std::ostream* sout) const
10881042
{

0 commit comments

Comments
 (0)