From 8c37266661594245c4bea4c4094c86851bdf5550 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Wed, 26 Sep 2007 16:38:18 -0400 Subject: Squashed commit of the following: commit 569cd3ce2933b104c980b4bfa8a1d0bc6d3be4c9 Author: Bernard Normier Date: Wed Sep 26 16:36:46 2007 -0400 Implemented admin facet filtering (Ice.Admin.Facets property) and Properties::getPropertyAsList[WithDefault] --- cpp/src/IceUtil/StringUtil.cpp | 66 +++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 26 deletions(-) (limited to 'cpp/src/IceUtil/StringUtil.cpp') 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& 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; } -- cgit v1.2.3