Return a pointer from str_endswith as well

(cherry picked from commit 9fcf5480f8)
This commit is contained in:
heinrich5991 2018-07-26 14:04:44 +02:00
parent e162ee085f
commit 185f353902
2 changed files with 14 additions and 5 deletions

View file

@ -1964,15 +1964,24 @@ const char *str_startswith(const char *str, const char *prefix)
} }
} }
int str_endswith(const char *str, const char *suffix) const char *str_endswith(const char *str, const char *suffix)
{ {
int strl = str_length(str); int strl = str_length(str);
int suffixl = str_length(suffix); int suffixl = str_length(suffix);
const char *strsuffix;
if(strl < suffixl) if(strl < suffixl)
{ {
return 0; return 0;
} }
return str_comp(str + strl - suffixl, suffix) == 0; strsuffix = str + strl - suffixl;
if(str_comp(strsuffix, suffix) == 0)
{
return strsuffix;
}
else
{
return 0;
}
} }
const char *str_find_nocase(const char *haystack, const char *needle) const char *str_find_nocase(const char *haystack, const char *needle)

View file

@ -1039,13 +1039,13 @@ const char *str_startswith(const char *str, const char *prefix);
suffix - Suffix to look for. suffix - Suffix to look for.
Returns: Returns:
0 - String suffix is not a suffix of string str A pointer to the beginning of the suffix in the string str, or
1 - String suffix is a suffix of string str 0 if the string suffix isn't a suffix of the string str.
Remarks: Remarks:
- The strings are treated as zero-terminated strings. - The strings are treated as zero-terminated strings.
*/ */
int str_endswith(const char *str, const char *suffix); const char *str_endswith(const char *str, const char *suffix);
/* /*
Function: str_find_nocase Function: str_find_nocase