virBufferAdjustIndent;
virBufferAsprintf;
virBufferContentAndReset;
+virBufferCurrentContent;
virBufferError;
virBufferEscape;
virBufferEscapeSexpr;
virBufferAdd(buf, &c, 1);
}
+/**
+ * virBufferCurrentContent:
+ * @buf: Buffer
+ *
+ * Get the current content from the buffer. The content is only valid
+ * until the next operation on @buf, and an empty string is returned if
+ * no content is present yet.
+ *
+ * Returns the buffer content or NULL in case of error.
+ */
+const char *
+virBufferCurrentContent(virBufferPtr buf)
+{
+ if (!buf || buf->error)
+ return NULL;
+ return buf->use ? buf->content : "";
+}
+
/**
* virBufferContentAndReset:
* @buf: Buffer
*
* Get the content from the buffer and free (only) the buffer structure.
* The caller owns the returned string & should free it when no longer
- * required. The buffer object is reset to its initial state.
+ * required. The buffer object is reset to its initial state. This
+ * interface intentionally returns NULL instead of an empty string if
+ * there is no content.
*
* Returns the buffer content or NULL in case of error.
*/
};
# endif
+const char *virBufferCurrentContent(virBufferPtr buf);
char *virBufferContentAndReset(virBufferPtr buf);
void virBufferFreeAndReset(virBufferPtr buf);
int virBufferError(const virBufferPtr buf);
ret = -1;
}
virBufferAdjustIndent(buf, 3);
+ if (STRNEQ(virBufferCurrentContent(buf), "")) {
+ TEST_ERROR("Wrong content");
+ ret = -1;
+ }
if (virBufferGetIndent(buf, false) != 3 ||
virBufferGetIndent(buf, true) != 3 ||
virBufferError(buf)) {
}
virBufferAdjustIndent(buf, 2);
virBufferAddLit(buf, "1");
+ if (STRNEQ(virBufferCurrentContent(buf), " 1")) {
+ TEST_ERROR("Wrong content");
+ ret = -1;
+ }
if (virBufferGetIndent(buf, false) != 2 ||
virBufferGetIndent(buf, true) != 0) {
TEST_ERROR("Wrong indentation");