From d1938a151fe0fdf5b1cdbe343c5e3aca1f81b99b Mon Sep 17 00:00:00 2001 From: Misa Date: Thu, 6 Aug 2020 21:56:35 -0700 Subject: [PATCH] Add fallback parameter to UtilityClass::Int() If necessary, the caller can provide a fallback to be returned in case the input given isn't a valid integer, instead of having to duplicate the is_number() check. --- desktop_version/src/UtilityClass.cpp | 4 ++-- desktop_version/src/UtilityClass.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/desktop_version/src/UtilityClass.cpp b/desktop_version/src/UtilityClass.cpp index 7b6695ad..175cbaa5 100644 --- a/desktop_version/src/UtilityClass.cpp +++ b/desktop_version/src/UtilityClass.cpp @@ -99,11 +99,11 @@ std::string UtilityClass::String( int _v ) return(os.str()); } -int UtilityClass::Int(const char* str) +int UtilityClass::Int(const char* str, int fallback /*= 0*/) { if (!is_number(str)) { - return 0; + return fallback; } return SDL_atoi(str); diff --git a/desktop_version/src/UtilityClass.h b/desktop_version/src/UtilityClass.h index d5eed8d6..8fbd7413 100644 --- a/desktop_version/src/UtilityClass.h +++ b/desktop_version/src/UtilityClass.h @@ -37,7 +37,7 @@ public: static std::string String(int _v); - static int Int(const char* str); + static int Int(const char* str, int fallback = 0); static std::string GCString(std::vector buttons);