mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #1458
1458: Fix remaining issues from #1443 r=heinrich5991 a=Learath2 ^ Co-authored-by: Learath <learath2@gmail.com>
This commit is contained in:
commit
e87681c893
|
@ -3041,7 +3041,7 @@ unsigned str_quickhash(const char *str)
|
|||
return hash;
|
||||
}
|
||||
|
||||
static const char *str_token_next(const char *str, const char *delim, size_t *length)
|
||||
static const char *str_token_next(const char *str, const char *delim, int *length)
|
||||
{
|
||||
str += strspn(str, delim);
|
||||
if(!*str)
|
||||
|
@ -3051,34 +3051,14 @@ static const char *str_token_next(const char *str, const char *delim, size_t *le
|
|||
return str;
|
||||
}
|
||||
|
||||
int str_tokenize(const char *str, const char *delim, const char **state, char *buf, size_t bufsz)
|
||||
{
|
||||
const char *ret = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
if((!str && !state) || !buf)
|
||||
return -1;
|
||||
|
||||
str = str ? str : *state;
|
||||
|
||||
if(!(ret = str_token_next(str, delim, &len)))
|
||||
return -1;
|
||||
|
||||
*state = ret + len;
|
||||
len = bufsz > len ? len : bufsz - 1;
|
||||
mem_copy(buf, ret, len);
|
||||
buf[len] = '\0';
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int str_in_list(const char *list, const char *delim, const char *needle)
|
||||
{
|
||||
const char *tok = list;
|
||||
size_t len = 0, notfound = 1;
|
||||
int len = 0, notfound = 1, needlelen = str_length(needle);
|
||||
|
||||
while(notfound && (tok = str_token_next(tok, delim, &len))){
|
||||
notfound = str_comp_num(tok, needle, len);
|
||||
while(notfound && (tok = str_token_next(tok, delim, &len)))
|
||||
{
|
||||
notfound = needlelen != len || str_comp_num(tok, needle, len);
|
||||
tok = tok + len;
|
||||
}
|
||||
|
||||
|
|
|
@ -1831,25 +1831,6 @@ int str_utf16le_encode(char *ptr, int chr);
|
|||
*/
|
||||
int str_utf8_check(const char *str);
|
||||
|
||||
/*
|
||||
Function: str_tokenize
|
||||
Tokenizes a string.
|
||||
|
||||
Parameters:
|
||||
str - Pointer to string.
|
||||
delim - Delimiter for tokenization.
|
||||
state - Pointer to remaining string
|
||||
buf - Buffer to store token in.
|
||||
bufsz - Size of the buffer.
|
||||
|
||||
Returns:
|
||||
The number of characters written to buf or -1 for end of string
|
||||
|
||||
Remarks:
|
||||
- The token is always null-terminated.
|
||||
*/
|
||||
int str_tokenize(const char *str, const char *delim, const char **state, char *buf, size_t bufsz);
|
||||
|
||||
/*
|
||||
Function: str_in_list
|
||||
Checks if needle is in list delimited by delim
|
||||
|
|
|
@ -359,7 +359,7 @@ MACRO_CONFIG_INT(SvSoloServer, sv_solo_server, 0, 0, 1, CFGFLAG_SERVER|CFGFLAG_G
|
|||
MACRO_CONFIG_STR(SvClientSuggestion, sv_client_suggestion, 128, "Get DDNet client from DDNet.tw to use all features on DDNet!", CFGFLAG_SERVER, "Broadcast to display to players without DDNet client")
|
||||
MACRO_CONFIG_STR(SvClientSuggestionOld, sv_client_suggestion_old, 128, "Your DDNet client is old, update it on DDNet.tw!", CFGFLAG_SERVER, "Broadcast to display to players with an old version of DDNet client")
|
||||
MACRO_CONFIG_STR(SvClientSuggestionBot, sv_client_suggestion_bot, 128, "Your client has bots and can be remotely controlled!\nPlease use another client like DDNet client from DDNet.tw", CFGFLAG_SERVER, "Broadcast to display to players with a known botting client")
|
||||
MACRO_CONFIG_STR(SvBannedVersions, sv_banned_versions, 128, "", CFGFLAG_SERVER, "Comma seperated list of banned clients to be kicked on join")
|
||||
MACRO_CONFIG_STR(SvBannedVersions, sv_banned_versions, 128, "", CFGFLAG_SERVER, "Comma separated list of banned clients to be kicked on join")
|
||||
|
||||
// netlimit
|
||||
MACRO_CONFIG_INT(SvNetlimit, sv_netlimit, 0, 0, 10000, CFGFLAG_SERVER, "Netlimit: Maximum amount of traffic a client is allowed to use (in kb/s)")
|
||||
|
|
|
@ -136,23 +136,6 @@ TEST(Str, HexDecode)
|
|||
EXPECT_EQ(str_hex_decode(aOut, 4, "41424344"), 0); EXPECT_STREQ(aOut, "ABCD");
|
||||
}
|
||||
|
||||
TEST(Str, Tokenize)
|
||||
{
|
||||
char aTest[] = "GER,RUS,ZAF,BRA,CAN";
|
||||
const char *aOut[] = {"GER", "RUS", "ZAF", "BRA", "CAN"};
|
||||
const char *pState;
|
||||
char aBuf[4];
|
||||
|
||||
int n = 0;
|
||||
str_tokenize(aTest, ",", &pState, aBuf, sizeof aBuf);
|
||||
do {
|
||||
EXPECT_STREQ(aOut[n++], aBuf);
|
||||
} while(str_tokenize(NULL, ",", &pState, aBuf, sizeof aBuf) >= 0);
|
||||
|
||||
char aTest2[] = "";
|
||||
EXPECT_EQ(str_tokenize(aTest2, ",", &pState, aBuf, sizeof aBuf), -1);
|
||||
}
|
||||
|
||||
TEST(Str, InList)
|
||||
{
|
||||
char aTest[] = "GER,RUS,ZAF,BRA,CAN";
|
||||
|
@ -164,4 +147,8 @@ TEST(Str, InList)
|
|||
|
||||
EXPECT_FALSE(str_in_list(aTest, ",", "CHN"));
|
||||
EXPECT_FALSE(str_in_list(aTest, ",", "R,R"));
|
||||
|
||||
EXPECT_FALSE(str_in_list("abc,xyz", ",", "abcdef"));
|
||||
EXPECT_FALSE(str_in_list("", ",", ""));
|
||||
EXPECT_FALSE(str_in_list("", ",", "xyz"));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue