Enlightenment CVS committal Author : pfritz Project : e17 Module : libs/ecore
Dir : e17/libs/ecore/src/lib/ecore Modified Files: Ecore_Str.h ecore_str.c Log Message: add ecore_str_has_extension() =================================================================== RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/Ecore_Str.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -3 -r1.9 -r1.10 --- Ecore_Str.h 15 Mar 2007 22:21:26 -0000 1.9 +++ Ecore_Str.h 25 Jan 2008 18:10:46 -0000 1.10 @@ -46,6 +46,8 @@ EAPI int ecore_str_has_prefix(const char *str, const char *prefix); EAPI int ecore_str_has_suffix(const char *str, const char *suffix); +EAPI int ecore_str_has_extension(const char *str, const char *ext); + EAPI char **ecore_str_split(const char *string, const char *delimiter, int max_tokens); =================================================================== RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/ecore_str.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -3 -r1.9 -r1.10 --- ecore_str.c 22 Aug 2007 17:44:04 -0000 1.9 +++ ecore_str.c 25 Jan 2008 18:10:46 -0000 1.10 @@ -23,6 +23,8 @@ #include "ecore_private.h" #include "Ecore_Str.h" +static int ecore_str_has_suffix_helper(const char *str, const char *suffix, + int (*cmp)(const char *, const char *)); /** * @param dst the destination * @param src the source @@ -140,18 +142,47 @@ int ecore_str_has_suffix(const char *str, const char *suffix) { - size_t str_len; - size_t suffix_len; - CHECK_PARAM_POINTER_RETURN("str", str, 0); CHECK_PARAM_POINTER_RETURN("suffix", suffix, 0); + + return ecore_str_has_suffix_helper(str, suffix, strcmp); +} + +/** + * This function does the same like ecore_str_has_suffix(), but with a + * case insensitive compare. + * + * @param str the string to work with + * @param ext the extension to check for + * @return true if str has the given extension + * @brief checks if the string has the given extension + */ +int +ecore_str_has_extension(const char *str, const char *ext) +{ + CHECK_PARAM_POINTER_RETURN("str", str, 0); + CHECK_PARAM_POINTER_RETURN("ext", ext, 0); + + return ecore_str_has_suffix_helper(str, ext, strcasecmp); +} + +/* + * Internal helper function used by ecore_str_has_suffix() and + * ecore_str_has_extension() + */ +static int +ecore_str_has_suffix_helper(const char *str, const char *suffix, + int (*cmp)(const char *, const char *)) +{ + size_t str_len; + size_t suffix_len; 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); + return cmp(str + str_len - suffix_len, suffix) == 0; } /** ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs