summaryrefslogtreecommitdiff
path: root/java/src/IceUtilInternal/StringUtil.java
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 /java/src/IceUtilInternal/StringUtil.java
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 'java/src/IceUtilInternal/StringUtil.java')
-rw-r--r--java/src/IceUtilInternal/StringUtil.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/java/src/IceUtilInternal/StringUtil.java b/java/src/IceUtilInternal/StringUtil.java
index 137bb234e06..dfbb095673f 100644
--- a/java/src/IceUtilInternal/StringUtil.java
+++ b/java/src/IceUtilInternal/StringUtil.java
@@ -386,6 +386,72 @@ public final class StringUtil
return s.toString();
}
+ //
+ // Split string helper; returns null for unmatched quotes
+ //
+ static public String[]
+ splitString(String str, String delim)
+ {
+ java.util.List<String> l = new java.util.ArrayList<String>();
+ char[] arr = new char[str.length()];
+ int pos = 0;
+
+ int n = 0;
+ char quoteChar = '\0';
+ while(pos < str.length())
+ {
+ if(quoteChar == '\0' && (str.charAt(pos) == '"' || str.charAt(pos) == '\''))
+ {
+ quoteChar = str.charAt(pos++);
+ continue; // Skip the quote.
+ }
+ else if(quoteChar == '\0' && str.charAt(pos) == '\\' && pos + 1 < str.length() &&
+ (str.charAt(pos + 1) == '"' || str.charAt(pos + 1) == '\''))
+ {
+ ++pos; // Skip the backslash
+ }
+ else if(quoteChar != '\0' && str.charAt(pos) == '\\' && pos + 1 < str.length() &&
+ str.charAt(pos + 1) == quoteChar)
+ {
+ ++pos; // Skip the backslash
+ }
+ else if(quoteChar != '\0' && str.charAt(pos) == quoteChar)
+ {
+ ++pos;
+ quoteChar = '\0';
+ continue; // Skip the quote.
+ }
+ else if(delim.indexOf(str.charAt(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.charAt(pos++);
+ }
+ }
+
+ if(n > 0)
+ {
+ l.add(new String(arr, 0, n));
+ }
+ if(quoteChar != '\0')
+ {
+ return null; // Unmatched quote.
+ }
+ return (String[])l.toArray(new String[0]);
+ }
+
public static int
checkQuote(String s)
{