Skip to content

Commit a42f311

Browse files
committed
add *_cstr* macros & funcs
1 parent 052a633 commit a42f311

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

jsonwriter.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,14 @@ int jsonwriter_bool(jsonwriter_handle data, unsigned char value) {
238238
return 1;
239239
}
240240

241+
int jsonwriter_cstr(jsonwriter_handle data, const char *s) {
242+
return jsonwriter_str(data, (const unsigned char *)s);
243+
}
244+
245+
int jsonwriter_cstrn(jsonwriter_handle data, const char *s, size_t len) {
246+
return jsonwriter_strn(data, (const unsigned char *)s, len);
247+
}
248+
241249
int jsonwriter_str(jsonwriter_handle data, const unsigned char *s) {
242250
if(data->depth < JSONWRITER_MAX_NESTING) {
243251
jsonwriter_indent(data, 0);

jsonwriter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ extern "C" {
6262

6363
int jsonwriter_object_key(jsonwriter_handle h, const char *key);
6464
#define jsonwriter_object_str(h, key, v) jsonwriter_object_key(h, key), jsonwriter_str(h, v)
65+
#define jsonwriter_object_strn(h, key, v, len) jsonwriter_object_key(h, key), jsonwriter_strn(h, v, len)
66+
#define jsonwriter_object_cstr(h, key, v) jsonwriter_object_key(h, key), jsonwriter_cstr(h, v)
67+
#define jsonwriter_object_cstrn(h, key, v, len) jsonwriter_object_key(h, key), jsonwriter_cstrn(h, v, len)
6568
#define jsonwriter_object_bool(h, key, v) jsonwriter_object_key(h, key), jsonwriter_bool(h, v)
6669
#define jsonwriter_object_dbl(h, key, v) jsonwriter_object_key(h, key), jsonwriter_dbl(h, v)
6770
#define jsonwriter_object_dblf(h, key, v, fmt, t) jsonwriter_object_key(h, key), jsonwriter_dblf(h, v, f, t)
@@ -72,6 +75,8 @@ extern "C" {
7275

7376
int jsonwriter_str(jsonwriter_handle h, const unsigned char *s);
7477
int jsonwriter_strn(jsonwriter_handle h, const unsigned char *s, size_t len);
78+
int jsonwriter_cstr(jsonwriter_handle data, const char *s);
79+
int jsonwriter_cstrn(jsonwriter_handle data, const char *s, size_t len);
7580
int jsonwriter_bool(jsonwriter_handle h, unsigned char value);
7681
int jsonwriter_dbl(jsonwriter_handle h, long double d);
7782
int jsonwriter_dblf(jsonwriter_handle h, long double d, const char *format_string, unsigned char trim_trailing_zeros_after_dec);

0 commit comments

Comments
 (0)