提交 9c9732d0 编写于 作者: P Peter Krempa

util: json: Introduce virJSONValueObjectAppendStringPrintf

Add a variant similar to virJSONValueObjectAppendString which also
formats more complex value strings with printf syntax.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
上级 003f063d
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册