summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-09-22 15:43:22 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-09-22 15:43:22 +0000
commit4578a490ce5a5a6325b4ff2b8f44468464de2d94 (patch)
tree62a5118879990d20e71cccf263f4648bfa3ba253 /src/libutil
parentfbedf6056eb2acb5049b0372350b2c93b8185ab7 (diff)
downloadguix-4578a490ce5a5a6325b4ff2b8f44468464de2d94.tar.gz
* Parse multi-valued options.
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 574c2566b7..2e684e9c14 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 beb98fe7c6..9e7eb11bd1 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);