static void dumpJsonValue(const JsonValue& val) { static int level = 0; level++; assert(level < 10); if(const JsonArray* arr = val.toArray()) { printf("["); //printf("%p", arr); for(size_t i=0; i<arr->size(); i++) { if(i != 0) printf(", "); dumpJsonValue((*arr)[i]); } printf("]"); } else if(const JsonObject* obj = val.toObject()) { printf("{%p", obj); #if 0 for(JsonObject::iterator itr = obj->begin(); itr != obj->end(); ++itr) { if(itr != obj->begin()) printf(", "); printf("%s:", itr->first.c_str()); dumpJsonValue(*itr->second); } #endif printf("}"); } else { printf("%s", val.toString().c_str()); } level--; }
static string parseCommentLine(const string& entry, const char* line) { JsonValue* root = parseJson(line); assert(root); //dumpJsonValue(*root); //printf("\n"); const JsonArray* arr = root->toArray(); assert(arr); string query; //printf("size: %zu\n", arr->size()); for(size_t i=0; i<arr->size(); i++) { const JsonObject* hp = (*arr)[i].toObject(); assert(hp); const JsonObject& h(*hp); query += "INSERT INTO '"CONFIG_TYPE"_comments' VALUES ("+entry+", "+ h["id"].toString()+");\n"; query += "INSERT INTO 'comments' VALUES ("+h["id"].toString()+", '"+ escape(h["user"].toString())+"', '"+ escape(h["body"].toString())+"', "+ h["rating"].toString()+", '"+ escape(h["date"].toString())+"', "+ h["indent"].toString()+");\n"; } delete root; return query; }