summaryrefslogtreecommitdiff
path: root/cs/src/Ice/StringUtil.cs
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2009-12-20 23:00:17 +0100
committerBenoit Foucher <benoit@zeroc.com>2009-12-20 23:00:17 +0100
commit1bfce436ef24da5886a752f906628472ceb60a96 (patch)
treeae4fc9bac597df81b4855a0fadbde552c978bbbf /cs/src/Ice/StringUtil.cs
parentedits to CHANGES & RELEASE_NOTES (diff)
downloadice-1bfce436ef24da5886a752f906628472ceb60a96.tar.bz2
ice-1bfce436ef24da5886a752f906628472ceb60a96.tar.xz
ice-1bfce436ef24da5886a752f906628472ceb60a96.zip
Fixed bug 4514 - Ice/facets test failure
Diffstat (limited to 'cs/src/Ice/StringUtil.cs')
-rw-r--r--cs/src/Ice/StringUtil.cs66
1 files changed, 66 insertions, 0 deletions
diff --git a/cs/src/Ice/StringUtil.cs b/cs/src/Ice/StringUtil.cs
index 9db9c17c697..fec68771cf4 100644
--- a/cs/src/Ice/StringUtil.cs
+++ b/cs/src/Ice/StringUtil.cs
@@ -9,6 +9,7 @@
using System.Text;
using System.Diagnostics;
+using System.Collections.Generic;
namespace IceUtilInternal
{
@@ -355,6 +356,71 @@ namespace IceUtilInternal
return utf8.GetString(arr); // May raise ArgumentException.
}
+ //
+ // Split string helper; returns null for unmatched quotes
+ //
+ static public string[] splitString(string str, string delim)
+ {
+ List<string> l = new List<string>();
+ char[] arr = new char[str.Length];
+ int pos = 0;
+
+ int n = 0;
+ char quoteChar = '\0';
+ while(pos < str.Length)
+ {
+ if(quoteChar == '\0' && (str[pos] == '"' || str[pos] == '\''))
+ {
+ quoteChar = str[pos++];
+ continue; // Skip the quote.
+ }
+ else if(quoteChar == '\0' && str[pos] == '\\' && pos + 1 < str.Length &&
+ (str[pos + 1] == '\'' || str[pos + 1] == '"'))
+ {
+ ++pos; // Skip the backslash
+ }
+ else if(quoteChar != '\0' && str[pos] == '\\' && pos + 1 < str.Length && str[pos + 1] == quoteChar)
+ {
+ ++pos; // Skip the backslash
+ }
+ else if(quoteChar != '\0' && str[pos] == quoteChar)
+ {
+ ++pos;
+ quoteChar = '\0';
+ continue; // Skip the quote.
+ }
+ else if(delim.IndexOf(str[pos]) != -1)
+ {
+ if(quoteChar == '\0')
+ {
+ ++pos;
+ if(n > 0)
+ {
+ l.Add(new string(arr, 0, n));
+ n = 0;
+ }
+ continue;
+ }
+ }
+
+ if(pos < str.Length)
+ {
+ arr[n++] = str[pos++];
+ }
+
+ }
+
+ if(n > 0)
+ {
+ l.Add(new string(arr, 0, n));
+ }
+ if(quoteChar != '\0')
+ {
+ return null; // Unmatched quote.
+ }
+ return l.ToArray();
+ }
+
public static int checkQuote(string s)
{
return checkQuote(s, 0);