Skip to content
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

Add makeCharReader function to deprecated newCharReader #1424

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion doc/jsoncpp.dox
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ CharReaders and StreamWriters are not thread-safe, but they are re-usable.
\code
Json::CharReaderBuilder rbuilder;
cfg >> rbuilder.settings_;
std::unique_ptr<Json::CharReader> const reader(rbuilder.newCharReader());
std::unique_ptr<Json::CharReader> const reader = rbuilder.makeCharReader();
reader->parse(start, stop, &value1, &errs);
// ...
reader->parse(start, stop, &value2, &errs);
Expand Down
5 changes: 4 additions & 1 deletion include/json/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class JSON_API CharReader {
* \throw std::exception if something goes wrong (e.g. invalid settings)
*/
virtual CharReader* newCharReader() const = 0;
std::unique_ptr<CharReader> makeCharReader() const;
AssafPassalCG marked this conversation as resolved.
Show resolved Hide resolved
}; // Factory
}; // CharReader

Expand Down Expand Up @@ -337,8 +338,10 @@ class JSON_API CharReaderBuilder : public CharReader::Factory {
CharReaderBuilder();
~CharReaderBuilder() override;

/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Doxygen comment /**.
Compress to 1-line.

* \deprecated Use makeCharReader.
*/
CharReader* newCharReader() const override;

AssafPassalCG marked this conversation as resolved.
Show resolved Hide resolved
/** \return true if 'settings' are legal and consistent;
* otherwise, indicate bad settings via 'invalid'.
*/
Expand Down
9 changes: 7 additions & 2 deletions src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ bool Reader::decodeDouble(Token& token, Value& decoded) {
value = -std::numeric_limits<double>::infinity();
else if (!std::isinf(value))
return addError(
"'" + String(token.start_, token.end_) + "' is not a number.", token);
"'" + String(token.start_, token.end_) + "' is not a number.", token);
AssafPassalCG marked this conversation as resolved.
Show resolved Hide resolved
}
decoded = value;
return true;
Expand Down Expand Up @@ -1660,7 +1660,7 @@ bool OurReader::decodeDouble(Token& token, Value& decoded) {
value = -std::numeric_limits<double>::infinity();
else if (!std::isinf(value))
return addError(
"'" + String(token.start_, token.end_) + "' is not a number.", token);
"'" + String(token.start_, token.end_) + "' is not a number.", token);
AssafPassalCG marked this conversation as resolved.
Show resolved Hide resolved
}
decoded = value;
return true;
Expand Down Expand Up @@ -1872,6 +1872,10 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
return allErrors;
}

std::unique_ptr<CharReader> CharReader::Factory::makeCharReader() const {
return std::unique_ptr<CharReader>(newCharReader());
}

class OurCharReader : public CharReader {
bool const collectComments_;
OurReader reader_;
Expand All @@ -1891,6 +1895,7 @@ class OurCharReader : public CharReader {

CharReaderBuilder::CharReaderBuilder() { setDefaults(&settings_); }
CharReaderBuilder::~CharReaderBuilder() = default;

AssafPassalCG marked this conversation as resolved.
Show resolved Hide resolved
CharReader* CharReaderBuilder::newCharReader() const {
bool collectComments = settings_["collectComments"].asBool();
OurFeatures features = OurFeatures::all();
Expand Down
5 changes: 3 additions & 2 deletions src/lib_json/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ String valueToString(double value, bool useSpecialFloats,
if (!isfinite(value)) {
static const char* const reps[2][3] = {{"NaN", "-Infinity", "Infinity"},
{"null", "-1e+9999", "1e+9999"}};
return reps[useSpecialFloats ? 0 : 1]
[isnan(value) ? 0 : (value < 0) ? 1 : 2];
return reps[useSpecialFloats ? 0 : 1][isnan(value) ? 0
AssafPassalCG marked this conversation as resolved.
Show resolved Hide resolved
: (value < 0) ? 1
: 2];
}

String buffer(size_t(36), '\0');
Expand Down