]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: introduce virBufferTrimLen
authorJán Tomko <jtomko@redhat.com>
Sun, 2 Feb 2020 19:16:36 +0000 (20:16 +0100)
committerJán Tomko <jtomko@redhat.com>
Mon, 3 Feb 2020 18:44:38 +0000 (19:44 +0100)
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>
src/libvirt_private.syms
src/util/virbuffer.c
src/util/virbuffer.h

index ebf830791e7cba4b906d67dd6c9b59a4828c56d8..7dfb2458eb31e446a052c07ebf66f0e533919e5e 100644 (file)
@@ -1646,6 +1646,7 @@ virBufferStrcat;
 virBufferStrcatVArgs;
 virBufferTrim;
 virBufferTrimChars;
+virBufferTrimLen;
 virBufferURIEncodeString;
 virBufferUse;
 virBufferVasprintf;
index 914c386b187b61a66a8833e00206f611f55d605e..b76d99b56f7edde025acb95a1a9d74ade32e9f5c 100644 (file)
@@ -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
index 183f78f279359c4a29f1378997ba1a2a01d59cd4..7b068075b278ac1300ae3e80eafd2594632f9b99 100644 (file)
@@ -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);