Browse Source

public: introduce Q_strnicmpext function

The goal is to provide both string compare with fixed length and simple pattern match
pull/2/head
Alibek Omarov 2 years ago
parent
commit
7f1bb9b4a6
  1. 12
      public/crtlib.c
  2. 3
      public/crtlib.h

12
public/crtlib.c

@ -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; char c;
while(( c = *pattern++ ) != '\0' ) while(( c = *pattern++ ) != '\0' )
{ {
i++;
switch( c ) switch( c )
{ {
case '?': case '?':
@ -361,7 +364,12 @@ qboolean Q_stricmpext( const char *pattern, const char *text )
return false; 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 ) const char* Q_timestamp( int format )

3
public/crtlib.h

@ -76,7 +76,8 @@ float Q_atof( const char *str );
void Q_atov( float *vec, const char *str, size_t siz ); void Q_atov( float *vec, const char *str, size_t siz );
#define Q_strchr strchr #define Q_strchr strchr
#define Q_strrchr strrchr #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 ); const char *Q_timestamp( int format );
#define Q_vsprintf( buffer, format, args ) Q_vsnprintf( buffer, 99999, format, args ) #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 ); int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args );

Loading…
Cancel
Save