summaryrefslogtreecommitdiff
path: root/src/utils/stringutils.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-08 19:39:32 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-08 19:39:32 +0300
commit571ff6e1401876cb775b827f6af25e14b1f59c6f (patch)
tree4cf36adcda2779a40f1f1f9a46b7a787f2834782 /src/utils/stringutils.cpp
parent15e87a84d62cc0b0077b25c235824879bde66a41 (diff)
downloadmv-571ff6e1401876cb775b827f6af25e14b1f59c6f.tar.gz
mv-571ff6e1401876cb775b827f6af25e14b1f59c6f.tar.bz2
mv-571ff6e1401876cb775b827f6af25e14b1f59c6f.tar.xz
mv-571ff6e1401876cb775b827f6af25e14b1f59c6f.zip
Improve string to int parsing.
Diffstat (limited to 'src/utils/stringutils.cpp')
-rw-r--r--src/utils/stringutils.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 11143206e..5674abfd9 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -746,3 +746,18 @@ bool parse2Int(const std::string &args, int &x, int &y)
}
return isValid;
}
+
+int parseNumber(const std::string &str)
+{
+ int i = 0;
+ int idx = 0;
+ if (strStartWith(str, "0x"))
+ idx = 2;
+ else if (str[0] == 'h' || str[0] == 'x')
+ idx = 1;
+ if (idx > 0)
+ sscanf(str.substr(idx).c_str(), "%10x", &i);
+ else
+ i = atoi(str.c_str());
+ return i;
+}