From: Holger Schemel Date: Wed, 17 Feb 2021 11:49:10 +0000 (+0100) Subject: added functions to case-insensitively compare strings that might be NULL X-Git-Tag: 4.2.3.0~8 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=d9459636e19bd84aad9ca46e20455b5c6aa44010;p=rocksndiamonds.git added functions to case-insensitively compare strings that might be NULL --- diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 569526af..7a3afc68 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1178,6 +1178,22 @@ boolean strEqualN(char *s1, char *s2, int n) strncmp(s1, s2, n) == 0); } +boolean strEqualCase(char *s1, char *s2) +{ + return (s1 == NULL && s2 == NULL ? TRUE : + s1 == NULL && s2 != NULL ? FALSE : + s1 != NULL && s2 == NULL ? FALSE : + strcasecmp(s1, s2) == 0); +} + +boolean strEqualCaseN(char *s1, char *s2, int n) +{ + return (s1 == NULL && s2 == NULL ? TRUE : + s1 == NULL && s2 != NULL ? FALSE : + s1 != NULL && s2 == NULL ? FALSE : + strncasecmp(s1, s2, n) == 0); +} + boolean strPrefix(char *s, char *prefix) { return (s == NULL && prefix == NULL ? TRUE : diff --git a/src/libgame/misc.h b/src/libgame/misc.h index bb7753d7..66b310e7 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -171,6 +171,8 @@ char *getStringToLower(const char *); void setString(char **, char *); boolean strEqual(char *, char *); boolean strEqualN(char *, char *, int); +boolean strEqualCase(char *, char *); +boolean strEqualCaseN(char *, char *, int); boolean strPrefix(char *, char *); boolean strSuffix(char *, char *); boolean strPrefixLower(char *, char *);