mirror of
https://github.com/privacore/open-source-search-engine.git
synced 2025-07-16 02:46:08 -04:00
start implementing handling for array of "objects"
This commit is contained in:
53
XmlDoc.cpp
53
XmlDoc.cpp
@ -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
|
||||
|
1
XmlDoc.h
1
XmlDoc.h
@ -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;
|
||||
|
Reference in New Issue
Block a user