提交 08040554 编写于 作者: J Ján Tomko

util: introduce virBufferTrimLen

Just like the existing virBufferTrim, but only
does one thing at a time.
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NPeter Krempa <pkrempa@redhat.com>
上级 e092daac
......@@ -1646,6 +1646,7 @@ virBufferStrcat;
virBufferStrcatVArgs;
virBufferTrim;
virBufferTrimChars;
virBufferTrimLen;
virBufferURIEncodeString;
virBufferUse;
virBufferVasprintf;
......
......@@ -700,6 +700,25 @@ virBufferTrimChars(virBufferPtr buf, const char *trim)
g_string_truncate(buf->str, i + 1);
}
/**
* virBufferTrimLen:
* @buf: the buffer to trim
* @len: the number of bytes to trim
*
* Trim the tail of a buffer.
*/
void
virBufferTrimLen(virBufferPtr buf, int len)
{
if (!buf || !buf->str)
return;
if (len > buf->str->len)
return;
g_string_truncate(buf->str, buf->str->len - len);
}
/**
* virBufferAddStr:
* @buf: the buffer to append to
......
......@@ -93,4 +93,5 @@ size_t virBufferGetEffectiveIndent(const virBuffer *buf);
void virBufferTrim(virBufferPtr buf, const char *trim, int len);
void virBufferTrimChars(virBufferPtr buf, const char *trim);
void virBufferTrimLen(virBufferPtr buf, int len);
void virBufferAddStr(virBufferPtr buf, const char *str);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册