mirror of https://gitee.com/openkylin/libvirt.git
util: json: Introduce virJSONValueObjectAppendStringPrintf
Add a variant similar to virJSONValueObjectAppendString which also formats more complex value strings with printf syntax. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
003f063dd6
commit
9c9732d03a
|
@ -2361,6 +2361,7 @@ virJSONValueObjectAppendNumberLong;
|
|||
virJSONValueObjectAppendNumberUint;
|
||||
virJSONValueObjectAppendNumberUlong;
|
||||
virJSONValueObjectAppendString;
|
||||
virJSONValueObjectAppendStringPrintf;
|
||||
virJSONValueObjectCreate;
|
||||
virJSONValueObjectCreateVArgs;
|
||||
virJSONValueObjectDeflatten;
|
||||
|
|
|
@ -649,6 +649,23 @@ virJSONValueObjectAppendString(virJSONValuePtr object,
|
|||
}
|
||||
|
||||
|
||||
int
|
||||
virJSONValueObjectAppendStringPrintf(virJSONValuePtr object,
|
||||
const char *key,
|
||||
const char *fmt,
|
||||
...)
|
||||
{
|
||||
va_list ap;
|
||||
g_autofree char *str = NULL;
|
||||
|
||||
va_start(ap, fmt);
|
||||
str = g_strdup_vprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return virJSONValueObjectInsertString(object, key, str, false);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virJSONValueObjectPrependString(virJSONValuePtr object,
|
||||
const char *key,
|
||||
|
|
|
@ -127,6 +127,8 @@ int virJSONValueObjectGetBoolean(virJSONValuePtr object, const char *key, bool *
|
|||
int virJSONValueObjectIsNull(virJSONValuePtr object, const char *key);
|
||||
|
||||
int virJSONValueObjectAppendString(virJSONValuePtr object, const char *key, const char *value);
|
||||
int virJSONValueObjectAppendStringPrintf(virJSONValuePtr object, const char *key, const char *fmt, ...)
|
||||
G_GNUC_PRINTF(3, 4);
|
||||
int virJSONValueObjectPrependString(virJSONValuePtr object, const char *key, const char *value);
|
||||
int virJSONValueObjectAppendNumberInt(virJSONValuePtr object, const char *key, int number);
|
||||
int virJSONValueObjectAppendNumberUint(virJSONValuePtr object, const char *key, unsigned int number);
|
||||
|
|
Loading…
Reference in New Issue