diff options
Diffstat (limited to 'db/json.cpp')
-rw-r--r-- | db/json.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/db/json.cpp b/db/json.cpp new file mode 100644 index 00000000000..6c875ab95d4 --- /dev/null +++ b/db/json.cpp @@ -0,0 +1,46 @@ +// json.cpp + +#include "stdafx.h" +#include "json.h" +#include "../util/builder.h" + +/* partial implementation for now */ + +void skipWhite(const char *&p) { + while( *p == ' ' || *p == '\r' || *p == '\n' || *p == '\t' ) + p++; +} + +void value(JSObjBuilder& b, const char *&p, string& id) { + if( strncmp(p, "ObjId()", 7) == 0 ) { + p += 7; + b.appendOID(id.c_str()); + } +} + +void _fromjson(JSObjBuilder& b, const char *&p) { + while( 1 ) { + skipWhite(p); + if( *p == 0 ) + break; + if( *p == '{' ) { _fromjson(b,++p); continue; } + if( *p == '}' ) { ++p; break; } + if( *p == '_' || isalpha(*p) ) { + string id; + while( *p == '_' || isalpha(*p) || isdigit(*p) ) { + id += *p++; + } + skipWhite(p); + assert( *p == ':' ); p++; + skipWhite(p); + value(b, p, id); + continue; + } + } +} + +JSObj fromjson(const char *str) { + JSObjBuilder b; + _fromjson(b,str); + return b.doneAndDecouple(); +} |