Added SDL_wcscasecmp() and SDL_wcsncasecmp()

This commit is contained in:
Sam Lantinga
2020-11-24 12:43:01 -08:00
parent e4b7d9a221
commit 46a844786b
8 changed files with 93 additions and 2 deletions

View File

@@ -786,3 +786,5 @@
#define SDL_GameControllerSetSensorEnabled SDL_GameControllerSetSensorEnabled_REAL
#define SDL_GameControllerIsSensorEnabled SDL_GameControllerIsSensorEnabled_REAL
#define SDL_GameControllerGetSensorData SDL_GameControllerGetSensorData_REAL
#define SDL_wcscasecmp SDL_wcscasecmp_REAL
#define SDL_wcsncasecmp SDL_wcsncasecmp_REAL

View File

@@ -847,3 +847,5 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerHasSensor,(SDL_GameController *a, SDL
SDL_DYNAPI_PROC(int,SDL_GameControllerSetSensorEnabled,(SDL_GameController *a, SDL_SensorType b, SDL_bool c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerIsSensorEnabled,(SDL_GameController *a, SDL_SensorType b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GameControllerGetSensorData,(SDL_GameController *a, SDL_SensorType b, float *c, int d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_wcscasecmp,(const wchar_t *a, const wchar_t *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_wcsncasecmp,(const wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return)

View File

@@ -531,6 +531,85 @@ SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
#endif /* HAVE_WCSNCMP */
}
int
SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2)
{
#if defined(HAVE_WCSCASECMP)
return wcscasecmp(str1, str2);
#elif defined(HAVE__WCSICMP)
return _wcsicmp(str1, str2);
#else
wchar_t a = 0;
wchar_t b = 0;
while (*str1 && *str2) {
/* FIXME: This doesn't actually support wide characters */
if (*str1 >= 0x80 || *str2 >= 0x80) {
a = *str1;
b = *str2;
} else {
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
}
if (a != b)
break;
++str1;
++str2;
}
/* FIXME: This doesn't actually support wide characters */
if (*str1 >= 0x80 || *str2 >= 0x80) {
a = *str1;
b = *str2;
} else {
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
}
return (int) ((unsigned int) a - (unsigned int) b);
#endif /* HAVE__WCSICMP */
}
int
SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen)
{
#if defined(HAVE_WCSNCASECMP)
return wcsncasecmp(str1, str2, maxlen);
#elif defined(HAVE__WCSNICMP)
return _wcsnicmp(str1, str2, maxlen);
#else
wchar_t a = 0;
wchar_t b = 0;
while (*str1 && *str2 && maxlen) {
/* FIXME: This doesn't actually support wide characters */
if (*str1 >= 0x80 || *str2 >= 0x80) {
a = *str1;
b = *str2;
} else {
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
}
if (a != b)
break;
++str1;
++str2;
--maxlen;
}
if (maxlen == 0) {
return 0;
} else {
/* FIXME: This doesn't actually support wide characters */
if (*str1 >= 0x80 || *str2 >= 0x80) {
a = *str1;
b = *str2;
} else {
a = SDL_toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2);
}
return (int) ((unsigned int) a - (unsigned int) b);
}
#endif /* HAVE__WCSNICMP */
}
size_t
SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
{