Skip to content
Closed
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ds283 <D.Seery@sussex.ac.uk>
Egor Tensin <Egor.Tensin@gmail.com>
eightnoteight <mr.eightnoteight@gmail.com>
Evince <baneyue@gmail.com>
Fedor Moiseev <fedormsv@gmail.com>
filipjs <filipjs@users.noreply.github.com>
findblar <ft@finbarr.ca>
Florian Meier <florian.meier@koalo.de>
Expand Down
14 changes: 14 additions & 0 deletions include/json/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,20 @@ class JSON_API CharReaderBuilder : public CharReader::Factory {
static void strictMode(Json::Value* settings);
};

/** Consume entire string and use its begin/end.
* Someday we might have a real StreamReader, but for now this
* is convenient.
*/
bool JSON_API parseFromString(CharReader::Factory const&, char const* str, size_t len, Value* root,
String* errs);

/** Consume entire string and use its begin/end.
* Someday we might have a real StreamReader, but for now this
* is convenient.
*/
bool JSON_API parseFromString(CharReader::Factory const&,const String&, Value* root,
String* errs);

/** Consume entire stream and use its begin/end.
* Someday we might have a real StreamReader, but for now this
* is convenient.
Expand Down
21 changes: 16 additions & 5 deletions src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1968,16 +1968,27 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
//////////////////////////////////
// global functions

bool parseFromString(CharReader::Factory const& fact, char const* str, size_t len, Value* root,
String* errs) {
char const* begin = str;
char const* end = str + len;
// Note that we do not actually need a null-terminator.
CharReaderPtr const reader(fact.newCharReader());
return reader->parse(begin, end, root, errs);
}

bool parseFromString(CharReader::Factory const& fact, const String& doc, Value* root,
String* errs) {
// Note that we do not actually need a null-terminator.
return parseFromString(fact, doc.data(), doc.size(), root, errs);
}

bool parseFromStream(CharReader::Factory const& fact, IStream& sin, Value* root,
String* errs) {
OStringStream ssin;
ssin << sin.rdbuf();
String doc = ssin.str();
char const* begin = doc.data();
char const* end = begin + doc.size();
// Note that we do not actually need a null-terminator.
CharReaderPtr const reader(fact.newCharReader());
return reader->parse(begin, end, root, errs);
return parseFromString(fact, doc, root, errs);
}

IStream& operator>>(IStream& sin, Value& root) {
Expand Down