mrp_json_t *o;
const char *s;
bool b;
- int i;
+ int i, l;
double d;
va_list ap;
switch (type) {
case MRP_JSON_STRING:
s = va_arg(ap, const char *);
- o = json_object_new_string(s);
+ l = va_arg(ap, int);
+ if (l < 0)
+ o = json_object_new_string(s);
+ else
+ o = json_object_new_string_len(s, l);
break;
case MRP_JSON_BOOLEAN:
b = va_arg(ap, int);
mrp_json_t *m;
const char *s;
bool b;
- int i;
+ int i, l;
double d;
va_list ap;
switch (type) {
case MRP_JSON_STRING:
s = va_arg(ap, const char *);
- m = json_object_new_string(s);
+ l = va_arg(ap, int);
+ if (l < 0)
+ m = json_object_new_string(s);
+ else
+ m = json_object_new_string_len(s, l);
break;
case MRP_JSON_BOOLEAN:
b = va_arg(ap, int);
mrp_json_t *v;
const char *s;
bool b;
- int i;
+ int i, l;
double d;
va_list ap;
switch (type) {
case MRP_JSON_STRING:
s = va_arg(ap, const char *);
- v = json_object_new_string(s);
+ l = va_arg(ap, int);
+ if (l < 0)
+ v = json_object_new_string(s);
+ else
+ v = json_object_new_string_len(s, l);
break;
case MRP_JSON_BOOLEAN:
b = va_arg(ap, int);
mrp_json_t *v;
const char *s;
bool b;
- int i;
+ int i, l;
double d;
va_list ap;
switch (type) {
case MRP_JSON_STRING:
s = va_arg(ap, const char *);
- v = json_object_new_string(s);
+ l = va_arg(ap, int);
+ if (l < 0)
+ v = json_object_new_string(s);
+ else
+ v = json_object_new_string_len(s, l);
break;
case MRP_JSON_BOOLEAN:
b = va_arg(ap, int);
/** Convenience macros to add members of various basic types. */
#define mrp_json_add_string(o, key, s) \
- mrp_json_add_member(o, key, MRP_JSON_STRING, s)
+ mrp_json_add_member(o, key, MRP_JSON_STRING, s, -1)
+
+#define mrp_json_add_string_slice(o, key, s, l) \
+ mrp_json_add_member(o, key, MRP_JSON_STRING, s, l)
#define mrp_json_add_integer(o, key, i) \
mrp_json_add_member(o, key, MRP_JSON_INTEGER, i)
/** Convenience macros for appending array items of basic types. */
#define mrp_json_array_append_string(a, s) \
- mrp_json_array_append_item(a, MRP_JSON_STRING, s)
+ mrp_json_array_append_item(a, MRP_JSON_STRING, s, -1)
+
+#define mrp_json_array_append_string_slice(a, s, l) \
+ mrp_json_array_append_item(a, MRP_JSON_STRING, s, l)
+
#define mrp_json_array_append_integer(a, i) \
mrp_json_array_append_item(a, MRP_JSON_INTEGER, (int)i)