mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-09-23 04:00:24 -04:00
#1209 add parseFromString to avoid unnecessary stringstream content copy
This commit is contained in:
parent
45733df96c
commit
a9025c7538
1
AUTHORS
1
AUTHORS
@ -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>
|
||||
|
@ -359,6 +359,20 @@ public:
|
||||
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.
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user