]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virJSONValueObjectAddVArgs: Add 'k' convertor for formatting non-negative integers
authorPeter Krempa <pkrempa@redhat.com>
Tue, 5 Oct 2021 12:07:31 +0000 (14:07 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Oct 2021 08:25:59 +0000 (10:25 +0200)
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>
src/util/virjson.c

index 9adcea4fff6e89e245768d16782a7f73f91ccb3a..26491bd6c73801a1fa3a32dbd99408b2820df67b 100644 (file)
@@ -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;