Added a utility function to simplify the hint handling logic

This commit is contained in:
Sam Lantinga 2019-11-13 21:53:01 -08:00
parent c3ed380542
commit 53768d7d97
5 changed files with 52 additions and 20 deletions

View file

@ -119,18 +119,24 @@ SDL_GetHint(const char *name)
}
SDL_bool
SDL_GetHintBoolean(const char *name, SDL_bool default_value)
SDL_GetStringBoolean(const char *value, SDL_bool default_value)
{
const char *hint = SDL_GetHint(name);
if (!hint || !*hint) {
if (!value || !*value) {
return default_value;
}
if (*hint == '0' || SDL_strcasecmp(hint, "false") == 0) {
if (*value == '0' || SDL_strcasecmp(value, "false") == 0) {
return SDL_FALSE;
}
return SDL_TRUE;
}
SDL_bool
SDL_GetHintBoolean(const char *name, SDL_bool default_value)
{
const char *hint = SDL_GetHint(name);
return SDL_GetStringBoolean(hint, default_value);
}
void
SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
{