From 185f35390239fb98d3afb9ee080946ede1cfaf7e Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Thu, 26 Jul 2018 14:04:44 +0200 Subject: [PATCH] Return a pointer from `str_endswith` as well (cherry picked from commit 9fcf5480f8cc2134007f61bf1e8cda7d1a6881de) --- src/base/system.c | 13 +++++++++++-- src/base/system.h | 6 +++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/base/system.c b/src/base/system.c index 9a5878eb3..626acc2ba 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -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 suffixl = str_length(suffix); + const char *strsuffix; if(strl < suffixl) { 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) diff --git a/src/base/system.h b/src/base/system.h index ed27da081..fff31dd61 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -1039,13 +1039,13 @@ const char *str_startswith(const char *str, const char *prefix); suffix - Suffix to look for. Returns: - 0 - String suffix is not a suffix of string str - 1 - String suffix is a suffix of string str + A pointer to the beginning of the suffix in the string str, or + 0 if the string suffix isn't a suffix of the string str. Remarks: - 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