mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
Support getting size of JSON object
This commit is contained in:
parent
97a024a47f
commit
10e83e8220
19
db/json.cpp
19
db/json.cpp
@ -557,15 +557,20 @@ public:
|
||||
ObjectBuilder &b;
|
||||
};
|
||||
|
||||
BSONObj fromjson( const char *str ) {
|
||||
if ( str[0] == '\0' )
|
||||
BSONObj fromjson( const char *str , int* len) {
|
||||
if ( str[0] == '\0' ){
|
||||
if (len) *len = 0;
|
||||
return BSONObj();
|
||||
}
|
||||
|
||||
ObjectBuilder b;
|
||||
JsonGrammar parser( b );
|
||||
parse_info<> result = parse( str, parser, space_p );
|
||||
if ( !result.full ) {
|
||||
int len = strnlen(result.stop , 10);
|
||||
massert( 10340 , "Failure parsing JSON string near: " + string( result.stop, len ) , false );
|
||||
if (len) {
|
||||
*len = result.stop - str;
|
||||
} else if ( !result.full ) {
|
||||
int limit = strnlen(result.stop , 10);
|
||||
msgasserted(10340, "Failure parsing JSON string near: " + string( result.stop, limit ));
|
||||
}
|
||||
BSONObj ret = b.pop();
|
||||
assert( b.empty() );
|
||||
@ -576,8 +581,4 @@ public:
|
||||
return fromjson( str.c_str() );
|
||||
}
|
||||
|
||||
BSONObj fromjson( istream &str ) {
|
||||
return BSONObj();
|
||||
}
|
||||
|
||||
} // namespace mongo
|
||||
|
Loading…
Reference in New Issue
Block a user