From 55fadc802ac80286e4f7266866ad789c78f57483 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 2 Feb 2021 16:39:41 +0000 Subject: html: list counter style: Revert to string for {pre|post}fix. --- content/handlers/html/list_counter_style.c | 34 ++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'content/handlers') diff --git a/content/handlers/html/list_counter_style.c b/content/handlers/html/list_counter_style.c index e864c9b52..81d9aa3d3 100644 --- a/content/handlers/html/list_counter_style.c +++ b/content/handlers/html/list_counter_style.c @@ -41,14 +41,40 @@ struct list_counter_style { const unsigned int length; const symbol_t value; } pad; - const symbol_t prefix; - const symbol_t postfix; + const char *prefix; + const char *postfix; const symbol_t *symbols; /**< array of symbols which represent this style */ const int *weights; /**< symbol weights for additive schemes */ const size_t items; /**< items in symbol and weight table */ size_t (*calc)(uint8_t *ares, const size_t alen, int value, const struct list_counter_style *cstyle); /**< function to calculate the system */ }; +/** + * Copy a null-terminated UTF-8 string to buffer at offset, if there is space + * + * \param[in] buf The output buffer + * \param[in] buflen The length of \a buf + * \param[in] pos Current position in \a buf + * \param[in] str The string to copy into \a buf + * \return The number of bytes needed in the output buffer which may be + * larger than \a buflen but the buffer will not be overrun + */ +static inline size_t +copy_string(char *buf, const size_t buflen, size_t pos, const char *str) +{ + size_t sidx = 0; /* current string index */ + + while (str[sidx] != '\0') { + if (pos < buflen) { + buf[pos] = str[sidx]; + } + pos++; + sidx++; + } + + return sidx; +} + /** * Copy a UTF-8 symbol to buffer at offset, if there is space * @@ -115,8 +141,8 @@ map_aval_to_symbols(char *buf, const size_t buflen, } /* postfix */ - oidx += copy_symbol(buf, buflen, oidx, - (cstyle->postfix[0] != '\0') ? + oidx += copy_string(buf, buflen, oidx, + (cstyle->postfix != NULL) ? cstyle->postfix : postfix); return oidx; -- cgit v1.2.3