0
0
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:
Mathias Stearn 2010-06-14 08:38:17 -04:00
parent 97a024a47f
commit 10e83e8220
2 changed files with 12 additions and 10 deletions

View File

@ -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

View File

@ -35,6 +35,7 @@ namespace mongo {
*/
BSONObj fromjson(const string &str);
BSONObj fromjson(const char *str);
/** len will be size of JSON object in text chars. */
BSONObj fromjson(const char *str, int* len=NULL);
} // namespace mongo