mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
properties: support properties from json object sting
Make pw_properties_new_string() work with a json object string. This makes it possible to specify property strings as more complex objects and escape characters.
This commit is contained in:
parent
62cdec8448
commit
6e4c138238
3 changed files with 96 additions and 20 deletions
|
|
@ -33,7 +33,9 @@ extern "C" {
|
|||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <spa/utils/defs.h>
|
||||
|
||||
/* a simple JSON compatible tokenizer */
|
||||
struct spa_json {
|
||||
|
|
@ -169,6 +171,20 @@ static inline int spa_json_enter_container(struct spa_json *iter, struct spa_jso
|
|||
return 1;
|
||||
}
|
||||
|
||||
static inline int spa_json_is_container(const char *val, int len)
|
||||
{
|
||||
return len > 0 && (*val == '{' || *val == '[');
|
||||
}
|
||||
|
||||
static inline int spa_json_container_len(struct spa_json *iter, const char *value, int len)
|
||||
{
|
||||
const char *val;
|
||||
struct spa_json sub;
|
||||
spa_json_enter(iter, &sub);
|
||||
while (spa_json_next(&sub, &val) > 0);
|
||||
return sub.cur + 1 - value;
|
||||
}
|
||||
|
||||
/* object */
|
||||
static inline int spa_json_is_object(const char *val, int len)
|
||||
{
|
||||
|
|
@ -321,6 +337,7 @@ static inline int spa_json_encode_string(char *str, int size, const char *val)
|
|||
}
|
||||
__PUT('"');
|
||||
__PUT('\0');
|
||||
#undef __PUT
|
||||
return len-1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue