From b70243d38d68c5eaf7643b492e9d5e38e8a35301 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sat, 04 Nov 2017 14:37:10 -0400 Subject: mq_html_document_v(): New function --- (limited to 'src/utils') diff --git a/src/utils/html.c b/src/utils/html.c index 262be3b..fdaa96a 100644 --- a/src/utils/html.c +++ b/src/utils/html.c @@ -300,6 +300,46 @@ mq_html_document(const gchar *title, ...) return document; } +gchar * +mq_html_document_v(const gchar *title, gchar **children) +{ + gsize len; + gsize i; + gchar *document; + gchar *ptr; + + /* Calculate length. */ + len = strlen("\n\n\n\n"); + len += strlen(title); + len += strlen("\n\n\n\n"); + for (i = 0; children && children[i]; ++i) { + len += strlen(children[i]); + } + len += strlen("\n\n"); + ++len; /* NUL byte */ + + /* Build string. */ + document = g_new(gchar, len); + ptr = g_stpcpy(document, "\n\n\n\n"); + ptr = g_stpcpy(ptr, title); + ptr = g_stpcpy(ptr, "\n\n\n\n"); + for (i = 0; children && children[i]; ++i) { + ptr = g_stpcpy(ptr, children[i]); + } + ptr = g_stpcpy(ptr, "\n\n"); /* g_stpcpy() adds NUL. */ + + return document; +} + #define TEXT_ELEMENT(ELEM) \ gchar * \ mq_html_##ELEM(const gchar *text) \ diff --git a/src/utils/html.h b/src/utils/html.h index 27e0cfe..10588f7 100644 --- a/src/utils/html.h +++ b/src/utils/html.h @@ -29,6 +29,9 @@ G_BEGIN_DECLS gchar * mq_html_document(const gchar *title, ...) G_GNUC_NULL_TERMINATED; +gchar * +mq_html_document_v(const gchar *title, gchar **children); + #define TEXT_ELEMENT(ELEM) \ gchar * \ mq_html_##ELEM(const gchar *text); \ -- cgit v0.9.1