summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil/StringUtil.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2007-09-25 17:59:25 -0400
committerBernard Normier <bernard@zeroc.com>2007-09-25 17:59:25 -0400
commitbf92b3d33fdf15bc8eacacb1baf35fdd17131ee6 (patch)
treee6e430aff788ded4e2e64d4a774c55b1f1dc0cb9 /cpp/src/IceUtil/StringUtil.cpp
parentFixed VC8 compilation error (diff)
downloadice-bf92b3d33fdf15bc8eacacb1baf35fdd17131ee6.tar.bz2
ice-bf92b3d33fdf15bc8eacacb1baf35fdd17131ee6.tar.xz
ice-bf92b3d33fdf15bc8eacacb1baf35fdd17131ee6.zip
Fixed bug #2440
Diffstat (limited to 'cpp/src/IceUtil/StringUtil.cpp')
-rw-r--r--cpp/src/IceUtil/StringUtil.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/cpp/src/IceUtil/StringUtil.cpp b/cpp/src/IceUtil/StringUtil.cpp
index 30029300f59..92acea288ca 100644
--- a/cpp/src/IceUtil/StringUtil.cpp
+++ b/cpp/src/IceUtil/StringUtil.cpp
@@ -308,6 +308,49 @@ IceUtil::unescapeString(const string& s, string::size_type start, string::size_t
}
}
+bool
+IceUtil::splitString(const string& str, const string& delim, vector<string>& result)
+{
+ string::size_type beg;
+ string::size_type end = 0;
+ while(true)
+ {
+ beg = str.find_first_not_of(delim, end);
+ if(beg == string::npos)
+ {
+ break;
+ }
+
+ //
+ // Check for quoted argument.
+ //
+ char ch = str[beg];
+ if(ch == '"' || ch == '\'')
+ {
+ beg++;
+ end = str.find(ch, beg);
+ if(end == string::npos)
+ {
+ return false;
+ }
+ result.push_back(str.substr(beg, end - beg));
+ end++; // Skip end quote.
+ }
+ else
+ {
+ end = str.find_first_of(delim + "'\"", beg);
+ if(end == string::npos)
+ {
+ end = str.length();
+ }
+ result.push_back(str.substr(beg, end - beg));
+ }
+ }
+
+ return true;
+}
+
+
//
// If a single or double quotation mark is found at the start position,
// then the position of the matching closing quote is returned. If no