X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmisc%2Fstrutils.cxx;h=8bd33b7f507686233140ce7e68ab8a17cf52767b;hb=e4e31be7d43569a92a5d9fa7e784381b66cbd95a;hp=d4ff839358effeb70bc804cd9461d9b7e6b37628;hpb=f06f25532ca06b7edb948131f45f8efea2268589;p=simgear.git diff --git a/simgear/misc/strutils.cxx b/simgear/misc/strutils.cxx index d4ff8393..8bd33b7f 100644 --- a/simgear/misc/strutils.cxx +++ b/simgear/misc/strutils.cxx @@ -22,11 +22,13 @@ #include #include +#include #include "strutils.hxx" using std::string; using std::vector; +using std::stringstream; namespace simgear { namespace strutils { @@ -243,9 +245,18 @@ namespace simgear { return result; } - int to_int(const std::string& s) + int to_int(const std::string& s, int base) { - return atoi(s.c_str()); + stringstream ss(s); + switch (base) { + case 8: ss >> std::oct; break; + case 16: ss >> std::hex; break; + default: break; + } + + int result; + ss >> result; + return result; } } // end namespace strutils