json: add integer parsing functions

While most numeric values used in pipewire are floating-point values, it 
can still be useful to be able to directly parse integer values.
This commit is contained in:
Arnaud Ferraris 2021-03-02 18:06:55 +01:00
parent 97cc27600a
commit 8b97416417

View file

@ -244,6 +244,27 @@ static inline int spa_json_get_float(struct spa_json *iter, float *res)
return spa_json_parse_float(value, len, res);
}
/* int */
static inline int spa_json_parse_int(const char *val, int len, int *result)
{
char *end;
*result = strtol(val, &end, 0);
return end == val + len;
}
static inline bool spa_json_is_int(const char *val, int len)
{
int dummy;
return spa_json_parse_int(val, len, &dummy);
}
static inline int spa_json_get_int(struct spa_json *iter, int *res)
{
const char *value;
int len;
if ((len = spa_json_next(iter, &value)) <= 0)
return -1;
return spa_json_parse_int(value, len, res);
}
/* bool */
static inline bool spa_json_is_true(const char *val, int len)
{