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.cc15
-rw-r--r--src/libutil/util.hh4
2 files changed, 19 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 574c2566b7a5..2e684e9c1441 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -665,6 +665,21 @@ Strings unpackStrings(const string & s)
 }
 
 
+Strings tokenizeString(const string & s, const string & separators)
+{
+    Strings result;
+    string::size_type pos = s.find_first_not_of(separators, 0);
+    while (pos != string::npos) {
+        string::size_type end = s.find_first_of(separators, pos + 1);
+        if (end == string::npos) end = s.size();
+        string token(s, pos, end - pos);
+        result.push_back(token);
+        pos = s.find_first_not_of(separators, end);
+    }
+    return result;
+}
+
+
 string statusToString(int status)
 {
     if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index beb98fe7c6e9..9e7eb11bd16d 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -261,6 +261,10 @@ string packStrings(const Strings & strings);
 Strings unpackStrings(const string & s);
 
 
+/* String tokenizer. */
+Strings tokenizeString(const string & s, const string & separators = " \t\n\r");
+
+
 /* Convert the exit status of a child as returned by wait() into an
    error string. */
 string statusToString(int status);