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

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

 



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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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