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

public: introduce Q_strnicmpext function

The goal is to provide both string compare with fixed length and simple pattern match
This commit is contained in:
Alibek Omarov 2022-08-25 19:14:52 +03:00
parent 7341a6b020
commit 7f1bb9b4a6
2 changed files with 12 additions and 3 deletions

View File

@ -338,12 +338,15 @@ static qboolean Q_starcmp( const char *pattern, const char *text )
}
}
qboolean Q_stricmpext( const char *pattern, const char *text )
qboolean Q_strnicmpext( const char *pattern, const char *text, size_t minimumlength )
{
size_t i = 0;
char c;
while(( c = *pattern++ ) != '\0' )
{
i++;
switch( c )
{
case '?':
@ -361,7 +364,12 @@ qboolean Q_stricmpext( const char *pattern, const char *text )
return false;
}
}
return ( *text == '\0' );
return ( *text == '\0' ) || i == minimumlength;
}
qboolean Q_stricmpext( const char *pattern, const char *text )
{
return Q_strnicmpext( pattern, text, ~((size_t)0) );
}
const char* Q_timestamp( int format )

View File

@ -76,7 +76,8 @@ float Q_atof( const char *str );
void Q_atov( float *vec, const char *str, size_t siz );
#define Q_strchr strchr
#define Q_strrchr strrchr
qboolean Q_stricmpext( const char *s1, const char *s2 );
qboolean Q_stricmpext( const char *pattern, const char *text );
qboolean Q_strnicmpext( const char *pattern, const char *text, size_t minimumlen );
const char *Q_timestamp( int format );
#define Q_vsprintf( buffer, format, args ) Q_vsnprintf( buffer, 99999, format, args )
int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args );