git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
755ff80599636340863ff232e5a70bf5658f83ef blob 4543 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
 
#include "cache.h"
#include "json-writer.h"

/*
 * Append JSON-quoted version of the given string to 'out'.
 */
static void jw_append_quoted_string(struct strbuf *out, const char *in)
{
	strbuf_addch(out, '"');
	for (/**/; *in; in++) {
		unsigned char c = (unsigned char)*in;
		if (c == '"')
			strbuf_add(out, "\\\"", 2);
		else if (c == '\\')
			strbuf_add(out, "\\\\", 2);
		else if (c == '\n')
			strbuf_add(out, "\\n", 2);
		else if (c == '\r')
			strbuf_add(out, "\\r", 2);
		else if (c == '\t')
			strbuf_add(out, "\\t", 2);
		else if (c == '\f')
			strbuf_add(out, "\\f", 2);
		else if (c == '\b')
			strbuf_add(out, "\\b", 2);
		else if (c < 0x20)
			strbuf_addf(out, "\\u%04x", c);
		else
			strbuf_addch(out, c);
	}
	strbuf_addch(out, '"');
}

void jw_object_begin(struct strbuf *out)
{
	strbuf_reset(out);
	strbuf_addch(out, '{');
}

void jw_object_append_string(struct strbuf *out, const char *key,
			     const char *value)
{
	if (out->len > 1)
		strbuf_addch(out, ',');

	jw_append_quoted_string(out, key);
	strbuf_addch(out, ':');
	jw_append_quoted_string(out, value);
}

void jw_object_append_int(struct strbuf *out, const char *key, int value)
{
	if (out->len > 1)
		strbuf_addch(out, ',');

	jw_append_quoted_string(out, key);
	strbuf_addf(out, ":%d", value);
}

void jw_object_append_uint64(struct strbuf *out, const char *key, uint64_t value)
{
	if (out->len > 1)
		strbuf_addch(out, ',');

	jw_append_quoted_string(out, key);
	strbuf_addf(out, ":%"PRIuMAX, value);
}

void jw_object_append_double(struct strbuf *out, const char *key, double value)
{
	if (out->len > 1)
		strbuf_addch(out, ',');

	jw_append_quoted_string(out, key);
	strbuf_addf(out, ":%f", value);
}

void jw_object_append_true(struct strbuf *out, const char *key)
{
	if (out->len > 1)
		strbuf_addch(out, ',');

	jw_append_quoted_string(out, key);
	strbuf_addstr(out, ":true");
}

void jw_object_append_false(struct strbuf *out, const char *key)
{
	if (out->len > 1)
		strbuf_addch(out, ',');

	jw_append_quoted_string(out, key);
	strbuf_addstr(out, ":false");
}

void jw_object_append_null(struct strbuf *out, const char *key)
{
	if (out->len > 1)
		strbuf_addch(out, ',');

	jw_append_quoted_string(out, key);
	strbuf_addstr(out, ":null");
}

void jw_object_append_object(struct strbuf *out, const char *key,
			     const char *value)
{
	if (out->len > 1)
		strbuf_addch(out, ',');

	jw_append_quoted_string(out, key);
	strbuf_addch(out, ':');
	strbuf_addstr(out, value);
}

void jw_object_append_array(struct strbuf *out, const char *key,
			    const char *value)
{
	if (out->len > 1)
		strbuf_addch(out, ',');

	jw_append_quoted_string(out, key);
	strbuf_addch(out, ':');
	strbuf_addstr(out, value);
}

void jw_object_end(struct strbuf *out)
{
	strbuf_addch(out, '}');
}

void jw_array_begin(struct strbuf *out)
{
	strbuf_reset(out);
	strbuf_addch(out, '[');
}

void jw_array_append_string(struct strbuf *out, const char *elem)
{
	struct strbuf qe = STRBUF_INIT;

	jw_append_quoted_string(&qe, elem);

	if (out->len > 1)
		strbuf_addch(out, ',');
	strbuf_addstr(out, qe.buf);

	strbuf_release(&qe);
}

void jw_array_append_int(struct strbuf *out, int elem)
{
	if (out->len > 1)
		strbuf_addch(out, ',');
	strbuf_addf(out, "%d", elem);
}

void jw_array_append_uint64(struct strbuf *out, uint64_t elem)
{
	if (out->len > 1)
		strbuf_addch(out, ',');
	strbuf_addf(out, "%"PRIuMAX, elem);
}

void jw_array_append_double(struct strbuf *out, double elem)
{
	if (out->len > 1)
		strbuf_addch(out, ',');
	strbuf_addf(out, "%f", elem);
}

void jw_array_append_true(struct strbuf *out)
{
	if (out->len > 1)
		strbuf_addch(out, ',');
	strbuf_addstr(out, "true");
}

void jw_array_append_false(struct strbuf *out)
{
	if (out->len > 1)
		strbuf_addch(out, ',');
	strbuf_addstr(out, "false");
}

void jw_array_append_null(struct strbuf *out)
{
	if (out->len > 1)
		strbuf_addch(out, ',');
	strbuf_addstr(out, "null");
}

void jw_array_append_object(struct strbuf *out, const char *obj)
{
	if (out->len > 1)
		strbuf_addch(out, ',');
	strbuf_addstr(out, obj);
}

void jw_array_append_array(struct strbuf *out, const char *array)
{
	if (out->len > 1)
		strbuf_addch(out, ',');
	strbuf_addstr(out, array);
}

void jw_array_append_argc_argv(struct strbuf *out, int argc, const char **argv)
{
	int k;

	for (k = 0; k < argc; k++)
		jw_array_append_string(out, argv[k]);
}

void jw_array_append_argv(struct strbuf *out, const char **argv)
{
	while (*argv)
		jw_array_append_string(out, *argv++);
}

void jw_array_end(struct strbuf *out)
{
	strbuf_addch(out, ']');
}
debug log:

solving 755ff80 ...
found 755ff80 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.c b/json-writer.c
new file mode 100644
index 0000000..755ff80

Checking patch json-writer.c...
Applied patch json-writer.c cleanly.

index at:
100644 755ff80599636340863ff232e5a70bf5658f83ef	json-writer.c

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).