mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 09:34:19 +00:00
Add tests for str_countchr
, update documentation
This commit is contained in:
parent
b029452e99
commit
3383b7dc0f
|
@ -1601,21 +1601,20 @@ const char *str_find(const char *haystack, const char *needle);
|
|||
*/
|
||||
const char *str_rchr(const char *haystack, char needle);
|
||||
|
||||
/*
|
||||
Function: str_countchr
|
||||
Counts the number of occurrences of a character in a string.
|
||||
/**
|
||||
* Counts the number of occurrences of a character in a string.
|
||||
*
|
||||
* @ingroup Strings
|
||||
*
|
||||
* @param haystack String to count in
|
||||
* @param needle Character to count
|
||||
|
||||
Parameters:
|
||||
haystack - String to count in
|
||||
needle - Character to count
|
||||
|
||||
Returns:
|
||||
The number of characters in the haystack string matching
|
||||
the needle character.
|
||||
|
||||
Remarks:
|
||||
- The strings are treated as zero-terminated strings.
|
||||
*/
|
||||
* @return The number of characters in the haystack string matching
|
||||
* the needle character.
|
||||
*
|
||||
* @remark The strings are treated as zero-terminated strings.
|
||||
* @remark The number of zero-terminator characters cannot be counted.
|
||||
*/
|
||||
int str_countchr(const char *haystack, char needle);
|
||||
|
||||
/*
|
||||
|
|
|
@ -728,3 +728,16 @@ TEST(Str, RightChar)
|
|||
EXPECT_EQ(str_rchr(pStr, '\0'), pStr + str_length(pStr));
|
||||
EXPECT_EQ(str_rchr(pStr, 'y'), nullptr);
|
||||
}
|
||||
|
||||
TEST(Str, CountChar)
|
||||
{
|
||||
const char *pStr = "a bb ccc dddd eeeee";
|
||||
EXPECT_EQ(str_countchr(pStr, 'a'), 1);
|
||||
EXPECT_EQ(str_countchr(pStr, 'b'), 2);
|
||||
EXPECT_EQ(str_countchr(pStr, 'c'), 3);
|
||||
EXPECT_EQ(str_countchr(pStr, 'd'), 4);
|
||||
EXPECT_EQ(str_countchr(pStr, 'e'), 5);
|
||||
EXPECT_EQ(str_countchr(pStr, ' '), 10);
|
||||
EXPECT_EQ(str_countchr(pStr, '\0'), 0);
|
||||
EXPECT_EQ(str_countchr(pStr, 'y'), 0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue