mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +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;
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user