Lines Matching full:self

29 static void jsonw_indent(json_writer_t *self)  in jsonw_indent()  argument
32 for (i = 0; i < self->depth; ++i) in jsonw_indent()
33 fputs(" ", self->out); in jsonw_indent()
37 static void jsonw_eol(json_writer_t *self) in jsonw_eol() argument
39 if (!self->pretty) in jsonw_eol()
42 putc('\n', self->out); in jsonw_eol()
43 jsonw_indent(self); in jsonw_eol()
47 static void jsonw_eor(json_writer_t *self) in jsonw_eor() argument
49 if (self->sep != '\0') in jsonw_eor()
50 putc(self->sep, self->out); in jsonw_eor()
51 self->sep = ','; in jsonw_eor()
57 static void jsonw_puts(json_writer_t *self, const char *str) in jsonw_puts() argument
59 putc('"', self->out); in jsonw_puts()
63 fputs("\\t", self->out); in jsonw_puts()
66 fputs("\\n", self->out); in jsonw_puts()
69 fputs("\\r", self->out); in jsonw_puts()
72 fputs("\\f", self->out); in jsonw_puts()
75 fputs("\\b", self->out); in jsonw_puts()
78 fputs("\\\\", self->out); in jsonw_puts()
81 fputs("\\\"", self->out); in jsonw_puts()
84 putc(*str, self->out); in jsonw_puts()
86 putc('"', self->out); in jsonw_puts()
92 json_writer_t *self = malloc(sizeof(*self)); in jsonw_new() local
93 if (self) { in jsonw_new()
94 self->out = f; in jsonw_new()
95 self->depth = 0; in jsonw_new()
96 self->pretty = false; in jsonw_new()
97 self->sep = '\0'; in jsonw_new()
99 return self; in jsonw_new()
105 json_writer_t *self = *self_p; in jsonw_destroy() local
107 assert(self->depth == 0); in jsonw_destroy()
108 fputs("\n", self->out); in jsonw_destroy()
109 fflush(self->out); in jsonw_destroy()
110 free(self); in jsonw_destroy()
114 void jsonw_pretty(json_writer_t *self, bool on) in jsonw_pretty() argument
116 self->pretty = on; in jsonw_pretty()
119 void jsonw_reset(json_writer_t *self) in jsonw_reset() argument
121 assert(self->depth == 0); in jsonw_reset()
122 self->sep = '\0'; in jsonw_reset()
126 static void jsonw_begin(json_writer_t *self, int c) in jsonw_begin() argument
128 jsonw_eor(self); in jsonw_begin()
129 putc(c, self->out); in jsonw_begin()
130 ++self->depth; in jsonw_begin()
131 self->sep = '\0'; in jsonw_begin()
134 static void jsonw_end(json_writer_t *self, int c) in jsonw_end() argument
136 assert(self->depth > 0); in jsonw_end()
138 --self->depth; in jsonw_end()
139 if (self->sep != '\0') in jsonw_end()
140 jsonw_eol(self); in jsonw_end()
141 putc(c, self->out); in jsonw_end()
142 self->sep = ','; in jsonw_end()
147 void jsonw_name(json_writer_t *self, const char *name) in jsonw_name() argument
149 jsonw_eor(self); in jsonw_name()
150 jsonw_eol(self); in jsonw_name()
151 self->sep = '\0'; in jsonw_name()
152 jsonw_puts(self, name); in jsonw_name()
153 putc(':', self->out); in jsonw_name()
154 if (self->pretty) in jsonw_name()
155 putc(' ', self->out); in jsonw_name()
158 void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap) in jsonw_vprintf_enquote() argument
160 jsonw_eor(self); in jsonw_vprintf_enquote()
161 putc('"', self->out); in jsonw_vprintf_enquote()
162 vfprintf(self->out, fmt, ap); in jsonw_vprintf_enquote()
163 putc('"', self->out); in jsonw_vprintf_enquote()
166 void jsonw_printf(json_writer_t *self, const char *fmt, ...) in jsonw_printf() argument
171 jsonw_eor(self); in jsonw_printf()
172 vfprintf(self->out, fmt, ap); in jsonw_printf()
177 void jsonw_start_object(json_writer_t *self) in jsonw_start_object() argument
179 jsonw_begin(self, '{'); in jsonw_start_object()
182 void jsonw_end_object(json_writer_t *self) in jsonw_end_object() argument
184 jsonw_end(self, '}'); in jsonw_end_object()
187 void jsonw_start_array(json_writer_t *self) in jsonw_start_array() argument
189 jsonw_begin(self, '['); in jsonw_start_array()
192 void jsonw_end_array(json_writer_t *self) in jsonw_end_array() argument
194 jsonw_end(self, ']'); in jsonw_end_array()
198 void jsonw_string(json_writer_t *self, const char *value) in jsonw_string() argument
200 jsonw_eor(self); in jsonw_string()
201 jsonw_puts(self, value); in jsonw_string()
204 void jsonw_bool(json_writer_t *self, bool val) in jsonw_bool() argument
206 jsonw_printf(self, "%s", val ? "true" : "false"); in jsonw_bool()
209 void jsonw_null(json_writer_t *self) in jsonw_null() argument
211 jsonw_printf(self, "null"); in jsonw_null()
214 void jsonw_float_fmt(json_writer_t *self, const char *fmt, double num) in jsonw_float_fmt() argument
216 jsonw_printf(self, fmt, num); in jsonw_float_fmt()
220 void jsonw_float(json_writer_t *self, double num) in jsonw_float() argument
222 jsonw_printf(self, "%g", num); in jsonw_float()
226 void jsonw_hu(json_writer_t *self, unsigned short num) in jsonw_hu() argument
228 jsonw_printf(self, "%hu", num); in jsonw_hu()
231 void jsonw_uint(json_writer_t *self, uint64_t num) in jsonw_uint() argument
233 jsonw_printf(self, "%"PRIu64, num); in jsonw_uint()
236 void jsonw_lluint(json_writer_t *self, unsigned long long int num) in jsonw_lluint() argument
238 jsonw_printf(self, "%llu", num); in jsonw_lluint()
241 void jsonw_int(json_writer_t *self, int64_t num) in jsonw_int() argument
243 jsonw_printf(self, "%"PRId64, num); in jsonw_int()
247 void jsonw_string_field(json_writer_t *self, const char *prop, const char *val) in jsonw_string_field() argument
249 jsonw_name(self, prop); in jsonw_string_field()
250 jsonw_string(self, val); in jsonw_string_field()
253 void jsonw_bool_field(json_writer_t *self, const char *prop, bool val) in jsonw_bool_field() argument
255 jsonw_name(self, prop); in jsonw_bool_field()
256 jsonw_bool(self, val); in jsonw_bool_field()
260 void jsonw_float_field(json_writer_t *self, const char *prop, double val) in jsonw_float_field() argument
262 jsonw_name(self, prop); in jsonw_float_field()
263 jsonw_float(self, val); in jsonw_float_field()
267 void jsonw_float_field_fmt(json_writer_t *self, in jsonw_float_field_fmt() argument
272 jsonw_name(self, prop); in jsonw_float_field_fmt()
273 jsonw_float_fmt(self, fmt, val); in jsonw_float_field_fmt()
276 void jsonw_uint_field(json_writer_t *self, const char *prop, uint64_t num) in jsonw_uint_field() argument
278 jsonw_name(self, prop); in jsonw_uint_field()
279 jsonw_uint(self, num); in jsonw_uint_field()
282 void jsonw_hu_field(json_writer_t *self, const char *prop, unsigned short num) in jsonw_hu_field() argument
284 jsonw_name(self, prop); in jsonw_hu_field()
285 jsonw_hu(self, num); in jsonw_hu_field()
288 void jsonw_lluint_field(json_writer_t *self, in jsonw_lluint_field() argument
292 jsonw_name(self, prop); in jsonw_lluint_field()
293 jsonw_lluint(self, num); in jsonw_lluint_field()
296 void jsonw_int_field(json_writer_t *self, const char *prop, int64_t num) in jsonw_int_field() argument
298 jsonw_name(self, prop); in jsonw_int_field()
299 jsonw_int(self, num); in jsonw_int_field()
302 void jsonw_null_field(json_writer_t *self, const char *prop) in jsonw_null_field() argument
304 jsonw_name(self, prop); in jsonw_null_field()
305 jsonw_null(self); in jsonw_null_field()