Add eina_strbuf_reset

Function to reset the internal string, so we can reuse the allocated
mem.

SVN revision: 45952
This commit is contained in:
Sebastian Dransfeld 2010-02-06 21:43:22 +00:00
parent fc5f097b7e
commit 2587c28d9a
2 changed files with 18 additions and 0 deletions

View File

@ -9,6 +9,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_reset(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);

View File

@ -85,6 +85,23 @@ eina_strbuf_free(Eina_Strbuf *buf)
free(buf);
}
/**
* Reset a string buffer
* @param buf the buffer to reset
*
* The buffer len is set to 0, no mem is free'd
*/
EAPI void
eina_strbuf_reset(Eina_Strbuf *buf)
{
EINA_MAGIC_CHECK_STRBUF(buf);
buf->len = 0;
buf->size = EINA_STRBUF_INIT_SIZE;
buf->step = EINA_STRBUF_INIT_STEP;
buf->buf[0] = '\0';
}
/**
* Append a string to a buffer, reallocating as necessary.
* @param buf the Eina_Strbuf to append to