]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/strutils.cxx
Fix BTG writer for non-included index arrays.
[simgear.git] / simgear / misc / strutils.cxx
index d4ff839358effeb70bc804cd9461d9b7e6b37628..8bd33b7f507686233140ce7e68ab8a17cf52767b 100644 (file)
 
 #include <ctype.h>
 #include <cstring>
+#include <sstream>
 
 #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