Skip to content

Commit

Permalink
Better encoding for warnings in JSON result format
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Harris committed Oct 6, 2009
1 parent 70aa7d1 commit a61f47c
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/frontend/results.c
Original file line number Diff line number Diff line change
Expand Up @@ -1326,15 +1326,6 @@ static void output_json(fs_query *q, int flags, FILE *out)
}
fprintf(out, "]},\n");

if (q->warnings) {
GSList *it;
for (it = q->warnings; it; it = it->next) {
fprintf(out, "// %s\n", (char *)it->data);
}
g_slist_free(q->warnings);
q->warnings = NULL;
}

fprintf(out, " \"results\": {\n");
fprintf(out, " \"bindings\":[");
fs_row *row;
Expand Down Expand Up @@ -1387,16 +1378,32 @@ static void output_json(fs_query *q, int flags, FILE *out)
if (rownum) {
fputs("\n ", out);
}
fprintf(out, "]\n }\n}\n");
fprintf(out, "]\n }");

if (q->warnings) {
fprintf(out, ",\n \"warnings\": [");
GSList *it;
int count = 0;
for (it = q->warnings; it; it = it->next) {
fprintf(out, "// %s\n", (char *)it->data);
if (count++) {
printf(", ");
}
char *text = it->data;
char *escd = NULL;
int esclen = 0;
if (json_needs_escape(text, &esclen)) {
escd = json_escape(text, esclen);
text = escd;
}
fprintf(out, "\"%s\"", text);
if (escd) free(escd);
}
g_slist_free(q->warnings);
q->warnings = NULL;
fprintf(out, "]\n");
}

fprintf(out, "}\n");
}

static void output_testcase(fs_query *q, int flags, FILE *out)
Expand Down

0 comments on commit a61f47c

Please sign in to comment.