about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc8
-rw-r--r--src/libutil/util.hh4
2 files changed, 12 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index a25665e4a88c..5a41c098654e 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -616,3 +616,11 @@ bool statusOk(int status)
 {
     return WIFEXITED(status) && WEXITSTATUS(status) == 0;
 }
+
+
+bool string2Int(const string & s, int & n)
+{
+    istringstream str(s);
+    str >> n;
+    return str && str.eof();
+}
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index ae5b4882e62d..a79c07305df8 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -246,6 +246,10 @@ string statusToString(int status);
 bool statusOk(int status);
 
 
+/* Parse a string into an integer. */
+bool string2Int(const string & s, int & n);
+
+
 /* !!! HACK HACK HACK - this should be in shared.hh, but it's to
    facilitate a quick hack - will remove this eventually (famous last
    words). */