diff --git a/desktop_version/src/UtilityClass.cpp b/desktop_version/src/UtilityClass.cpp index 31b571cf..c472583d 100644 --- a/desktop_version/src/UtilityClass.cpp +++ b/desktop_version/src/UtilityClass.cpp @@ -36,12 +36,41 @@ static const char* GCChar(const SDL_GameControllerButton button) } } -int ss_toi( std::string _s ) +int ss_toi(const std::string& str) { - std::istringstream i(_s); - int x = 0; - i >> x; - return x; + int retval = 0; + int place = 1; + bool negative = false; + const int radix = 10; + + for (size_t i = 0; i < str.size(); ++i) + { + const char chr = str[i]; + + if (i == 0 && chr == '-') + { + negative = true; + continue; + } + + if (SDL_isdigit(chr)) + { + retval *= place; + retval += chr - '0'; + place *= radix; + } + else + { + break; + } + } + + if (negative) + { + return -retval; + } + + return retval; } std::vector split( const std::string &s, char delim, std::vector &elems ) diff --git a/desktop_version/src/UtilityClass.h b/desktop_version/src/UtilityClass.h index a24a7dbd..1f9c2c51 100644 --- a/desktop_version/src/UtilityClass.h +++ b/desktop_version/src/UtilityClass.h @@ -5,7 +5,7 @@ #include #include -int ss_toi(std::string _s); +int ss_toi(const std::string& str); std::vector split(const std::string &s, char delim, std::vector &elems);