diff options
Diffstat (limited to 'content/handlers/html')
-rw-r--r-- | content/handlers/html/list_counter_style.c | 34 |
1 files changed, 30 insertions, 4 deletions
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,8 +41,8 @@ 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 */ @@ -50,6 +50,32 @@ struct list_counter_style { }; /** + * 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 * * \param[in] buf The output buffer @@ -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; |