summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2017-01-29 23:33:27 +0100
committerJon Bratseth <bratseth@yahoo-inc.com>2017-01-29 23:33:27 +0100
commitcbfd3edbea5217fba5fd189aba33261e4510bd7d (patch)
treec3c3e7217387d69e9a8cc792baa469c40f422911 /vespajlib
parentb69c1cad6dae7506c22e13ceb2432d8f1839ab4d (diff)
Split vespa_zkfacade__restrict on space too
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/text/StringUtilities.java18
1 files changed, 17 insertions, 1 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java b/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java
index d65681e8f5b..975e2955d3a 100644
--- a/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java
+++ b/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java
@@ -1,18 +1,23 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.text;
+import com.google.common.collect.ImmutableSet;
+
import java.nio.charset.Charset;
+import java.util.Collections;
import java.util.List;
import java.io.ByteArrayOutputStream;
+import java.util.Set;
/**
* Escapes strings into and out of a format where they only contain printable characters.
*
* Need to duplicate escape / unescape of strings as we have in C++ for java version of system states.
*
- * @author <a href="mailto:humbe@yahoo-inc.com">Haakon Humberset</a>
+ * @author Haakon Humberset
*/
public class StringUtilities {
+
private static Charset UTF8 = Charset.forName("utf8");
private static byte toHex(int val) { return (byte) (val < 10 ? '0' + val : 'a' + (val - 10)); }
@@ -201,4 +206,15 @@ public class StringUtilities {
public static String quote(Object object) {
return "'" + object.toString() + "'";
}
+
+ /** Splits a string on both space and comma */
+ public static Set<String> split(String s) {
+ if (s == null || s.isEmpty()) return Collections.emptySet();
+ ImmutableSet.Builder<String> b = new ImmutableSet.Builder<>();
+ for (String item : s.split("[\\s\\,]"))
+ if ( ! item.isEmpty())
+ b.add(item);
+ return b.build();
+ }
+
}