diff options
author | David Walter Seikel | 2012-04-22 09:19:23 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-04-22 09:19:23 +1000 |
commit | c963d75dfdeec11f82e79e727062fbf89afa2c04 (patch) | |
tree | 895633dbf641110be46f117c29890c49b3ffc0bd /libraries/eina/src/lib/eina_unicode.c | |
parent | Adding the new extantz viewer and grid manager. (diff) | |
download | SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.zip SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.gz SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.bz2 SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.xz |
Update EFL to latest beta.
Diffstat (limited to '')
-rw-r--r-- | libraries/eina/src/lib/eina_unicode.c | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/libraries/eina/src/lib/eina_unicode.c b/libraries/eina/src/lib/eina_unicode.c index 342e3cb..7505906 100644 --- a/libraries/eina/src/lib/eina_unicode.c +++ b/libraries/eina/src/lib/eina_unicode.c | |||
@@ -15,10 +15,18 @@ | |||
15 | * You should have received a copy of the GNU Lesser General Public | 15 | * You should have received a copy of the GNU Lesser General Public |
16 | * License along with this library; | 16 | * License along with this library; |
17 | * if not, see <http://www.gnu.org/licenses/>. | 17 | * if not, see <http://www.gnu.org/licenses/>. |
18 | |||
19 | */ | 18 | */ |
20 | 19 | ||
21 | #include <Eina.h> | 20 | #ifdef HAVE_CONFIG_H |
21 | # include "config.h" | ||
22 | #endif | ||
23 | |||
24 | #include "eina_config.h" | ||
25 | #include "eina_private.h" | ||
26 | #include <string.h> | ||
27 | |||
28 | /* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */ | ||
29 | #include "eina_safety_checks.h" | ||
22 | #include "eina_unicode.h" | 30 | #include "eina_unicode.h" |
23 | 31 | ||
24 | /* FIXME: check if sizeof(wchar_t) == sizeof(Eina_Unicode) if so, | 32 | /* FIXME: check if sizeof(wchar_t) == sizeof(Eina_Unicode) if so, |
@@ -30,6 +38,9 @@ EAPI const Eina_Unicode *EINA_UNICODE_EMPTY_STRING = _EINA_UNICODE_EMPTY_STRING; | |||
30 | EAPI int | 38 | EAPI int |
31 | eina_unicode_strcmp(const Eina_Unicode *a, const Eina_Unicode *b) | 39 | eina_unicode_strcmp(const Eina_Unicode *a, const Eina_Unicode *b) |
32 | { | 40 | { |
41 | EINA_SAFETY_ON_NULL_RETURN_VAL(a, -1); | ||
42 | EINA_SAFETY_ON_NULL_RETURN_VAL(b, -1); | ||
43 | |||
33 | for (; *a && *a == *b; a++, b++) | 44 | for (; *a && *a == *b; a++, b++) |
34 | ; | 45 | ; |
35 | if (*a == *b) | 46 | if (*a == *b) |
@@ -45,6 +56,9 @@ eina_unicode_strcpy(Eina_Unicode *dest, const Eina_Unicode *source) | |||
45 | { | 56 | { |
46 | Eina_Unicode *ret = dest; | 57 | Eina_Unicode *ret = dest; |
47 | 58 | ||
59 | EINA_SAFETY_ON_NULL_RETURN_VAL(dest, NULL); | ||
60 | EINA_SAFETY_ON_NULL_RETURN_VAL(source, NULL); | ||
61 | |||
48 | while (*source) | 62 | while (*source) |
49 | *dest++ = *source++; | 63 | *dest++ = *source++; |
50 | *dest = 0; | 64 | *dest = 0; |
@@ -56,6 +70,9 @@ eina_unicode_strncpy(Eina_Unicode *dest, const Eina_Unicode *source, size_t n) | |||
56 | { | 70 | { |
57 | Eina_Unicode *ret = dest; | 71 | Eina_Unicode *ret = dest; |
58 | 72 | ||
73 | EINA_SAFETY_ON_NULL_RETURN_VAL(dest, NULL); | ||
74 | EINA_SAFETY_ON_NULL_RETURN_VAL(source, NULL); | ||
75 | |||
59 | for ( ; n && *source ; n--) | 76 | for ( ; n && *source ; n--) |
60 | *dest++ = *source++; | 77 | *dest++ = *source++; |
61 | for (; n; n--) | 78 | for (; n; n--) |
@@ -67,6 +84,9 @@ EAPI size_t | |||
67 | eina_unicode_strlen(const Eina_Unicode *ustr) | 84 | eina_unicode_strlen(const Eina_Unicode *ustr) |
68 | { | 85 | { |
69 | const Eina_Unicode *end; | 86 | const Eina_Unicode *end; |
87 | |||
88 | EINA_SAFETY_ON_NULL_RETURN_VAL(ustr, 0); | ||
89 | |||
70 | for (end = ustr; *end; end++) | 90 | for (end = ustr; *end; end++) |
71 | ; | 91 | ; |
72 | return end - ustr; | 92 | return end - ustr; |
@@ -77,6 +97,9 @@ eina_unicode_strnlen(const Eina_Unicode *ustr, int n) | |||
77 | { | 97 | { |
78 | const Eina_Unicode *end; | 98 | const Eina_Unicode *end; |
79 | const Eina_Unicode *last = ustr + n; /* technically not portable ;-) */ | 99 | const Eina_Unicode *last = ustr + n; /* technically not portable ;-) */ |
100 | |||
101 | EINA_SAFETY_ON_NULL_RETURN_VAL(ustr, 0); | ||
102 | |||
80 | for (end = ustr; end < last && *end; end++) | 103 | for (end = ustr; end < last && *end; end++) |
81 | ; | 104 | ; |
82 | return end - ustr; | 105 | return end - ustr; |
@@ -90,7 +113,9 @@ eina_unicode_strndup(const Eina_Unicode *text, size_t n) | |||
90 | { | 113 | { |
91 | Eina_Unicode *ustr; | 114 | Eina_Unicode *ustr; |
92 | 115 | ||
93 | ustr = (Eina_Unicode *) malloc((n + 1) * sizeof(Eina_Unicode)); | 116 | EINA_SAFETY_ON_NULL_RETURN_VAL(text, NULL); |
117 | |||
118 | ustr = malloc((n + 1) * sizeof(Eina_Unicode)); | ||
94 | memcpy(ustr, text, n * sizeof(Eina_Unicode)); | 119 | memcpy(ustr, text, n * sizeof(Eina_Unicode)); |
95 | ustr[n] = 0; | 120 | ustr[n] = 0; |
96 | return ustr; | 121 | return ustr; |
@@ -101,6 +126,8 @@ eina_unicode_strdup(const Eina_Unicode *text) | |||
101 | { | 126 | { |
102 | size_t len; | 127 | size_t len; |
103 | 128 | ||
129 | EINA_SAFETY_ON_NULL_RETURN_VAL(text, NULL); | ||
130 | |||
104 | len = eina_unicode_strlen(text); | 131 | len = eina_unicode_strlen(text); |
105 | return eina_unicode_strndup(text, len); | 132 | return eina_unicode_strndup(text, len); |
106 | } | 133 | } |
@@ -110,6 +137,9 @@ eina_unicode_strstr(const Eina_Unicode *haystack, const Eina_Unicode *needle) | |||
110 | { | 137 | { |
111 | const Eina_Unicode *i, *j; | 138 | const Eina_Unicode *i, *j; |
112 | 139 | ||
140 | EINA_SAFETY_ON_NULL_RETURN_VAL(haystack, NULL); | ||
141 | EINA_SAFETY_ON_NULL_RETURN_VAL(needle, NULL); | ||
142 | |||
113 | for (i = haystack; *i; i++) | 143 | for (i = haystack; *i; i++) |
114 | { | 144 | { |
115 | haystack = i; /* set this location as the base position */ | 145 | haystack = i; /* set this location as the base position */ |
@@ -131,6 +161,8 @@ eina_unicode_escape(const Eina_Unicode *str) | |||
131 | Eina_Unicode *s2, *d; | 161 | Eina_Unicode *s2, *d; |
132 | const Eina_Unicode *s; | 162 | const Eina_Unicode *s; |
133 | 163 | ||
164 | EINA_SAFETY_ON_NULL_RETURN_VAL(str, NULL); | ||
165 | |||
134 | s2 = malloc((eina_unicode_strlen(str) * 2) + 1); | 166 | s2 = malloc((eina_unicode_strlen(str) * 2) + 1); |
135 | if (!s2) | 167 | if (!s2) |
136 | return NULL; | 168 | return NULL; |
@@ -165,6 +197,9 @@ eina_unicode_utf8_get_next(const char *buf, int *iindex) | |||
165 | Eina_Unicode r; | 197 | Eina_Unicode r; |
166 | unsigned char d; | 198 | unsigned char d; |
167 | 199 | ||
200 | EINA_SAFETY_ON_NULL_RETURN_VAL(buf, 0); | ||
201 | EINA_SAFETY_ON_NULL_RETURN_VAL(iindex, 0); | ||
202 | |||
168 | /* if this char is the null terminator, exit */ | 203 | /* if this char is the null terminator, exit */ |
169 | if ((d = buf[ind++]) == 0) return 0; | 204 | if ((d = buf[ind++]) == 0) return 0; |
170 | 205 | ||
@@ -266,8 +301,12 @@ error: | |||
266 | EAPI Eina_Unicode | 301 | EAPI Eina_Unicode |
267 | eina_unicode_utf8_get_prev(const char *buf, int *iindex) | 302 | eina_unicode_utf8_get_prev(const char *buf, int *iindex) |
268 | { | 303 | { |
269 | int r; | 304 | int r, ind; |
270 | int ind = *iindex; | 305 | |
306 | EINA_SAFETY_ON_NULL_RETURN_VAL(buf, 0); | ||
307 | EINA_SAFETY_ON_NULL_RETURN_VAL(iindex, 0); | ||
308 | |||
309 | ind = *iindex; | ||
271 | /* First obtain the codepoint at iindex */ | 310 | /* First obtain the codepoint at iindex */ |
272 | r = eina_unicode_utf8_get_next(buf, &ind); | 311 | r = eina_unicode_utf8_get_next(buf, &ind); |
273 | 312 | ||
@@ -292,6 +331,8 @@ eina_unicode_utf8_get_len(const char *buf) | |||
292 | /* returns the number of utf8 characters (not bytes) in the string */ | 331 | /* returns the number of utf8 characters (not bytes) in the string */ |
293 | int i = 0, len = 0; | 332 | int i = 0, len = 0; |
294 | 333 | ||
334 | EINA_SAFETY_ON_NULL_RETURN_VAL(buf, 0); | ||
335 | |||
295 | while (eina_unicode_utf8_get_next(buf, &i)) | 336 | while (eina_unicode_utf8_get_next(buf, &i)) |
296 | len++; | 337 | len++; |
297 | 338 | ||
@@ -306,6 +347,8 @@ eina_unicode_utf8_to_unicode(const char *utf, int *_len) | |||
306 | int ind; | 347 | int ind; |
307 | Eina_Unicode *buf, *uind; | 348 | Eina_Unicode *buf, *uind; |
308 | 349 | ||
350 | EINA_SAFETY_ON_NULL_RETURN_VAL(utf, NULL); | ||
351 | |||
309 | len = eina_unicode_utf8_get_len(utf); | 352 | len = eina_unicode_utf8_get_len(utf); |
310 | if (_len) | 353 | if (_len) |
311 | *_len = len; | 354 | *_len = len; |
@@ -328,6 +371,8 @@ eina_unicode_unicode_to_utf8(const Eina_Unicode *uni, int *_len) | |||
328 | char *ind; | 371 | char *ind; |
329 | int ulen, len; | 372 | int ulen, len; |
330 | 373 | ||
374 | EINA_SAFETY_ON_NULL_RETURN_VAL(uni, NULL); | ||
375 | |||
331 | ulen = eina_unicode_strlen(uni); | 376 | ulen = eina_unicode_strlen(uni); |
332 | buf = (char *) calloc(ulen + 1, EINA_UNICODE_UTF8_BYTES_PER_CHAR); | 377 | buf = (char *) calloc(ulen + 1, EINA_UNICODE_UTF8_BYTES_PER_CHAR); |
333 | 378 | ||