summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil/StringUtil.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2007-09-26 16:38:18 -0400
committerBernard Normier <bernard@zeroc.com>2007-09-26 16:38:18 -0400
commit8c37266661594245c4bea4c4094c86851bdf5550 (patch)
tree1871c4c29711c162a296f7994bfd9115a30216ef /cpp/src/IceUtil/StringUtil.cpp
parentFixed bug 2488 (diff)
downloadice-8c37266661594245c4bea4c4094c86851bdf5550.tar.bz2
ice-8c37266661594245c4bea4c4094c86851bdf5550.tar.xz
ice-8c37266661594245c4bea4c4094c86851bdf5550.zip
Squashed commit of the following:
commit 569cd3ce2933b104c980b4bfa8a1d0bc6d3be4c9 Author: Bernard Normier <bernard@zeroc.com> Date: Wed Sep 26 16:36:46 2007 -0400 Implemented admin facet filtering (Ice.Admin.Facets property) and Properties::getPropertyAsList[WithDefault]
Diffstat (limited to 'cpp/src/IceUtil/StringUtil.cpp')
-rw-r--r--cpp/src/IceUtil/StringUtil.cpp66
1 files changed, 40 insertions, 26 deletions
diff --git a/cpp/src/IceUtil/StringUtil.cpp b/cpp/src/IceUtil/StringUtil.cpp
index 92acea288ca..c2aa45d3c95 100644
--- a/cpp/src/IceUtil/StringUtil.cpp
+++ b/cpp/src/IceUtil/StringUtil.cpp
@@ -311,42 +311,56 @@ 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)
+ string::size_type pos = 0;
+ string::size_type length = str.length();
+ string elt;
+
+ while(pos < length)
{
- beg = str.find_first_not_of(delim, end);
- if(beg == string::npos)
+ char quoteChar = '\0';
+ if(str[pos] == '"' || str[pos] == '\'')
{
- break;
+ quoteChar = str[pos];
+ ++pos;
}
-
- //
- // Check for quoted argument.
- //
- char ch = str[beg];
- if(ch == '"' || ch == '\'')
+ bool trim = true;
+ while(pos < length)
{
- beg++;
- end = str.find(ch, beg);
- if(end == string::npos)
+ if(quoteChar != '\0' && str[pos] == '\\' && pos + 1 < length && str[pos + 1] == quoteChar)
{
- return false;
+ ++pos;
}
- result.push_back(str.substr(beg, end - beg));
- end++; // Skip end quote.
- }
- else
- {
- end = str.find_first_of(delim + "'\"", beg);
- if(end == string::npos)
+ else if(quoteChar != '\0' && str[pos] == quoteChar)
{
- end = str.length();
+ trim = false;
+ ++pos;
+ quoteChar = '\0';
+ break;
}
- result.push_back(str.substr(beg, end - beg));
+ else if(delim.find(str[pos]) != string::npos)
+ {
+ if(quoteChar == '\0')
+ {
+ ++pos;
+ break;
+ }
+ }
+
+ if(pos < length)
+ {
+ elt += str[pos++];
+ }
+ }
+ if(quoteChar != '\0')
+ {
+ return false; // Unmatched quote.
+ }
+ if(elt.length() > 0)
+ {
+ result.push_back(elt);
+ elt = "";
}
}
-
return true;
}