\chapter{Eina\+\_\+\+Strbuf example}
\hypertarget{tutorial_strbuf}{}\label{tutorial_strbuf}\index{Eina\_Strbuf example@{Eina\_Strbuf example}}


First thing always is including Eina\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <\mbox{\hyperlink{Eina_8h}{Eina.h}}>}}

\end{DoxyCodeInclude}
 Next we initialize eina and create a string buffer to play with\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}\ main(\textcolor{keywordtype}{int}\ argc\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{char}\ **argv\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__Strbuf}{Eina\_Strbuf}}\ *buf,\ *substr;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Main__Group_ga81b8137665b8a4d2cb38ca50017d4c74}{eina\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ buf\ =\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_ga13277ebcc07defa040d6e92f22774031}{eina\_strbuf\_new}}();}

\end{DoxyCodeInclude}
 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\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gaafc0d73b12be5e1953cf1a417560cbea}{eina\_strbuf\_append\_length}}(buf,\ \textcolor{stringliteral}{"{}BUFFE"{}},\ 5);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_ga5683cd7f0a499065d99cc0de4d393265}{eina\_strbuf\_append\_char}}(buf,\ \textcolor{charliteral}{'R'});}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gafd020a4f5483d73741c9d1b6d44b24d5}{eina\_strbuf\_string\_get}}(buf));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gac070cb3adc8b4ae2a0aa5e1587fca90c}{eina\_strbuf\_tolower}}(buf);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gafd020a4f5483d73741c9d1b6d44b24d5}{eina\_strbuf\_string\_get}}(buf));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ substr\ =\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gae656aff3c5c7fb271b78a22bb37294b8}{eina\_strbuf\_substr\_get}}(buf,\ 3,\ 2);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gafd020a4f5483d73741c9d1b6d44b24d5}{eina\_strbuf\_string\_get}}(substr));}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_ga88d8da6589bad44714ad9e47aaa1992b}{eina\_strbuf\_free}}(substr);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gac956e556785513d2d76642982ace57fc}{eina\_strbuf\_insert\_escaped}}(buf,\ \textcolor{stringliteral}{"{}my\ "{}},\ 0);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gafd020a4f5483d73741c9d1b6d44b24d5}{eina\_strbuf\_string\_get}}(buf));}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_ga43f27247b21aa3ca82d26ec6d66eeb47}{eina\_strbuf\_reset}}(buf);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_ga097411cd0edbf76c58a48e8b6b4814a7}{eina\_strbuf\_append\_escaped}}(buf,\ \textcolor{stringliteral}{"{}my\ buffer"{}});}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gafd020a4f5483d73741c9d1b6d44b24d5}{eina\_strbuf\_string\_get}}(buf));}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_ga43f27247b21aa3ca82d26ec6d66eeb47}{eina\_strbuf\_reset}}(buf);}

\end{DoxyCodeInclude}
 Next we use the printf family of functions to create a formatted string, add, remove and replace some content\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ eina\_strbuf\_append\_printf(buf,\ \textcolor{stringliteral}{"{}\%s\%c"{}},\ \textcolor{stringliteral}{"{}buffe"{}},\ \textcolor{charliteral}{'r'});}
\DoxyCodeLine{\ \ \ eina\_strbuf\_insert\_printf(buf,\ \textcolor{stringliteral}{"{}\ \%s:\ \%d"{}},\ 6,\ \textcolor{stringliteral}{"{}length"{}},\ (\textcolor{keywordtype}{int})\mbox{\hyperlink{group__Eina__String__Buffer__Group_ga001e098d7021494e8980c6db0605f3f0}{eina\_strbuf\_length\_get}}(buf));}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gafd020a4f5483d73741c9d1b6d44b24d5}{eina\_strbuf\_string\_get}}(buf));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gafc75dce22b1af29f7a3f1b6ecf505fc9}{eina\_strbuf\_remove}}(buf,\ 0,\ 7);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gafd020a4f5483d73741c9d1b6d44b24d5}{eina\_strbuf\_string\_get}}(buf));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gade7cf2d9653035e8362b85720df9214c}{eina\_strbuf\_replace\_all}}(buf,\ \textcolor{stringliteral}{"{}length"{}},\ \textcolor{stringliteral}{"{}size"{}});}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gafd020a4f5483d73741c9d1b6d44b24d5}{eina\_strbuf\_string\_get}}(buf));}

\end{DoxyCodeInclude}
 Once done we free our string buffer, shut down Eina and end the application\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_ga88d8da6589bad44714ad9e47aaa1992b}{eina\_strbuf\_free}}(buf);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ buf\ =\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_ga1f6ff5b582b29b4d4ec9e188f96fb8d8}{eina\_strbuf\_manage\_read\_only\_new\_length}}(\textcolor{stringliteral}{"{}Example\ string"{}},\ 14);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gafd020a4f5483d73741c9d1b6d44b24d5}{eina\_strbuf\_string\_get}}(buf));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_ga5683cd7f0a499065d99cc0de4d393265}{eina\_strbuf\_append\_char}}(buf,\ \textcolor{charliteral}{'.'});}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gafd020a4f5483d73741c9d1b6d44b24d5}{eina\_strbuf\_string\_get}}(buf));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gaafc0d73b12be5e1953cf1a417560cbea}{eina\_strbuf\_append\_length}}(buf,\ \textcolor{stringliteral}{"{}Another\ string."{}},\ 15);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__String__Buffer__Group_gafd020a4f5483d73741c9d1b6d44b24d5}{eina\_strbuf\_string\_get}}(buf));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__String__Buffer__Group_ga88d8da6589bad44714ad9e47aaa1992b}{eina\_strbuf\_free}}(buf);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Main__Group_ga5bf35513199d5220341437c05696285d}{eina\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
