diff --git a/lib/wp/spa-json.c b/lib/wp/spa-json.c index cc76d960..193d1051 100644 --- a/lib/wp/spa-json.c +++ b/lib/wp/spa-json.c @@ -170,11 +170,26 @@ wp_spa_json_new (const gchar *data, size_t size) */ WpSpaJson * wp_spa_json_new_from_string (const gchar *json_str) +{ + return wp_spa_json_new_from_stringn(json_str, strlen (json_str)); +} + +/*! + * \brief Constructs a new WpSpaJson from a JSON string with specific length. + * + * \ingroup wpspajson + * \param json_str a JSON string + * \param len the specific length of the string + * \returns a new WpSpaJson that references the data in \a json_str. \a json_str + * is not copied, so it needs to stay alive. + */ +WpSpaJson * +wp_spa_json_new_from_stringn (const gchar *json_str, size_t len) { WpSpaJson *self = g_slice_new0 (WpSpaJson); g_ref_count_init (&self->ref); self->flags = FLAG_NO_OWNERSHIP; - spa_json_init (&self->json_data, json_str, strlen (json_str)); + spa_json_init (&self->json_data, json_str, len); self->builder = NULL; self->data = (gchar *)self->json_data.cur; self->size = self->json_data.end - self->json_data.cur; diff --git a/lib/wp/spa-json.h b/lib/wp/spa-json.h index 085ce5e6..1e51b220 100644 --- a/lib/wp/spa-json.h +++ b/lib/wp/spa-json.h @@ -37,6 +37,9 @@ void wp_spa_json_unref (WpSpaJson *self); WP_API WpSpaJson * wp_spa_json_new_from_string (const gchar *json_str); +WP_API +WpSpaJson * wp_spa_json_new_from_stringn (const gchar *json_str, size_t len); + WP_API WpSpaJson * wp_spa_json_new_wrap (struct spa_json *json);