# HG changeset patch # User Matti Hamalainen # Date 1400355577 -10800 # Node ID 30690f5c4cae2a996be40d1dd054fe31ce132493 # Parent d3d3cd41a95a03dd5e59c8df6c22005ed19dc5e6 Add new function th_strrcasecmp(). diff -r d3d3cd41a95a -r 30690f5c4cae th_string.c --- a/th_string.c Sat May 17 22:39:27 2014 +0300 +++ b/th_string.c Sat May 17 22:39:37 2014 +0300 @@ -158,6 +158,29 @@ } +/* Check if end of the given string str matches needle + * case-insensitively, return pointer to start of the match, + * if found, NULL otherwise. + */ +char *th_strrcasecmp(char *str, const char *needle) +{ + if (str == NULL || needle == NULL) + return NULL; + + const size_t + slen = strlen(str), + nlen = strlen(needle); + + if (slen < nlen) + return NULL; + + if (th_strcasecmp(str - nlen - 1, needle) == 0) + return str - nlen - 1; + else + return NULL; +} + + /* Remove all occurences of control characters, in-place. * Resulting string is always shorter or same length than original. */ diff -r d3d3cd41a95a -r 30690f5c4cae th_string.h --- a/th_string.h Sat May 17 22:39:27 2014 +0300 +++ b/th_string.h Sat May 17 22:39:37 2014 +0300 @@ -47,6 +47,7 @@ int th_strcasecmp(const char *, const char *); int th_strncasecmp(const char *, const char *, size_t); +char *th_strrcasecmp(char *str, const char *needle); void th_strip_ctrlchars(char *); char *th_strdup_vprintf(const char *, va_list);