diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/eina/src/lib/eina_strbuf.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/eina/src/lib/eina_strbuf.c')
-rw-r--r-- | libraries/eina/src/lib/eina_strbuf.c | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/libraries/eina/src/lib/eina_strbuf.c b/libraries/eina/src/lib/eina_strbuf.c new file mode 100644 index 0000000..74b1eb9 --- /dev/null +++ b/libraries/eina/src/lib/eina_strbuf.c | |||
@@ -0,0 +1,202 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <string.h> | ||
7 | #include <ctype.h> | ||
8 | |||
9 | #ifdef HAVE_EVIL | ||
10 | # include <Evil.h> | ||
11 | #endif | ||
12 | |||
13 | #include "eina_private.h" | ||
14 | #include "eina_str.h" | ||
15 | #include "eina_strbuf_common.h" | ||
16 | #include "eina_unicode.h" | ||
17 | |||
18 | /*============================================================================* | ||
19 | * Local * | ||
20 | *============================================================================*/ | ||
21 | |||
22 | /** | ||
23 | * @cond LOCAL | ||
24 | */ | ||
25 | |||
26 | #ifdef _STRBUF_DATA_TYPE | ||
27 | # undef _STRBUF_DATA_TYPE | ||
28 | #endif | ||
29 | |||
30 | #ifdef _STRBUF_CSIZE | ||
31 | # undef _STRBUF_CSIZE | ||
32 | #endif | ||
33 | |||
34 | #ifdef _STRBUF_STRUCT_NAME | ||
35 | # undef _STRBUF_STRUCT_NAME | ||
36 | #endif | ||
37 | |||
38 | #ifdef _STRBUF_STRLEN_FUNC | ||
39 | # undef _STRBUF_STRLEN_FUNC | ||
40 | #endif | ||
41 | |||
42 | #ifdef _STRBUF_STRESCAPE_FUNC | ||
43 | # undef _STRBUF_STRESCAPE_FUNC | ||
44 | #endif | ||
45 | |||
46 | #ifdef _STRBUF_MAGIC | ||
47 | # undef _STRBUF_MAGIC | ||
48 | #endif | ||
49 | |||
50 | #ifdef _STRBUF_MAGIC_STR | ||
51 | # undef _STRBUF_MAGIC_STR | ||
52 | #endif | ||
53 | |||
54 | #ifdef _FUNC_EXPAND | ||
55 | # undef _FUNC_EXPAND | ||
56 | #endif | ||
57 | |||
58 | |||
59 | #define _STRBUF_DATA_TYPE char | ||
60 | #define _STRBUF_CSIZE sizeof(_STRBUF_DATA_TYPE) | ||
61 | #define _STRBUF_STRUCT_NAME Eina_Strbuf | ||
62 | #define _STRBUF_STRLEN_FUNC(x) strlen(x) | ||
63 | #define _STRBUF_STRESCAPE_FUNC(x) eina_str_escape(x) | ||
64 | #define _STRBUF_MAGIC EINA_MAGIC_STRBUF | ||
65 | #define _STRBUF_MAGIC_STR __STRBUF_MAGIC_STR | ||
66 | static const char __STRBUF_MAGIC_STR[] = "Eina Strbuf"; | ||
67 | |||
68 | #define _FUNC_EXPAND(y) eina_strbuf_ ## y | ||
69 | |||
70 | /** | ||
71 | * @endcond | ||
72 | */ | ||
73 | |||
74 | |||
75 | /*============================================================================* | ||
76 | * Global * | ||
77 | *============================================================================*/ | ||
78 | |||
79 | |||
80 | /*============================================================================* | ||
81 | * API * | ||
82 | *============================================================================*/ | ||
83 | |||
84 | |||
85 | EAPI Eina_Bool | ||
86 | eina_strbuf_append_printf(Eina_Strbuf *buf, const char *fmt, ...) | ||
87 | { | ||
88 | va_list args; | ||
89 | char *str; | ||
90 | size_t len; | ||
91 | Eina_Bool ret; | ||
92 | |||
93 | va_start(args, fmt); | ||
94 | len = vasprintf(&str, fmt, args); | ||
95 | va_end(args); | ||
96 | |||
97 | if (len <= 0 || !str) | ||
98 | return EINA_FALSE; | ||
99 | |||
100 | ret = eina_strbuf_append_length(buf, str, len); | ||
101 | free(str); | ||
102 | return ret; | ||
103 | } | ||
104 | |||
105 | EAPI Eina_Bool | ||
106 | eina_strbuf_append_vprintf(Eina_Strbuf *buf, const char *fmt, va_list args) | ||
107 | { | ||
108 | char *str; | ||
109 | size_t len; | ||
110 | Eina_Bool ret; | ||
111 | |||
112 | len = vasprintf(&str, fmt, args); | ||
113 | |||
114 | if (len <= 0 || !str) | ||
115 | return EINA_FALSE; | ||
116 | |||
117 | ret = eina_strbuf_append_length(buf, str, len); | ||
118 | free(str); | ||
119 | return ret; | ||
120 | } | ||
121 | |||
122 | EAPI Eina_Bool | ||
123 | eina_strbuf_insert_printf(Eina_Strbuf *buf, const char *fmt, size_t pos, ...) | ||
124 | { | ||
125 | va_list args; | ||
126 | char *str; | ||
127 | size_t len; | ||
128 | Eina_Bool ret; | ||
129 | |||
130 | va_start(args, pos); | ||
131 | len = vasprintf(&str, fmt, args); | ||
132 | va_end(args); | ||
133 | |||
134 | if (len <= 0 || !str) | ||
135 | return EINA_FALSE; | ||
136 | |||
137 | ret = eina_strbuf_insert(buf, str, pos); | ||
138 | free(str); | ||
139 | return ret; | ||
140 | } | ||
141 | |||
142 | EAPI Eina_Bool | ||
143 | eina_strbuf_insert_vprintf(Eina_Strbuf *buf, | ||
144 | const char *fmt, | ||
145 | size_t pos, | ||
146 | va_list args) | ||
147 | { | ||
148 | char *str; | ||
149 | size_t len; | ||
150 | Eina_Bool ret; | ||
151 | |||
152 | len = vasprintf(&str, fmt, args); | ||
153 | |||
154 | if (len <= 0 || !str) | ||
155 | return EINA_FALSE; | ||
156 | |||
157 | ret = eina_strbuf_insert(buf, str, pos); | ||
158 | free(str); | ||
159 | return ret; | ||
160 | } | ||
161 | |||
162 | EAPI void | ||
163 | eina_strbuf_trim(Eina_Strbuf *buf) | ||
164 | { | ||
165 | char *c = buf->buf; | ||
166 | |||
167 | while (buf->len > 0 && isspace(((unsigned char*)(buf->buf))[buf->len - 1])) | ||
168 | buf->len--; | ||
169 | while (buf->len > 0 && isspace(*c)) | ||
170 | { | ||
171 | c++; | ||
172 | buf->len--; | ||
173 | } | ||
174 | memmove(buf->buf, c, buf->len); | ||
175 | ((unsigned char *)buf->buf)[buf->len] = '\0'; | ||
176 | } | ||
177 | |||
178 | EAPI void | ||
179 | eina_strbuf_ltrim(Eina_Strbuf *buf) | ||
180 | { | ||
181 | char *c = buf->buf; | ||
182 | |||
183 | while (buf->len > 0 && isspace(*c)) | ||
184 | { | ||
185 | c++; | ||
186 | buf->len--; | ||
187 | } | ||
188 | memmove(buf->buf, c, buf->len); | ||
189 | ((unsigned char *)buf->buf)[buf->len] = '\0'; | ||
190 | } | ||
191 | |||
192 | EAPI void | ||
193 | eina_strbuf_rtrim(Eina_Strbuf *buf) | ||
194 | { | ||
195 | while (buf->len > 0 && isspace(((unsigned char*)(buf->buf))[buf->len - 1])) | ||
196 | buf->len--; | ||
197 | ((unsigned char *)buf->buf)[buf->len] = '\0'; | ||
198 | } | ||
199 | |||
200 | /* Unicode */ | ||
201 | |||
202 | #include "eina_strbuf_template_c.x" | ||