2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-22 09:56:22 +01:00

public: add Q_splitstr function

This commit is contained in:
Alibek Omarov 2024-11-17 05:34:29 +03:00
parent 0813d2c7ce
commit ac7617990a

View File

@ -284,6 +284,34 @@ static inline const char *Q_strchrnul( const char *s, int c )
}
#endif // !HAVE_STRCHRNUL
/*
===========
Q_splitstr
splits strings by a character
if handler returns nonzero value, exists with that value
===========
*/
static inline int Q_splitstr( char *str, int delim, void *userdata,
int (*handler)( char *prev, char *next, void *userdata ))
{
char *prev = str;
char *next = Q_strchrnul( prev, delim );
int ret = 0;
for( ; ; prev = next + 1, next = Q_strchrnul( prev, delim ))
{
int ch = *next; // save next value if it's modified by handler
ret = handler( prev, next, userdata );
if( !ch || ret != 0 )
break;
}
return ret;
}
#ifdef __cplusplus
}
#endif