diff --git a/legacy/eina/src/include/eina_strbuf.h b/legacy/eina/src/include/eina_strbuf.h index 0ffdfe89ac..985b3a3fa9 100644 --- a/legacy/eina/src/include/eina_strbuf.h +++ b/legacy/eina/src/include/eina_strbuf.h @@ -10,6 +10,7 @@ typedef struct _Eina_Strbuf Eina_Strbuf; EAPI Eina_Strbuf *eina_strbuf_new(void); EAPI void eina_strbuf_free(Eina_Strbuf *buf) EINA_ARG_NONNULL(1); EAPI void eina_strbuf_append(Eina_Strbuf *buf, const char *str) EINA_ARG_NONNULL(1, 2); +EAPI void eina_strbuf_append_escaped(Eina_Strbuf *buf, const char *str) EINA_ARG_NONNULL(1, 2); EAPI void eina_strbuf_append_n(Eina_Strbuf *buf, const char *str, unsigned int maxlen) EINA_ARG_NONNULL(1, 2); EAPI void eina_strbuf_append_char(Eina_Strbuf *buf, char c) EINA_ARG_NONNULL(1); EAPI void eina_strbuf_insert(Eina_Strbuf *buf, const char *str, diff --git a/legacy/eina/src/lib/eina_strbuf.c b/legacy/eina/src/lib/eina_strbuf.c index 2e60e32872..52a00dec0b 100644 --- a/legacy/eina/src/lib/eina_strbuf.c +++ b/legacy/eina/src/lib/eina_strbuf.c @@ -102,6 +102,26 @@ eina_strbuf_append(Eina_Strbuf *buf, const char *str) buf->len += len; } +/** + * Append an escaped string to a buffer, reallocating as necessary. + * @param buf the Eina_Strbuf to append to + * @param str the string to append + */ +EAPI void +eina_strbuf_append_escaped(Eina_Strbuf *buf, const char *str) +{ + size_t len; + char *esc; + EINA_MAGIC_CHECK_STRBUF(buf); + + esc = eina_str_escape(str); + len = strlen(str); + _eina_strbuf_resize(buf, buf->len + len); + eina_strlcpy(buf->buf + buf->len, str, buf->size - buf->len); + buf->len += len; + free(esc); +} + /** * Append a string to a buffer, reallocating as necessary. Limited by maxlen. * @param buf the Eina_Strbuf to append to