Eina_Strbuf example
First thing always is including Eina:
Next we initialize eina and create a string buffer to play with:
Here you can see two different ways of creating a buffer with the same contents. We could create them in simpler ways, but this gives us an opportunity to demonstrate several functions in action:
eina_strbuf_append_length(buf, "buffe", 5);
eina_strbuf_append_char(buf, 'r');
printf("%s\n", eina_strbuf_string_get(buf));
eina_strbuf_insert_escaped(buf, "my ", 0);
printf("%s\n", eina_strbuf_string_get(buf));
eina_strbuf_reset(buf);
Eina_Bool eina_strbuf_insert_escaped(Eina_Strbuf *buf, const char *str, size_t pos)
Insert an escaped string to a buffer, reallocating as necessary.
Eina_Bool eina_strbuf_append_char(Eina_Strbuf *buf, char c)
Append a character to a string buffer, reallocating as necessary.
const char * eina_strbuf_string_get(const Eina_Strbuf *buf)
Retrieve a pointer to the contents of a string buffer.
Eina_Bool eina_strbuf_append_length(Eina_Strbuf *buf, const char *str, size_t length)
Append a string of exact length to a buffer, reallocating as necessary.
eina_strbuf_append_escaped(buf, "my buffer");
printf("%s\n", eina_strbuf_string_get(buf));
eina_strbuf_reset(buf);
Eina_Bool eina_strbuf_append_escaped(Eina_Strbuf *buf, const char *str)
Append an escaped string to a buffer, reallocating as necessary.
Next we use the printf family of functions to create a formated string, add, remove and replace some content:
printf("%s\n", eina_strbuf_string_get(buf));
Eina_Bool eina_strbuf_append_printf(Eina_Strbuf *buf, const char *fmt,...) EINA_PRINTF(2
Append a string to a buffer, reallocating as necessary.
Eina_Bool eina_strbuf_insert_printf(Eina_Strbuf *buf, const char *fmt, size_t pos,...) EINA_PRINTF(2
Insert a string to a buffer, reallocating as necessary.
size_t eina_strbuf_length_get(const Eina_Strbuf *buf)
Retrieve the length of the string buffer content.
eina_strbuf_remove(buf, 0, 7);
printf("%s\n", eina_strbuf_string_get(buf));
Eina_Bool eina_strbuf_remove(Eina_Strbuf *buf, size_t start, size_t end)
Remove a slice of the given string buffer.
printf("%s\n", eina_strbuf_string_get(buf));
int eina_strbuf_replace_all(Eina_Strbuf *buf, const char *str, const char *with)
Replace all strings with an other string.
Definition eina_strbuf_common.c:801
Once done we free our string buffer, shut down Eina and end the application: