Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2014-05-20 03:02:10 +0000
committerslewis2014-05-20 03:02:10 +0000
commit5e235cd42d7ee5c0915b88070ac99627a56d6ac1 (patch)
tree10a727062da315e1f72ccb1ce6f316cf341663be
parent6eede270700c81071550f7fa4b32f6a83612f27a (diff)
downloadorg.eclipse.ecf-R-Release_HEAD-sdk_feature-138_2014-05-20_03-09-25.tar.gz
org.eclipse.ecf-R-Release_HEAD-sdk_feature-138_2014-05-20_03-09-25.tar.xz
org.eclipse.ecf-R-Release_HEAD-sdk_feature-138_2014-05-20_03-09-25.zip
Fixes for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=430752.R-Release_HEAD-sdk_feature-138_2014-05-20_03-09-25
Updated util.StringUtils. Change-Id: I0000000000000000000000000000000000000000
-rw-r--r--protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/CodeAnalyzer.java2
-rw-r--r--protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/util/StringUtils.java58
2 files changed, 44 insertions, 16 deletions
diff --git a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/CodeAnalyzer.java b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/CodeAnalyzer.java
index 1df6fb1ed..541ccf614 100644
--- a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/CodeAnalyzer.java
+++ b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/CodeAnalyzer.java
@@ -245,8 +245,6 @@ final class CodeAnalyzer extends ClassVisitor {
}
}
- System.out.println("INJECTIONS: " + injections);
-
final DeliverServiceMessage message = new DeliverServiceMessage();
message.setInterfaceNames(ifaces);
message.setSmartProxyName(smartProxy);
diff --git a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/util/StringUtils.java b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/util/StringUtils.java
index 79f6bcec2..e0476f21b 100644
--- a/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/util/StringUtils.java
+++ b/protocols/bundles/ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/util/StringUtils.java
@@ -32,7 +32,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
/**
* String utilities.
@@ -58,34 +57,65 @@ public final class StringUtils {
* @return the array of strings.
* @since 0.2
*/
- public static String[] stringToArray(final String data, final String delim) {
- final StringTokenizer tokenizer = new StringTokenizer(data, delim);
- final String[] tokens = new String[tokenizer.countTokens()];
- final int tokenCount = tokenizer.countTokens();
- for (int i = 0; i < tokenCount; i++) {
- tokens[i] = tokenizer.nextToken().trim();
+ public static String[] stringToArray(final String data,
+ final String delim) {
+
+ if (data == null) {
+ return new String[0];
}
- return tokens;
+ final List tokens = new ArrayList(data.length() / 10);
+ int pointer = 0;
+ int quotePointer = 0;
+ int tokenStart = 0;
+ int nextDelimiter;
+ while ((nextDelimiter = data.indexOf(delim, pointer)) > -1) {
+ final int openingQuote = data.indexOf("\"", quotePointer);
+ int closingQuote = data.indexOf("\"", openingQuote + 1);
+ if (openingQuote > closingQuote) {
+ throw new IllegalArgumentException(
+ "Missing closing quotation mark.");
+ }
+ if (openingQuote > -1 && openingQuote < nextDelimiter
+ && closingQuote < nextDelimiter) {
+ quotePointer = ++closingQuote;
+ continue;
+ }
+ if (openingQuote < nextDelimiter && nextDelimiter < closingQuote) {
+ pointer = ++closingQuote;
+ continue;
+ }
+ // TODO: for performance, fold the trim into the splitting
+ tokens.add(data.substring(tokenStart, nextDelimiter).trim());
+ pointer = ++nextDelimiter;
+ quotePointer = pointer;
+ tokenStart = pointer;
+ }
+ tokens.add(data.substring(tokenStart).trim());
+ return (String[]) tokens.toArray(new String[tokens.size()]);
}
/**
* R \ L (comparison operation allows wildcards)
- * @param left A set of matchers (supports wildcard at end)
- * @param right A set of inputs
- * @return The subset of right with all elements removed matching left
+ *
+ * @param left
+ * A set of matchers (supports wildcard at end)
+ * @param right
+ * A set of inputs
+ * @return The subset of right with all elements removed matching left
* @since 1.0
*/
public static Collection rightDifference(Collection left, Collection right) {
// This is O(n²) due to substring (wildcard) matching
// It's also quick and dirty (better use pattern matcher instead)
// TODO use pattern matcher
- // (pattern matcher would increase the BREE dependency, but we could hide
- // the FilterUtils implementation behind an interface and provide different
+ // (pattern matcher would increase the BREE dependency, but we could
+ // hide
+ // the FilterUtils implementation behind an interface and provide
+ // different
// service implementations)
// A trie would also allow for faster lookup.
-
// Have to convert c1 into List to support remove operation
final List result = new ArrayList(right);

Back to the top