[libvirt] [PATCH 02/23] util: buffer: Add API to set indentation level to a given value

Peter Krempa pkrempa at redhat.com
Wed Mar 15 16:37:14 UTC 2017


It will be useful to set indentation level to 0 after formatting a
nested structure rather than having to track the depth.
---
 src/libvirt_private.syms |  1 +
 src/util/virbuffer.c     | 19 +++++++++++++++++++
 src/util/virbuffer.h     |  2 ++
 3 files changed, 22 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 4efea0098..39e2b40c5 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1303,6 +1303,7 @@ virBufferEscapeShell;
 virBufferEscapeString;
 virBufferFreeAndReset;
 virBufferGetIndent;
+virBufferSetIndent;
 virBufferStrcat;
 virBufferTrim;
 virBufferURIEncodeString;
diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c
index 41d541b32..8f0f49d7f 100644
--- a/src/util/virbuffer.c
+++ b/src/util/virbuffer.c
@@ -88,6 +88,25 @@ virBufferAdjustIndent(virBufferPtr buf, int indent)
     buf->indent += indent;
 }

+
+/**
+ * virBufferAdjustIndent:
+ * @buf: the buffer
+ * @indent: new indentation size.
+ *
+ * Set the auto-indent value to @indent. See virBufferAdjustIndent on how auto
+ * indentation is applied.
+ */
+void
+virBufferSetIndent(virBufferPtr buf, int indent)
+{
+    if (!buf || buf->error)
+        return;
+
+    buf->indent = indent;
+}
+
+
 /**
  * virBufferGetIndent:
  * @buf: the buffer
diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h
index 94f14b5b1..d1b64ca3a 100644
--- a/src/util/virbuffer.h
+++ b/src/util/virbuffer.h
@@ -95,6 +95,8 @@ void virBufferURIEncodeString(virBufferPtr buf, const char *str);
     virBufferAdd(buf_, "" literal_string_ "", sizeof(literal_string_) - 1)

 void virBufferAdjustIndent(virBufferPtr buf, int indent);
+void virBufferSetIndent(virBufferPtr, int indent);
+
 int virBufferGetIndent(const virBuffer *buf, bool dynamic);

 void virBufferTrim(virBufferPtr buf, const char *trim, int len);
-- 
2.12.0




More information about the libvir-list mailing list