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

Peter Krempa posted 23 patches 8 years, 11 months ago
[libvirt] [PATCH 02/23] util: buffer: Add API to set indentation level to a given value
Posted by Peter Krempa 8 years, 11 months ago
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@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 02/23] util: buffer: Add API to set indentation level to a given value
Posted by Eric Blake 8 years, 10 months ago
On 03/15/2017 11:37 AM, Peter Krempa wrote:
> 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(+)
> 

> +
> +/**
> + * virBufferAdjustIndent:

Too much copy-and-paste.

> + * @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;
> +}
> +

No testsuite addition?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 02/23] util: buffer: Add API to set indentation level to a given value
Posted by Peter Krempa 8 years, 10 months ago
On Wed, Mar 22, 2017 at 14:27:18 -0500, Eric Blake wrote:
> On 03/15/2017 11:37 AM, Peter Krempa wrote:
> > 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(+)
> > 
> 
> > +
> > +/**
> > + * virBufferAdjustIndent:
> 
> Too much copy-and-paste.
> 
> > + * @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;
> > +}
> > +
> 
> No testsuite addition?

For such trivial operation? I think we have pretty strong coverage of
the indentation code. This simple setter isn't worth it IMO.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 02/23] util: buffer: Add API to set indentation level to a given value
Posted by Eric Blake 8 years, 10 months ago
On 03/23/2017 02:14 AM, Peter Krempa wrote:

>>
>> No testsuite addition?
> 
> For such trivial operation? I think we have pretty strong coverage of
> the indentation code. This simple setter isn't worth it IMO.

I don't see how adding one or two lines to the testsuite, to ensure we
don't break this new interface, is not worth it.  Yes, we have a lot of
good coverage already, so let's keep it good, rather than introducing
holes in the coverage as we add new stuff.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

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