From: Karel Zak Date: Fri, 5 Jun 2015 09:58:42 +0000 (+0200) Subject: libsmartcols: keep JSON field names lower-case X-Git-Tag: v2.27-rc1~169 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a768b55165f8b09bf95fc018b771261ddf64084;p=thirdparty%2Futil-linux.git libsmartcols: keep JSON field names lower-case Signed-off-by: Karel Zak --- diff --git a/include/carefulputc.h b/include/carefulputc.h index 3a0ec5b669..681e666602 100644 --- a/include/carefulputc.h +++ b/include/carefulputc.h @@ -26,7 +26,7 @@ static inline int fputc_careful(int c, FILE *fp, const char fail) return (ret < 0) ? EOF : 0; } -static inline void fputs_quoted(const char *data, FILE *out) +static inline void fputs_quoted_case(const char *data, FILE *out, int dir) { const char *p; @@ -41,11 +41,17 @@ static inline void fputs_quoted(const char *data, FILE *out) fprintf(out, "\\x%02x", (unsigned char) *p); } else - fputc(*p, out); + fputc(dir == 1 ? toupper(*p) : + dir == -1 ? tolower(*p) : + *p, out); } fputc('"', out); } +#define fputs_quoted(_d, _o) fputs_quoted_case(_d, _o, 0) +#define fputs_quoted_upper(_d, _o) fputs_quoted_case(_d, _o, 1) +#define fputs_quoted_lower(_d, _o) fputs_quoted_case(_d, _o, -1) + static inline void fputs_nonblank(const char *data, FILE *out) { const char *p; diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index 731879cae6..c743bf7bd2 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -284,7 +284,7 @@ static int print_data(struct libscols_table *tb, return 0; case SCOLS_FMT_JSON: - fputs_quoted(scols_cell_get_data(&cl->header), tb->out); + fputs_quoted_lower(scols_cell_get_data(&cl->header), tb->out); fputs(": ", tb->out); if (!data || !*data) fputs("null", tb->out);