EFL 1.7 svn doobies
[profile/ivi/eina.git] / src / lib / eina_strbuf_template_c.x
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 /* This file should be included from files implementing strbuf.
6    The including file should define the following macros:
7  * _STRBUF_DATA_TYPE
8  * _STRBUF_CSIZE
9  * _STRBUF_STRUCT_NAME
10  * _STRBUF_STRLEN_FUNC(x)
11  * _STRBUF_STRESCAPE_FUNC(x)
12  * _STRBUF_STRSTR_FUNC(x, y)
13  * _STRBUF_MAGIC
14  * _STRBUF_MAGIC_STR
15  * See how it's done in eina_ustrbuf.c and eina_strbuf.c. This just makes things
16  * a lot easier since those are essentially the same just with different sizes.
17  */
18
19 #include "eina_binbuf_template_c.x"
20
21 /*============================================================================*
22  *                                   API                                      *
23  *============================================================================*/
24
25 EAPI _STRBUF_STRUCT_NAME *
26 _FUNC_EXPAND(manage_new)(_STRBUF_DATA_TYPE *str)
27 {
28    _STRBUF_STRUCT_NAME *buf = eina_strbuf_common_manage_new(_STRBUF_CSIZE,
29          (void *) str, _STRBUF_STRLEN_FUNC(str));
30    EINA_MAGIC_SET(buf, _STRBUF_MAGIC);
31    return buf;
32 }
33
34 EAPI Eina_Bool
35 _FUNC_EXPAND(append)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str)
36 {
37    EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
38    return eina_strbuf_common_append(_STRBUF_CSIZE, buf, (const void *) str, _STRBUF_STRLEN_FUNC(str));
39 }
40
41 EAPI Eina_Bool
42 _FUNC_EXPAND(append_escaped)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str)
43 {
44    _STRBUF_DATA_TYPE *esc;
45    Eina_Bool ret;
46
47    EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
48    esc = _STRBUF_STRESCAPE_FUNC(str);
49    if (!esc) {
50       return _FUNC_EXPAND(append)(buf, str);
51    }
52    ret = _FUNC_EXPAND(append)(buf, esc);
53    if (esc)
54       free(esc);
55
56    return ret;
57 }
58
59 EAPI Eina_Bool
60 _FUNC_EXPAND(append_n)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t maxlen)
61 {
62    EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
63    return eina_strbuf_common_append_n(_STRBUF_CSIZE, buf, (const void *) str, _STRBUF_STRLEN_FUNC(str), maxlen);
64 }
65
66 EAPI Eina_Bool
67 _FUNC_EXPAND(insert)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t pos)
68 {
69    EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
70    return eina_strbuf_common_insert(_STRBUF_CSIZE, buf, (const void *) str, _STRBUF_STRLEN_FUNC(str), pos);
71 }
72
73 EAPI Eina_Bool
74 _FUNC_EXPAND(insert_escaped)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t pos)
75 {
76    _STRBUF_DATA_TYPE *esc;
77    Eina_Bool ret;
78    EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
79
80    esc = _STRBUF_STRESCAPE_FUNC(str);
81    if (!esc) {
82       return _FUNC_EXPAND(insert)(buf, str, pos);
83    }
84    ret = _FUNC_EXPAND(insert)(buf, esc, pos);
85    if (esc)
86       free(esc);
87
88    return ret;
89 }
90
91 EAPI Eina_Bool
92 _FUNC_EXPAND(insert_n)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t maxlen, size_t pos)
93 {
94    EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
95    return eina_strbuf_common_insert_n(_STRBUF_CSIZE, buf, (const void *) str, _STRBUF_STRLEN_FUNC(str), maxlen, pos);
96 }
97