public: add generic implementation for Q_memmem

This commit is contained in:
Alibek Omarov 2023-01-03 06:58:58 +03:00
parent aa3a0fa392
commit 07e622f224
2 changed files with 18 additions and 0 deletions

View File

@ -372,6 +372,23 @@ qboolean Q_stricmpext( const char *pattern, const char *text )
return Q_strnicmpext( pattern, text, ~((size_t)0) );
}
const byte *Q_memmem( const byte *haystack, size_t haystacklen, const byte *needle, size_t needlelen )
{
const byte *i;
// quickly find first matching symbol
while( haystacklen && ( i = memchr( haystack, needle[0], haystacklen )))
{
if( !memcmp( i, needle, needlelen ))
return i;
haystacklen -= i - haystack;
haystack = i + 1;
}
return NULL;
}
const char* Q_timestamp( int format )
{
static string timestamp;

View File

@ -78,6 +78,7 @@ void Q_atov( float *vec, const char *str, size_t siz );
#define Q_strrchr strrchr
qboolean Q_stricmpext( const char *pattern, const char *text );
qboolean Q_strnicmpext( const char *pattern, const char *text, size_t minimumlen );
const byte *Q_memmem( const byte *haystack, size_t haystacklen, const byte *needle, size_t needlelen );
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 );