mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
util: introduce virBufferTrimLen
Just like the existing virBufferTrim, but only does one thing at a time. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
e092daacee
commit
080405540a
@ -1646,6 +1646,7 @@ virBufferStrcat;
|
|||||||
virBufferStrcatVArgs;
|
virBufferStrcatVArgs;
|
||||||
virBufferTrim;
|
virBufferTrim;
|
||||||
virBufferTrimChars;
|
virBufferTrimChars;
|
||||||
|
virBufferTrimLen;
|
||||||
virBufferURIEncodeString;
|
virBufferURIEncodeString;
|
||||||
virBufferUse;
|
virBufferUse;
|
||||||
virBufferVasprintf;
|
virBufferVasprintf;
|
||||||
|
@ -700,6 +700,25 @@ virBufferTrimChars(virBufferPtr buf, const char *trim)
|
|||||||
g_string_truncate(buf->str, i + 1);
|
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:
|
* virBufferAddStr:
|
||||||
* @buf: the buffer to append to
|
* @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 virBufferTrim(virBufferPtr buf, const char *trim, int len);
|
||||||
void virBufferTrimChars(virBufferPtr buf, const char *trim);
|
void virBufferTrimChars(virBufferPtr buf, const char *trim);
|
||||||
|
void virBufferTrimLen(virBufferPtr buf, int len);
|
||||||
void virBufferAddStr(virBufferPtr buf, const char *str);
|
void virBufferAddStr(virBufferPtr buf, const char *str);
|
||||||
|
Loading…
Reference in New Issue
Block a user