提交 5e8551fb 编写于 作者: P Peter Krempa

util: virbuffer: Remove @dynamic from virBufferGetIndent

After the conversion of all callers that would pass true as @dynamic to
a different function we can remove the unused argument now.

Additionally modify the return type to 'size_t' as indentation can't be
negative and remove checks whether @buf is passed as it's caller's duty
to do so.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 c7ccb159
......@@ -28487,7 +28487,7 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def,
xmlIndentTreeOutput = 1;
xmlbuf = xmlBufferCreate();
if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
virBufferGetIndent(buf, false) / 2, 1) < 0) {
virBufferGetIndent(buf) / 2, 1) < 0) {
xmlBufferFree(xmlbuf);
xmlIndentTreeOutput = oldIndentTreeOutput;
goto error;
......
......@@ -2458,7 +2458,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
xmlIndentTreeOutput = 1;
xmlbuf = xmlBufferCreate();
if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
virBufferGetIndent(buf, false) / 2, 1) < 0) {
virBufferGetIndent(buf) / 2, 1) < 0) {
xmlBufferFree(xmlbuf);
xmlIndentTreeOutput = oldIndentTreeOutput;
goto error;
......
......@@ -102,18 +102,12 @@ virBufferSetIndent(virBufferPtr buf, int indent)
/**
* virBufferGetIndent:
* @buf: the buffer
* @dynamic: if false, return set value; if true, return 0 unless next
* append would be affected by auto-indent
*
* Return the current auto-indent value, or -1 if there has been an error.
* Return the current auto-indent setting of @buf.
*/
int
virBufferGetIndent(const virBuffer *buf, bool dynamic)
size_t
virBufferGetIndent(const virBuffer *buf)
{
if (!buf || buf->error)
return -1;
if (dynamic && buf->use && buf->content[buf->use - 1] != '\n')
return 0;
return buf->indent;
}
......
......@@ -107,9 +107,9 @@ void virBufferSetIndent(virBufferPtr, int indent);
* child buffer.
*/
#define virBufferSetChildIndent(childBuf_, parentBuf_) \
virBufferSetIndent(childBuf_, virBufferGetIndent(parentBuf_, false) + 2)
virBufferSetIndent(childBuf_, virBufferGetIndent(parentBuf_) + 2)
int virBufferGetIndent(const virBuffer *buf, bool dynamic);
size_t virBufferGetIndent(const virBuffer *buf);
size_t virBufferGetEffectiveIndent(const virBuffer *buf);
void virBufferTrim(virBufferPtr buf, const char *trim, int len);
......
......@@ -430,7 +430,7 @@ testQEMUSchemaValidateAlternate(virJSONValuePtr obj,
virBufferAddLit(debug, "(\n");
virBufferAdjustIndent(debug, 3);
indent = virBufferGetIndent(debug, false);
indent = virBufferGetIndent(debug);
n = virJSONValueArraySize(members);
for (i = 0; i < n; i++) {
......
......@@ -18,7 +18,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED)
char *result = NULL;
int ret = 0;
if (virBufferGetIndent(buf, false) != 0 ||
if (virBufferGetIndent(buf) != 0 ||
virBufferGetEffectiveIndent(buf) != 0) {
VIR_TEST_DEBUG("Wrong indentation");
ret = -1;
......@@ -28,28 +28,28 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED)
VIR_TEST_DEBUG("Wrong content");
ret = -1;
}
if (virBufferGetIndent(buf, false) != 3 ||
if (virBufferGetIndent(buf) != 3 ||
virBufferGetEffectiveIndent(buf) != 3 ||
virBufferError(buf)) {
VIR_TEST_DEBUG("Wrong indentation");
ret = -1;
}
virBufferAdjustIndent(buf, -2);
if (virBufferGetIndent(buf, false) != 1 ||
if (virBufferGetIndent(buf) != 1 ||
virBufferGetEffectiveIndent(buf) != 1 ||
virBufferError(buf)) {
VIR_TEST_DEBUG("Wrong indentation");
ret = -1;
}
virBufferAdjustIndent(buf, -3);
if (virBufferGetIndent(buf, false) != 0 ||
if (virBufferGetIndent(buf) != 0 ||
virBufferGetEffectiveIndent(buf) != 0) {
VIR_TEST_DEBUG("Indentation level not truncated");
ret = -1;
}
virBufferAdjustIndent(buf, 3);
virBufferFreeAndReset(buf);
if (virBufferGetIndent(buf, false) != 0 ||
if (virBufferGetIndent(buf) != 0 ||
virBufferGetEffectiveIndent(buf) != 0 ||
virBufferError(buf)) {
VIR_TEST_DEBUG("Reset didn't clear indentation");
......@@ -65,7 +65,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED)
VIR_TEST_DEBUG("Wrong content");
ret = -1;
}
if (virBufferGetIndent(buf, false) != 2 ||
if (virBufferGetIndent(buf) != 2 ||
virBufferGetEffectiveIndent(buf) != 0) {
VIR_TEST_DEBUG("Wrong indentation");
ret = -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册