aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/lib/eina_strbuf_template_c.x
blob: e8c3b617d3bbf0e4615bd9491220b247cdb7abdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */

/* This file should be included from files implementing strbuf.
   The including file should define the following macros:
 * _STRBUF_DATA_TYPE
 * _STRBUF_CSIZE
 * _STRBUF_STRUCT_NAME
 * _STRBUF_STRLEN_FUNC(x)
 * _STRBUF_STRESCAPE_FUNC(x)
 * _STRBUF_STRSTR_FUNC(x, y)
 * _STRBUF_MAGIC
 * _STRBUF_MAGIC_STR
 * See how it's done in eina_ustrbuf.c and eina_strbuf.c. This just makes things
 * a lot easier since those are essentially the same just with different sizes.
 */

#include "eina_binbuf_template_c.x"

/*============================================================================*
 *                                   API                                      *
 *============================================================================*/

EAPI _STRBUF_STRUCT_NAME *
_FUNC_EXPAND(manage_new)(_STRBUF_DATA_TYPE *str)
{
   _STRBUF_STRUCT_NAME *buf = eina_strbuf_common_manage_new(_STRBUF_CSIZE,
	 (void *) str, _STRBUF_STRLEN_FUNC(str));
   EINA_MAGIC_SET(buf, _STRBUF_MAGIC);
   return buf;
}

EAPI Eina_Bool
_FUNC_EXPAND(append)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str)
{
   EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
   return eina_strbuf_common_append(_STRBUF_CSIZE, buf, (const void *) str, _STRBUF_STRLEN_FUNC(str));
}

EAPI Eina_Bool
_FUNC_EXPAND(append_escaped)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str)
{
   _STRBUF_DATA_TYPE *esc;
   Eina_Bool ret;

   EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
   esc = _STRBUF_STRESCAPE_FUNC(str);
   if (!esc) {
      return _FUNC_EXPAND(append)(buf, str);
   }
   ret = _FUNC_EXPAND(append)(buf, esc);
   if (esc)
      free(esc);

   return ret;
}

EAPI Eina_Bool
_FUNC_EXPAND(append_n)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t maxlen)
{
   EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
   return eina_strbuf_common_append_n(_STRBUF_CSIZE, buf, (const void *) str, _STRBUF_STRLEN_FUNC(str), maxlen);
}

EAPI Eina_Bool
_FUNC_EXPAND(insert)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t pos)
{
   EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
   return eina_strbuf_common_insert(_STRBUF_CSIZE, buf, (const void *) str, _STRBUF_STRLEN_FUNC(str), pos);
}

EAPI Eina_Bool
_FUNC_EXPAND(insert_escaped)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t pos)
{
   _STRBUF_DATA_TYPE *esc;
   Eina_Bool ret;
   EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);

   esc = _STRBUF_STRESCAPE_FUNC(str);
   if (!esc) {
      return _FUNC_EXPAND(insert)(buf, str, pos);
   }
   ret = _FUNC_EXPAND(insert)(buf, esc, pos);
   if (esc)
      free(esc);

   return ret;
}

EAPI Eina_Bool
_FUNC_EXPAND(insert_n)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t maxlen, size_t pos)
{
   EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
   return eina_strbuf_common_insert_n(_STRBUF_CSIZE, buf, (const void *) str, _STRBUF_STRLEN_FUNC(str), maxlen, pos);
}