1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

json: add new json_variant_is_blank_{object,array}() helpers

This commit is contained in:
Lennart Poettering 2019-07-04 17:38:17 +02:00
parent 07737617a1
commit e787b211a5
2 changed files with 15 additions and 0 deletions

View File

@ -946,6 +946,19 @@ mismatch:
return false;
}
bool json_variant_is_blank_object(JsonVariant *v) {
/* Returns true if the specified object is null or empty */
return !v ||
json_variant_is_null(v) ||
(json_variant_is_object(v) && json_variant_elements(v) == 0);
}
bool json_variant_is_blank_array(JsonVariant *v) {
return !v ||
json_variant_is_null(v) ||
(json_variant_is_array(v) && json_variant_elements(v) == 0);
}
JsonVariantType json_variant_type(JsonVariant *v) {
if (!v)

View File

@ -120,6 +120,8 @@ static inline bool json_variant_is_null(JsonVariant *v) {
}
bool json_variant_is_negative(JsonVariant *v);
bool json_variant_is_blank_object(JsonVariant *v);
bool json_variant_is_blank_array(JsonVariant *v);
size_t json_variant_elements(JsonVariant *v);
JsonVariant *json_variant_by_index(JsonVariant *v, size_t index);