start implementing handling for array of "objects"

This commit is contained in:
Daniel Steinberg
2014-05-12 15:04:36 -07:00
parent f52bda67e1
commit 78e2bd8171
2 changed files with 54 additions and 0 deletions

@ -13595,6 +13595,59 @@ SafeBuf *XmlDoc::getTokenizedDiffbotReply ( ) {
char *text = dbr->getBufStart();
Json jp;
if ( ! jp.parseJsonStringIntoJsonItems ( text , m_niceness ) ) {
g_errno = EBADJSONPARSER;
return NULL;
}
JsonItem *jsonItem = jp.getItem("objects");
if ( jsonItem ) {
m_v3buf.safeMemcpy(jsonItem->getValue(), jsonItem->getValueLen());
m_v3buf.nullTerm();
// trim off the enclosing []'s
char *p = m_v3buf.getBufStart();
for ( ; *p && is_wspace_a(*p) ; p++ );
if ( *p == '[') *p = ' ';
char *e = m_v3buf.getBuf()-1;
for ( ; e>p && is_wspace_a(*e) ;e--);
if ( *e ==']') *e=' ';
// replace top level commas with \0's
long curlies = 0;
char *x = p;
bool inQuotes = false;
// scan now
for ( ; *x ; x++ ) {
// escaping a quote? ignore quote then.
if ( *x == '\\' && x[1] == '\"' ) {
// skip two bytes then..
x++;
continue;
}
if ( *x == '\"' ) {
inQuotes = ! inQuotes;
continue;
}
// if in a quote, ignore {} in there
if ( inQuotes ) continue;
if ( *x== '{' ) {
curlies++;
continue;
}
if ( *x == '}' ) {
curlies--;
continue;
}
if ( curlies != 0 ) continue;
if ( *x == ',' ) *x = '\0';
}
m_tokenizedDiffbotReplyPtr = &m_v3buf;
m_tokenizedDiffbotReplyValid = true;
return m_tokenizedDiffbotReplyPtr;
}
// it must have \"type\":\"product or \"type\":\"image
// in order for us to do the array separation logic below.
// we don't want to do this logic for articles because they

@ -1595,6 +1595,7 @@ class XmlDoc {
XmlDoc *m_dx;
char *m_diffbotObj;
SafeBuf m_diffbotReply;
SafeBuf m_v3buf;
SafeBuf *m_tokenizedDiffbotReplyPtr;
SafeBuf m_tokenizedDiffbotReply;
long m_diffbotReplyError;