summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/stringutils.cpp11
-rw-r--r--src/utils/stringutils.h8
2 files changed, 17 insertions, 2 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 2f9bc9a8..57a0131e 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -30,10 +30,9 @@ std::string &trim(std::string &str)
{
str.erase(pos + 1);
pos = str.find_first_not_of(' ');
+
if (pos != std::string::npos)
- {
str.erase(0, pos);
- }
}
else
{
@@ -49,6 +48,14 @@ std::string &toLower(std::string &str)
return str;
}
+unsigned int atox(const std::string &str)
+{
+ unsigned int value;
+ sscanf(str.c_str(), "0x%06x", &value);
+
+ return value;
+}
+
const char *ipToString(int address)
{
static char asciiIP[16];
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 872a8f52..3af0bfa5 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -42,6 +42,14 @@ std::string &trim(std::string &str);
std::string &toLower(std::string &str);
/**
+ * Converts an ascii hexidecimal string to an integer
+ *
+ * @param str the hex string to convert to an int
+ * @return the integer representation of the hex string
+ */
+unsigned int atox(const std::string &str);
+
+/**
* Converts the given value to a string using std::stringstream.
*
* @param arg the value to convert to a string