git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
0a60ab38e237e3e10af3ef98de90224b692c40d5 blob 4000 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
 
#ifndef JSON_WRITER_H
#define JSON_WRITER_H

/*
 * JSON data structures are defined at:
 *      http://json.org/
 *      http://www.ietf.org/rfc/rfc7159.txt
 *
 * The JSON-writer API allows one to build JSON data structures using a
 * "struct strbuf" buffer.  This is intended as a simple API to build
 * output strings; it is not intended to be a general object model for
 * JSON data.
 *
 * All string values (both keys and string r-values) are properly quoted
 * and escaped if they contain special characters.
 *
 * These routines create compact JSON data (with no unnecessary whitespace,
 * newlines, or indenting).
 *
 * Both "JSON objects" (aka sets of k/v pairs) and "JSON array" can be
 * constructed using a 'begin append* end' model.
 *
 * Example JSON Object Usage:
 *
 *      struct strbuf obj1 = STRBUF_INIT;
 *
 *      jw_object_begin(&obj1);
 *          jw_object_append_string(&obj1, "a", "abc");
 *          jw_object_append_int(&obj1, "b", 42);
 *          jw_object_append_true(&obj1, "c");
 *      jw_object_end(&obj1);
 *
 *      printf("%s\n", obj1.buf);
 *
 * Should yield:   
 *
 *      {"a":"abc","b":42,"c":true}
 *
 * Example JSON Array Usage:
 *
 *      struct strbuf arr1 = STRBUF_INIT;
 *
 *      jw_array_begin(&arr1);
 *          jw_array_append_string(&arr1, "abc");
 *          jw_array_append_int(&arr1, 42);
 *          jw_array_append_true(&arr1);
 *      jw_array_end(&arr1);
 *
 *      printf("%s\n", arr1.buf);
 *
 * Should yield:
 *
 *      ["abc",42,true]
 *
 * Nested JSON structures are also supported.  These should be composed bottom
 * up using multiple strbuf variables.
 *
 * Example Nested Usage (using the above "obj1" and "arr1" variables):
 *
 *       struct strbuf obj2 = STRBUF_INIT;
 *
 *       jw_object_begin(&obj2);
 *           jw_object_append_object(&obj2, "obj1", obj1.buf);
 *           jw_object_append_array(&obj2, "arr1", arr1.buf);
 *       jw_object_end(&obj2);
 *
 *       printf("%s\n", obj2.buf);
 *
 * Should yield:
 *
 *       {"obj1":{"a":"abc","b":42,"c":true},"arr1":["abc",42,true]}
 *
 * And:
 *
 *       struct strbuf arr2 = STRBUF_INIT;
 *
 *       jw_array_begin(&arr2);
 *           jw_array_append_object(&arr2, obj1.buf);
 *           jw_array_append_array(&arr2, arr1.buf);
 *       jw_array_end(&arr2);
 *
 *       printf("%s\n", arr2.buf);
 *
 * Should yield:
 *
 *       [{"a":"abc","b":42,"c":true},["abc",42,true]]
 *
 */

void jw_object_begin(struct strbuf *out);
void jw_object_append_string(struct strbuf *out, const char *key,
			     const char *value);
void jw_object_append_int(struct strbuf *out, const char *key, int value);
void jw_object_append_uint64(struct strbuf *out, const char *key,
			     uint64_t value);
void jw_object_append_double(struct strbuf *out, const char *key, double value);
void jw_object_append_true(struct strbuf *out, const char *key);
void jw_object_append_false(struct strbuf *out, const char *key);
void jw_object_append_null(struct strbuf *out, const char *key);
void jw_object_append_object(struct strbuf *out, const char *key,
			     const char *value);
void jw_object_append_array(struct strbuf *out, const char *key,
			    const char *value);
void jw_object_end(struct strbuf *out);

void jw_array_begin(struct strbuf *out);
void jw_array_append_string(struct strbuf *out, const char *elem);
void jw_array_append_int(struct strbuf *out, int elem);
void jw_array_append_uint64(struct strbuf *out, uint64_t elem);
void jw_array_append_double(struct strbuf *out, double elem);
void jw_array_append_true(struct strbuf *out);
void jw_array_append_false(struct strbuf *out);
void jw_array_append_null(struct strbuf *out);
void jw_array_append_object(struct strbuf *out, const char *obj);
void jw_array_append_array(struct strbuf *out, const char *array);
void jw_array_append_argc_argv(struct strbuf *out, int argc, const char **argv);
void jw_array_append_argv(struct strbuf *out, const char **argv);
void jw_array_end(struct strbuf *out);

#endif /* JSON_WRITER_H */
debug log:

solving 0a60ab3 ...
found 0a60ab3 in https://public-inbox.org/git/20180316194057.77513-2-git@jeffhostetler.com/

applying [1/1] https://public-inbox.org/git/20180316194057.77513-2-git@jeffhostetler.com/
diff --git a/json-writer.h b/json-writer.h
new file mode 100644
index 0000000..0a60ab3

1:41: trailing whitespace.
 * Should yield:   
Checking patch json-writer.h...
Applied patch json-writer.h cleanly.
warning: 1 line adds whitespace errors.

index at:
100644 0a60ab38e237e3e10af3ef98de90224b692c40d5	json-writer.h

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).