From cbfd3edbea5217fba5fd189aba33261e4510bd7d Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Sun, 29 Jan 2017 23:33:27 +0100 Subject: Split vespa_zkfacade__restrict on space too --- .../src/main/java/com/yahoo/text/StringUtilities.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'vespajlib') 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 Haakon Humberset + * @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 split(String s) { + if (s == null || s.isEmpty()) return Collections.emptySet(); + ImmutableSet.Builder b = new ImmutableSet.Builder<>(); + for (String item : s.split("[\\s\\,]")) + if ( ! item.isEmpty()) + b.add(item); + return b.build(); + } + } -- cgit v1.2.3