mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-04-01 20:05:19 +00:00
virJSONValueObjectAddVArgs: Add 'k' convertor for formatting non-negative integers
In many cases we use a signed value, but use the sign to note that it was not assigned. For converting to JSON objects it will be handy to have possibility to do this automatically. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
618e8665db
commit
eb5b7722ea
@ -115,6 +115,7 @@ virJSONValueGetType(const virJSONValue *value)
|
||||
*
|
||||
* i: signed integer value
|
||||
* j: signed integer value, error if negative
|
||||
* k: signed integer value, omitted if negative
|
||||
* z: signed integer value, omitted if zero
|
||||
* y: signed integer value, omitted if zero, error if negative
|
||||
*
|
||||
@ -189,6 +190,7 @@ virJSONValueObjectAddVArgs(virJSONValue *obj,
|
||||
|
||||
case 'z':
|
||||
case 'y':
|
||||
case 'k':
|
||||
case 'j':
|
||||
case 'i': {
|
||||
int val = va_arg(args, int);
|
||||
@ -203,6 +205,9 @@ virJSONValueObjectAddVArgs(virJSONValue *obj,
|
||||
if (!val && (type == 'z' || type == 'y'))
|
||||
continue;
|
||||
|
||||
if (val < 0 && type == 'k')
|
||||
continue;
|
||||
|
||||
rc = virJSONValueObjectAppendNumberInt(obj, key, val);
|
||||
} break;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user