On Thu, Oct 24, 2019 at 03:56:33PM +0200, Peter Krempa wrote:
GString is surprisingly similar to what libvirt was doing painstaikingly
painstakingly Imagine a pancake, but much more convoluted.
manually. Yet it doesn't support the automatic indentation features we use for XML so we rather keep those in form of virBuffer using GString internally. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/util/virbuffer.c | 205 +++++++++++++++---------------------------- src/util/virbuffer.h | 6 +- 2 files changed, 71 insertions(+), 140 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 2256bd5de5..9306b79703 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c +static void +virBufferApplyIndent(virBufferPtr buf) +{ + const char space[] = " "; + size_t spacesz = sizeof(space) - 1;
/* infinity minus one */
+ size_t toindent = virBufferGetEffectiveIndent(buf); - size = buf->use + len + 1000; + if (toindent == 0) + return;
@@ -810,21 +737,27 @@ virBufferTrim(virBufferPtr buf, const char *str, int len) { size_t len2 = 0; - if (!buf || buf->error) + if (!buf || buf->error || !buf->str) return; + if (!str && len < 0) return; - if (len > 0 && len > buf->use) + + if (len > 0 && len > buf->str->len) return; + if (str) { len2 = strlen(str); - if (len2 > buf->use || - memcmp(&buf->content[buf->use - len2], str, len2) != 0) + if (len2 > buf->str->len || + memcmp(&buf->str->str[buf->str->len - len2], str, len2) != 0) return; } - buf->use -= len < 0 ? len2 : len; - buf->content[buf->use] = '\0'; + + if (len < 0) + len = len2;
This function is odd. Maybe it would work better as two (which is - ironically - even) separate ones. But the conversion looks good.
+ + g_string_truncate(buf->str, buf->str->len - len); }
Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx> Jano
Attachment:
signature.asc
Description: PGP signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list