mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Return a pointer from str_endswith
as well
This commit is contained in:
parent
5c4e819e44
commit
9fcf5480f8
|
@ -2405,15 +2405,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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int min3(int a, int b, int c)
|
static int min3(int a, int b, int c)
|
||||||
|
|
|
@ -1213,13 +1213,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_utf8_dist
|
Function: str_utf8_dist
|
||||||
|
|
|
@ -69,9 +69,9 @@ TEST(Str, Startswith)
|
||||||
EXPECT_TRUE(str_startswith("поплавать", "по"));
|
EXPECT_TRUE(str_startswith("поплавать", "по"));
|
||||||
EXPECT_FALSE(str_startswith("плавать", "по"));
|
EXPECT_FALSE(str_startswith("плавать", "по"));
|
||||||
|
|
||||||
static const char ABCDEF[] = "abcdef";
|
static const char ABCDEFG[] = "abcdefg";
|
||||||
static const char ABC[] = "abc";
|
static const char ABC[] = "abc";
|
||||||
EXPECT_EQ(str_startswith(ABCDEF, ABC) - ABCDEF, str_length(ABC));
|
EXPECT_EQ(str_startswith(ABCDEFG, ABC) - ABCDEFG, str_length(ABC));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Str, Endswith)
|
TEST(Str, Endswith)
|
||||||
|
@ -87,4 +87,9 @@ TEST(Str, Endswith)
|
||||||
|
|
||||||
EXPECT_TRUE(str_endswith("люди", "юди"));
|
EXPECT_TRUE(str_endswith("люди", "юди"));
|
||||||
EXPECT_FALSE(str_endswith("люди", "любовь"));
|
EXPECT_FALSE(str_endswith("люди", "любовь"));
|
||||||
|
|
||||||
|
static const char ABCDEFG[] = "abcdefg";
|
||||||
|
static const char DEFG[] = "defg";
|
||||||
|
EXPECT_EQ(str_endswith(ABCDEFG, DEFG) - ABCDEFG,
|
||||||
|
str_length(ABCDEFG) - str_length(DEFG));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue