--- a/src/cx/json.h Sat Nov 02 19:27:45 2024 +0100 +++ b/src/cx/json.h Sat Nov 02 19:37:59 2024 +0100 @@ -180,7 +180,39 @@ void cxJsonDestroy(CxJson *json); __attribute__((__nonnull__)) -void cxJsonFill(CxJson *json, const char *buf, size_t len); +int cxJsonFilln(CxJson *json, const char *buf, size_t len); + +#define cxJsonFill(prop, str) _Generic((str), \ + cxstring: cx_json_fill_cxstr, \ + cxmutstr: cx_json_fill_mutstr, \ + char*: cx_json_fill_str, \ + const char*: cx_json_fill_str) \ + (prop, str) + +__attribute__((__nonnull__)) +static inline int cx_json_fill_cxstr( + CxJson *json, + cxstring str +) { + return cxJsonFilln(json, str.ptr, str.length); +} + +__attribute__((__nonnull__)) +static inline int cx_json_fill_mutstr( + CxJson *json, + cxmutstr str +) { + return cxJsonFilln(json, str.ptr, str.length); +} + +__attribute__((__nonnull__)) +static inline int cx_json_fill_str( + CxJson *json, + const char *str +) { + return cxJsonFilln(json, str, strlen(str)); +} + __attribute__((__nonnull__)) int cxJsonNext(CxJson *json, CxJsonValue **value);