[libvirt PATCH 1/3] util: introduce virBufferTrimLen

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Just like the existing virBufferTrim, but only
does one thing at a time.

Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/util/virbuffer.c     | 19 +++++++++++++++++++
 src/util/virbuffer.h     |  1 +
 3 files changed, 21 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index ebf830791e..7dfb2458eb 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1646,6 +1646,7 @@ virBufferStrcat;
 virBufferStrcatVArgs;
 virBufferTrim;
 virBufferTrimChars;
+virBufferTrimLen;
 virBufferURIEncodeString;
 virBufferUse;
 virBufferVasprintf;
diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c
index 914c386b18..b76d99b56f 100644
--- a/src/util/virbuffer.c
+++ b/src/util/virbuffer.c
@@ -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
diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h
index 183f78f279..7b068075b2 100644
--- a/src/util/virbuffer.h
+++ b/src/util/virbuffer.h
@@ -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);
-- 
2.19.2





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux