From edfbe7f65d4e0fbf875f8199f458f763c1dd5286 Mon Sep 17 00:00:00 2001 From: doursse Date: Thu, 25 Jan 2007 23:43:46 +0000 Subject: [PATCH] formatting. Add of ecore_str_has_prefix/suffix functions SVN revision: 28118 --- legacy/ecore/src/lib/ecore/Ecore_Str.h | 11 ++++- legacy/ecore/src/lib/ecore/ecore_str.c | 81 +++++++++++++++++++++++++--------- 2 files changed, 68 insertions(+), 24 deletions(-) diff --git a/legacy/ecore/src/lib/ecore/Ecore_Str.h b/legacy/ecore/src/lib/ecore/Ecore_Str.h index 76bc38b..4e4e5bf 100644 --- a/legacy/ecore/src/lib/ecore/Ecore_Str.h +++ b/legacy/ecore/src/lib/ecore/Ecore_Str.h @@ -38,10 +38,17 @@ extern "C" { # endif # endif - /* strlcpy implementation for libc's lacking it */ - EAPI size_t ecore_strlcpy(char *dst, const char *src, size_t siz); + +/* strlcpy implementation for libc's lacking it */ +EAPI size_t ecore_strlcpy(char *dst, const char *src, size_t siz); + +EAPI int ecore_str_has_prefix(const char *str, const char *prefix); + +EAPI int ecore_str_has_suffix(const char *str, const char *suffix); + #ifdef __cplusplus } #endif + #endif /* _ECORE_STR_H */ diff --git a/legacy/ecore/src/lib/ecore/ecore_str.c b/legacy/ecore/src/lib/ecore/ecore_str.c index 09f205e..9821446 100644 --- a/legacy/ecore/src/lib/ecore/ecore_str.c +++ b/legacy/ecore/src/lib/ecore/ecore_str.c @@ -29,28 +29,65 @@ size_t ecore_strlcpy(char *dst, const char *src, size_t siz) { #ifdef HAVE_STRLCPY - return strlcpy(dst, src, siz); + return strlcpy(dst, src, siz); #else - char *d = dst; - const char *s = src; - size_t n = siz; - - /* Copy as many bytes as will fit */ - if (n != 0) { - while (--n != 0) { - if ((*d++ = *s++) == '\0') - break; - } - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0) + { + while (--n != 0) + { + if ((*d++ = *s++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) + { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ #endif } + +int +ecore_str_has_prefix(const char *str, const char *prefix) +{ + int str_len; + int prefix_len; + + if (!str || !prefix) + return 0; + + str_len = strlen(str); + prefix_len = strlen(prefix); + if (prefix_len > str_len) + return 0; + + return (strncmp(str, prefix, prefix_len) == 0); +} + +int +ecore_str_has_suffix(const char *str, const char *suffix) +{ + int str_len; + int suffix_len; + + if (!str || !suffix) + return 0; + + str_len = strlen(str); + suffix_len = strlen(suffix); + if (suffix_len > str_len) + return 0; + + return (strncmp(str + str_len - suffix_len, suffix, suffix_len) == 0); +} -- 2.7.4