Skip to content

Commit 6770bfc

Browse files
lucasoshirogitster
authored andcommitted
json-writer: add docstrings to jw_* functions
Add a docstring for each function that manipulates json_writers. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 683c54c commit 6770bfc

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

json-writer.h

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,42 +69,175 @@ struct json_writer
6969
.open_stack = STRBUF_INIT, \
7070
}
7171

72+
/*
73+
* Initialize a json_writer with empty values.
74+
*/
7275
void jw_init(struct json_writer *jw);
76+
77+
/*
78+
* Release the internal buffers of a json_writer.
79+
*/
7380
void jw_release(struct json_writer *jw);
7481

82+
/*
83+
* Begin the json_writer using an object as the top-level data structure. If
84+
* pretty is set to 1, the result will be a human-readable and indented JSON,
85+
* and if it is set to 0 the result will be minified single-line JSON.
86+
*/
7587
void jw_object_begin(struct json_writer *jw, int pretty);
88+
89+
/*
90+
* Begin the json_writer using an array as the top-level data structure. If
91+
* pretty is set to 1, the result will be a human-readable and indented JSON,
92+
* and if it is set to 0 the result will be minified single-line JSON.
93+
*/
7694
void jw_array_begin(struct json_writer *jw, int pretty);
7795

96+
/*
97+
* Append a string field to the current object of the json_writer, given its key
98+
* and its value.
99+
*/
78100
void jw_object_string(struct json_writer *jw, const char *key,
79101
const char *value);
102+
103+
/*
104+
* Append an int field to the current object of the json_writer, given its key
105+
* and its value.
106+
*/
80107
void jw_object_intmax(struct json_writer *jw, const char *key, intmax_t value);
108+
109+
/*
110+
* Append a double field to the current object of the json_writer, given its key
111+
* and its value. The precision parameter can be used for specifying the number
112+
* of decimals after the point, using -1 for formatting with the maximum
113+
* precision available.
114+
*/
81115
void jw_object_double(struct json_writer *jw, const char *key, int precision,
82116
double value);
117+
118+
/*
119+
* Append a boolean field set to true to the current object of the json_writer,
120+
* given its key.
121+
*/
83122
void jw_object_true(struct json_writer *jw, const char *key);
123+
124+
/*
125+
* Append a boolean field set to false to the current object of the json_writer,
126+
* given its key.
127+
*/
84128
void jw_object_false(struct json_writer *jw, const char *key);
129+
130+
/*
131+
* Append a boolean field to the current object of the json_writer, given its
132+
* key and its value.
133+
*/
85134
void jw_object_bool(struct json_writer *jw, const char *key, int value);
135+
136+
/*
137+
* Append a null field to the current object of the json_writer, given its key.
138+
*/
86139
void jw_object_null(struct json_writer *jw, const char *key);
140+
141+
/*
142+
* Append a field to the current object of the json_writer, given its key and
143+
* another json_writer that represents its content.
144+
*/
87145
void jw_object_sub_jw(struct json_writer *jw, const char *key,
88146
const struct json_writer *value);
89147

148+
/*
149+
* Start an object as the value of a field in the current object of the
150+
* json_writer, given the field key.
151+
*/
90152
void jw_object_inline_begin_object(struct json_writer *jw, const char *key);
153+
154+
/*
155+
* Start an array as the value of a field in the current object of the
156+
* json_writer, given the field key.
157+
*/
91158
void jw_object_inline_begin_array(struct json_writer *jw, const char *key);
92159

160+
/*
161+
* Append a string value to the current array of the json_writer.
162+
*/
93163
void jw_array_string(struct json_writer *jw, const char *value);
164+
165+
/*
166+
* Append an int value to the current array of the json_writer.
167+
*/
94168
void jw_array_intmax(struct json_writer *jw, intmax_t value);
169+
170+
/*
171+
* Append a double value to the current array of the json_writer. The precision
172+
* parameter can be used for specifying the number of decimals after the point,
173+
* using -1 for formatting with the maximum precision available.
174+
*/
95175
void jw_array_double(struct json_writer *jw, int precision, double value);
176+
177+
/*
178+
* Append a true value to the current array of the json_writer.
179+
*/
96180
void jw_array_true(struct json_writer *jw);
181+
182+
/*
183+
* Append a false value to the current array of the json_writer.
184+
*/
97185
void jw_array_false(struct json_writer *jw);
186+
187+
/*
188+
* Append a boolean value to the current array of the json_writer.
189+
*/
98190
void jw_array_bool(struct json_writer *jw, int value);
191+
192+
/*
193+
* Append a null value to the current array of the json_writer.
194+
*/
99195
void jw_array_null(struct json_writer *jw);
196+
197+
/*
198+
* Append a value to the current array of the json_writer, given the
199+
* json_writer that represents its content.
200+
*/
100201
void jw_array_sub_jw(struct json_writer *jw, const struct json_writer *value);
202+
203+
/*
204+
* Append the first argc values from the argv array of strings to the current
205+
* array of the json_writer.
206+
*
207+
* This function does not provide safety for cases where the array has less than
208+
* argc values.
209+
*/
101210
void jw_array_argc_argv(struct json_writer *jw, int argc, const char **argv);
211+
212+
/*
213+
* Append a null-terminated array of strings to the current array of the
214+
* json_writer.
215+
*/
102216
void jw_array_argv(struct json_writer *jw, const char **argv);
103217

218+
/*
219+
* Start an object as a value in the current array of the json_writer.
220+
*/
104221
void jw_array_inline_begin_object(struct json_writer *jw);
222+
223+
/*
224+
* Start an array as a value in the current array.
225+
*/
105226
void jw_array_inline_begin_array(struct json_writer *jw);
106227

228+
/*
229+
* Return if the json_writer is terminated. In other words, if the all the
230+
* objects and arrays are already closed.
231+
*/
107232
int jw_is_terminated(const struct json_writer *jw);
233+
234+
/*
235+
* Terminates the current object or array of the json_writer. In other words,
236+
* append a ] if the current array is not closed or } if the current object
237+
* is not closed.
238+
*
239+
* Abort the execution if there's no object or array that can be terminated.
240+
*/
108241
void jw_end(struct json_writer *jw);
109242

110243
#endif /* JSON_WRITER_H */

0 commit comments

Comments
 (0)