public static String[] split(String line, char delimiter, char quoteChar) { return split(line, delimiter, quoteChar, quoteChar); }
public static String[] split(String line, char delimiter, char beginQuoteChar, char endQuoteChar) { return split(line, delimiter, beginQuoteChar, endQuoteChar, false, true); }
public static String[] split(String line, char delimiter) { return split(line, delimiter, DEFAULT_QUOTE_CHAR); }
public static String[] split(String line) { return split(line, DEFAULT_DELIMITER_CHAR); }
/** * Splits the comma-delimited filter chain definition line into individual filter definition tokens. * <p/> * Example Input: * <pre> * foo, bar[baz], blah[x, y] * </pre> * Resulting Output: * <pre> * output[0] == foo * output[1] == bar[baz] * output[2] == blah[x, y] * </pre> * @param chainDefinition the comma-delimited filter chain definition. * @return an array of filter definition tokens * @since 1.2 * @see <a href="https://issues.apache.org/jira/browse/SHIRO-205">SHIRO-205</a> */ protected String[] splitChainDefinition(String chainDefinition) { return StringUtils.split(chainDefinition, StringUtils.DEFAULT_DELIMITER_CHAR, '[', ']', true, true); }
public static Set<String> toPermissionStrings(String permissionsString) { String[] tokens = StringUtils.split(permissionsString); if (tokens != null && tokens.length > 0) { return new LinkedHashSet<String>(Arrays.asList(tokens)); } return null; }
/** * Split a string into a list of not empty and trimmed strings, delimiter is a comma. * * @param s the input string * @return the list of not empty and trimmed strings */ private List<String> split(String s) { List<String> list = new ArrayList<String>(); String[] elements = StringUtils.split(s, ','); if (elements != null && elements.length > 0) { for (String element : elements) { if (StringUtils.hasText(element)) { list.add(element.trim()); } } } return list; }
/** * Splits the {@code delimited} string (delimited by the specified {@code separator} character) and returns the * delimited values as a {@code Set}. * <p/> * If either argument is {@code null}, this method returns {@code null}. * * @param delimited the string to split * @param separator the character that delineates individual tokens to split * @return the delimited values as a {@code Set}. * @since 1.2 */ public static Set<String> splitToSet(String delimited, String separator) { if (delimited == null || separator == null) { return null; } String[] split = split(delimited, separator.charAt(0)); return asSet(split); }
public void setConfigLocations(String locations) { if (!StringUtils.hasText(locations)) { throw new IllegalArgumentException("Null/empty locations argument not allowed."); } String[] arr = StringUtils.split(locations); setConfigLocations(arr); }
protected Set<?> toSet(String sValue) { String[] tokens = StringUtils.split(sValue); if (tokens == null || tokens.length <= 0) { return null; } //SHIRO-423: check to see if the value is a referenced Set already, and if so, return it immediately: if (tokens.length == 1 && isReference(tokens[0])) { Object reference = resolveReference(tokens[0]); if (reference instanceof Set) { return (Set)reference; } } Set<String> setTokens = new LinkedHashSet<String>(Arrays.asList(tokens)); //now convert into correct values and/or references: Set<Object> values = new LinkedHashSet<Object>(setTokens.size()); for (String token : setTokens) { Object value = resolveValue(token); values.add(value); } return values; }
protected Collection<?> toCollection(String sValue) { String[] tokens = StringUtils.split(sValue); if (tokens == null || tokens.length <= 0) { return null; } //SHIRO-423: check to see if the value is a referenced Collection already, and if so, return it immediately: if (tokens.length == 1 && isReference(tokens[0])) { Object reference = resolveReference(tokens[0]); if (reference instanceof Collection) { return (Collection)reference; } } //now convert into correct values and/or references: List<Object> values = new ArrayList<Object>(tokens.length); for (String token : tokens) { Object value = resolveValue(token); values.add(value); } return values; }
protected List<?> toList(String sValue) { String[] tokens = StringUtils.split(sValue); if (tokens == null || tokens.length <= 0) { return null; } //SHIRO-423: check to see if the value is a referenced List already, and if so, return it immediately: if (tokens.length == 1 && isReference(tokens[0])) { Object reference = resolveReference(tokens[0]); if (reference instanceof List) { return (List)reference; } } //now convert into correct values and/or references: List<Object> values = new ArrayList<Object>(tokens.length); for (String token : tokens) { Object value = resolveValue(token); values.add(value); } return values; }
@Test public void splitWithNullInput() { String line = null; String[] split = StringUtils.split(line); assertNull(split); }
@Test public void splitWithQuotedCommasAndSpaces() { String line = "shall, \"we, play\", a, game?"; String[] split = StringUtils.split(line); assertNotNull(split); assertTrue(split.length == 4); assertEquals("shall", split[0]); assertEquals("we, play", split[1]); assertEquals("a", split[2]); assertEquals("game?", split[3]); }
@Test public void splitWithQuotedCommasAndSpacesAndDifferentQuoteCharsWhileRetainingQuotes() { String line = "authc, test[blah], test[1,2,3], test[]"; String[] split = StringUtils.split(line, ',', '[', ']', true, true); assertNotNull(split); assertTrue(split.length == 4); assertEquals("authc", split[0]); assertEquals("test[blah]", split[1]); assertEquals("test[1,2,3]", split[2]); assertEquals("test[]", split[3]); }
@Test public void splitTestWithQuotedCommas() { String line = "authc, test[blah], test[\"1,2,3\"], test[]"; String[] split = StringUtils.split(line); assertNotNull(split); assertTrue(split.length == 4); assertEquals("authc", split[0]); assertEquals("test[blah]", split[1]); assertEquals("test[1,2,3]", split[2]); assertEquals("test[]", split[3]); }
@Test public void splitWithQuotedCommasAndSpacesAndDifferentQuoteChars() { String line = "authc, test[blah], test[1,2,3], test[]"; String[] split = StringUtils.split(line, ',', '[', ']', false, true); assertNotNull(split); assertTrue(split.length == 4); assertEquals("authc", split[0]); assertEquals("testblah", split[1]); assertEquals("test1,2,3", split[2]); assertEquals("test", split[3]); }
@Test public void splitWithQuotedCommasAndSpacesAndEscapedQuotes() { String line = "shall, \"\"\"we, play\", a, \"\"\"game?"; String[] split = StringUtils.split(line); assertNotNull(split); assertTrue(split.length == 4); assertEquals("shall", split[0]); assertEquals("\"we, play", split[1]); assertEquals("a", split[2]); assertEquals("\"game?", split[3]); }
@Test public void splitWithCommas() { String line = "shall,we,play,a,game?"; String[] split = StringUtils.split(line); assertNotNull(split); assertTrue(split.length == 5); assertEquals("shall", split[0]); assertEquals("we", split[1]); assertEquals("play", split[2]); assertEquals("a", split[3]); assertEquals("game?", split[4]); }
@Test public void splitWithCommasAndSpaces() { String line = "shall,we , play, a,game?"; String[] split = StringUtils.split(line); assertNotNull(split); assertTrue(split.length == 5); assertEquals("shall", split[0]); assertEquals("we", split[1]); assertEquals("play", split[2]); assertEquals("a", split[3]); assertEquals("game?", split[4]); }