From 01f1b4d0240dd6099769fdc882e48e8e5312c7b4 Mon Sep 17 00:00:00 2001 From: gastal Date: Tue, 28 Jun 2011 14:38:17 +0000 Subject: [PATCH] Eina: eina_strbuf example and documentation. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@60762 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/examples/Makefile.am | 6 ++++-- src/examples/eina_strbuf_01.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/include/eina_strbuf.h | 31 +++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/examples/eina_strbuf_01.c diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am index f3e474c..7585257 100644 --- a/src/examples/Makefile.am +++ b/src/examples/Makefile.am @@ -29,7 +29,8 @@ SRCS = \ eina_inlist_01.c \ eina_inlist_02.c \ eina_inlist_03.c \ - eina_str_01.c + eina_str_01.c \ + eina_strbuf_01.c pkglib_PROGRAMS = @@ -58,6 +59,7 @@ pkglib_PROGRAMS += \ eina_inlist_01 \ eina_inlist_02 \ eina_inlist_03 \ - eina_str_01 + eina_str_01 \ + eina_strbuf_01 endif diff --git a/src/examples/eina_strbuf_01.c b/src/examples/eina_strbuf_01.c new file mode 100644 index 0000000..eddfccf --- /dev/null +++ b/src/examples/eina_strbuf_01.c @@ -0,0 +1,41 @@ +//Compile with: +//gcc -Wall -o eina_strbuf_01 eina_strbuf_01.c `pkg-config --cflags --libs eina` + +#include +#include + +int main(int argc, char **argv) +{ + Eina_Strbuf *buf; + + eina_init(); + + buf = eina_strbuf_new(); + + 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_strbuf_append_escaped(buf, "my buffer"); + printf("%s\n", eina_strbuf_string_get(buf)); + eina_strbuf_reset(buf); + + eina_strbuf_append_printf(buf, "%s%c", "buffe", 'r'); + eina_strbuf_insert_printf(buf, " %s: %d", 6, "length", eina_strbuf_length_get(buf)); + printf("%s\n", eina_strbuf_string_get(buf)); + + eina_strbuf_remove(buf, 0, 7); + printf("%s\n", eina_strbuf_string_get(buf)); + + eina_strbuf_replace_all(buf, "length", "size"); + printf("%s\n", eina_strbuf_string_get(buf)); + + eina_strbuf_free(buf); + eina_shutdown(); + + return 0; +} diff --git a/src/include/eina_strbuf.h b/src/include/eina_strbuf.h index ba9b717..f8f90e6 100644 --- a/src/include/eina_strbuf.h +++ b/src/include/eina_strbuf.h @@ -6,6 +6,35 @@ #include "eina_types.h" + +/** + * @page tutorial_strbuf Eina_Strbuf example + * @dontinclude eina_strbuf_01.c + * + * First thing always is including Eina: + * @skipline #include + * @until #include + * + * Next we initialize eina and create a string buffer to play with: + * @until strbuf_new + * + * 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 + * oportunity to demonstrate several functions in action: + * @until strbuf_reset + * @until strbuf_reset + * + * Next we use the printf family of functions to create a formated string, + * add, remove and replace some content: + * @until strbuf_string_get + * @until strbuf_string_get + * @until strbuf_string_get + * + * Once done we free our string buffer, shut down Eina and end the application: + * @until } + * + * @example eina_strbuf_01.c + */ /** * @addtogroup Eina_String_Buffer_Group String Buffer * @@ -14,6 +43,8 @@ * The String Buffer data type is designed to be a mutable string, * allowing to append, prepend or insert a string to a buffer. * + * For more information see @ref tutorial_strbuf "this example". + * * @{ */ -- 2.7.4