Implement a Q_strcasecmp() library replacement function.

It will be used in a later commit. While at it change Q_strcasecmp() and
Q_strncasecmp() to take the arguments as const, matching the signatures
of the non-replacement versions.
This commit is contained in:
Yamagi 2024-06-22 16:47:19 +02:00
parent d5d7ee29ec
commit 93178d0f6b
3 changed files with 22 additions and 6 deletions

View file

@ -318,8 +318,9 @@ void Com_PageInMemory(byte *buffer, int size);
/* portable case insensitive compare */
int Q_stricmp(const char *s1, const char *s2);
int Q_strcasecmp(char *s1, char *s2);
int Q_strncasecmp(char *s1, char *s2, int n);
int Q_strcasecmp(const char *s1, const char *s2);
int Q_strncasecmp(const char *s1, const char *s2, int n);
char *Q_strcasestr(const char *s1, const char *s2);
/* portable string lowercase */
char *Q_strlwr(char *s);

View file

@ -1021,7 +1021,7 @@ Q_stricmp(const char *s1, const char *s2)
}
int
Q_strncasecmp(char *s1, char *s2, int n)
Q_strncasecmp(const char *s1, const char *s2, int n)
{
int c1, c2;
@ -1058,8 +1058,22 @@ Q_strncasecmp(char *s1, char *s2, int n)
return 0; /* strings are equal */
}
char *Q_strcasestr(const char *haystack, const char *needle)
{
size_t len = strlen(needle);
for (; *haystack; haystack++)
{
if (!Q_strncasecmp(haystack, needle, len))
{
return (char *)haystack;
}
}
return 0;
}
int
Q_strcasecmp(char *s1, char *s2)
Q_strcasecmp(const char *s1, const char *s2)
{
return Q_strncasecmp(s1, s2, 99999);
}

View file

@ -51,8 +51,9 @@ extern int Q_strlcat ( char * dst , const char * src , int size ) ;
extern int Q_strlcpy ( char * dst , const char * src , int size ) ;
extern char * Q_strlwr ( char * s ) ;
extern void Com_sprintf ( char * dest , int size , char * fmt , ... ) ;
extern int Q_strcasecmp ( char * s1 , char * s2 ) ;
extern int Q_strncasecmp ( char * s1 , char * s2 , int n ) ;
extern int Q_strcasecmp ( const char * s1 , const char * s2 ) ;
extern int Q_strncasecmp ( const char * s1 , const char * s2 , int n ) ;
extern char *Q_strcasestr ( const char *s1, const char *s2 ) ;
extern int Q_stricmp ( const char * s1 , const char * s2 ) ;
extern void Com_PageInMemory ( byte * buffer , int size ) ;
extern char * COM_Parse ( char * * data_p ) ;