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

Re: [libvirt] [PATCH v2 1/3] util: virbuffer: introduce virBufferEscapeN



On Thu, Feb 23, 2017 at 09:36:16PM +0100, Pavel Hrdina wrote:
+/**
+ * virBufferEscapeN:
+ * @buf: the buffer to append to
+ * @format: a printf like format string but with only one %s parameter
+ * @str: the string argument which needs to be escaped

+ * @...: the variable list of arguments composed

s/arguments composed/escape pairs/ maybe?

+ *
+ * The variable list of arguments @... must be composed of
+ * 'char escape, char *toescape' pairs followed by NULL.
+ *
+ * This has the same functionality as virBufferEscape with the extension
+ * that allows to specify multiple pairs of chars that needs to be escaped.
+ */
+void
+virBufferEscapeN(virBufferPtr buf,
+                 const char *format,
+                 const char *str,
+                 ...)
+{
+    int len;
+    size_t i;
+    char escape;
+    char *toescape;
+    char *escaped = NULL;
+    char *out;
+    const char *cur;
+    struct _virBufferEscapePair escapeItem;
+    struct _virBufferEscapePair *escapeList = NULL;
+    size_t nescapeList = 0;
+    va_list ap;
+
+    if ((format == NULL) || (buf == NULL) || (str == NULL))
+        return;
+
+    if (buf->error)
+        return;
+
+    len = strlen(str);
+
+    va_start(ap, str);
+

+    while ((escape = va_arg(ap, int))) {
+        if (!(toescape = va_arg(ap, char *))) {

You can either assign directly to escapeItem.{to,}escape here,
or declare toescape and escapeItem inside the while loop to reduce
the number of function-wide variables.

+            virBufferSetError(buf, errno);
+            goto cleanup;
+        }

Jan

Attachment: signature.asc
Description: Digital signature


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