2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
5 /* This file should be included from files implementing binbuf.
6 * The including file should define the following macros:
13 * See how it's done in eina_ustrbuf.c and eina_strbuf.c. This just makes things
14 * a lot easier since those are essentially the same just with different sizes.
17 /*============================================================================*
19 *============================================================================*/
23 * @brief Initialize the strbuf module.
25 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
27 * This function sets up the strbuf module of Eina. It is called by
33 _FUNC_EXPAND(init)(void)
35 eina_magic_string_static_set(_STRBUF_MAGIC, _STRBUF_MAGIC_STR);
36 return eina_strbuf_common_init();
41 * @brief Shut down the strbuf module.
43 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
45 * This function shuts down the strbuf module set up by
46 * eina_ustrbuf_init(). It is called by eina_shutdown().
48 * @see eina_shutdown()
51 _FUNC_EXPAND(shutdown)(void)
53 return eina_strbuf_common_shutdown();
56 /*============================================================================*
58 *============================================================================*/
60 EAPI _STRBUF_STRUCT_NAME *
61 _FUNC_EXPAND(new)(void)
63 _STRBUF_STRUCT_NAME *buf = eina_strbuf_common_new(_STRBUF_CSIZE);
64 EINA_MAGIC_SET(buf, _STRBUF_MAGIC);
68 EAPI _STRBUF_STRUCT_NAME *
69 _FUNC_EXPAND(manage_new_length)(_STRBUF_DATA_TYPE *str, size_t length)
71 _STRBUF_STRUCT_NAME *buf =
72 eina_strbuf_common_manage_new(_STRBUF_CSIZE, (void *) str, length);
73 EINA_MAGIC_SET(buf, _STRBUF_MAGIC);
78 _FUNC_EXPAND(free)(_STRBUF_STRUCT_NAME *buf)
80 EINA_MAGIC_CHECK_STRBUF(buf);
81 EINA_MAGIC_SET(buf, EINA_MAGIC_NONE);
82 eina_strbuf_common_free(buf);
86 _FUNC_EXPAND(reset)(_STRBUF_STRUCT_NAME *buf)
88 EINA_MAGIC_CHECK_STRBUF(buf);
89 eina_strbuf_common_reset(_STRBUF_CSIZE, buf);
93 _FUNC_EXPAND(append_length)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t length)
95 EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
96 return eina_strbuf_common_append_length(_STRBUF_CSIZE, buf, (const void *) str, length);
100 _FUNC_EXPAND(insert_length)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t length, size_t pos)
102 EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
103 return eina_strbuf_common_insert_length(_STRBUF_CSIZE, buf, (const void *) str, length, pos);
107 _FUNC_EXPAND(append_char)(_STRBUF_STRUCT_NAME *buf, _STRBUF_DATA_TYPE c)
109 EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
110 return eina_strbuf_common_append_char(_STRBUF_CSIZE, buf, (const void *) &c);
114 _FUNC_EXPAND(insert_char)(_STRBUF_STRUCT_NAME *buf, _STRBUF_DATA_TYPE c, size_t pos)
116 EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
117 return eina_strbuf_common_insert_char(_STRBUF_CSIZE, buf, (const void *) &c, pos);
121 _FUNC_EXPAND(remove)(_STRBUF_STRUCT_NAME *buf, size_t start, size_t end)
123 EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
124 return eina_strbuf_common_remove(_STRBUF_CSIZE, buf, start, end);
127 EAPI const _STRBUF_DATA_TYPE *
128 _FUNC_EXPAND(string_get)(const _STRBUF_STRUCT_NAME *buf)
130 EINA_MAGIC_CHECK_STRBUF(buf, NULL);
131 return (const _STRBUF_DATA_TYPE *) eina_strbuf_common_string_get(buf);
134 EAPI _STRBUF_DATA_TYPE *
135 _FUNC_EXPAND(string_steal)(_STRBUF_STRUCT_NAME *buf)
137 EINA_MAGIC_CHECK_STRBUF(buf, NULL);
138 return (_STRBUF_DATA_TYPE *) eina_strbuf_common_string_steal(_STRBUF_CSIZE, buf);
142 _FUNC_EXPAND(string_free)(_STRBUF_STRUCT_NAME *buf)
144 EINA_MAGIC_CHECK_STRBUF(buf);
145 eina_strbuf_common_string_free(_STRBUF_CSIZE, buf);
149 _FUNC_EXPAND(length_get)(const _STRBUF_STRUCT_NAME *buf)
151 EINA_MAGIC_CHECK_STRBUF(buf, 0);
152 return eina_strbuf_common_length_get(buf);