/** * Decodes locale code in string array that can be used for <code>Locale</code> constructor. */ public static String[] decodeLocaleCode(String localeCode) { String[] result = new String[3]; String[] data = StringUtil.splitc(localeCode, '_'); result[0] = data[0]; result[1] = result[2] = StringPool.EMPTY; if (data.length >= 2) { result[1] = data[1]; if (data.length >= 3) { result[2] = data[2]; } } return result; }
/** * Specifies hints for the query. Provided string is * split on ',' separator. */ public DbOomQuery withHints(final String hint) { this.hints = StringUtil.splitc(hint, ','); return this; }
/** * Returns IP address as integer. */ public static int getIpAsInt(String ipAddress) { int ipIntValue = 0; String[] tokens = StringUtil.splitc(ipAddress, '.'); for (String token : tokens) { if (ipIntValue > 0) { ipIntValue <<= 8; } ipIntValue += Integer.parseInt(token); } return ipIntValue; }
/** * Matches path against pattern using *, ? and ** wildcards. * Both path and the pattern are tokenized on path separators (both \ and /). * '**' represents deep tree wildcard, as in Ant. */ public static boolean matchPath(String path, String pattern) { String[] pathElements = StringUtil.splitc(path, PATH_SEPARATORS); String[] patternElements = StringUtil.splitc(pattern, PATH_SEPARATORS); return matchTokens(pathElements, patternElements); }
/** * Splits action path to chunks. */ public static String[] splitActionPath(final String actionPath) { return StringUtil.splitc(actionPath.substring(1), '/'); } }
public PathQuery(final String expression, final boolean included) { this.expression = StringUtil.splitc(expression, '.'); wildcard = expression.indexOf('*') >= 0; this.included = included; }
/** * Returns IP address as integer. */ public static int getIpAsInt(final String ipAddress) { int ipIntValue = 0; String[] tokens = StringUtil.splitc(ipAddress, '.'); for (String token : tokens) { if (ipIntValue > 0) { ipIntValue <<= 8; } ipIntValue += Integer.parseInt(token); } return ipIntValue; }
/** * Matches path against pattern using *, ? and ** wildcards. * Both path and the pattern are tokenized on path separators (both \ and /). * '**' represents deep tree wildcard, as in Ant. */ public static boolean matchPath(final String path, final String pattern) { String[] pathElements = StringUtil.splitc(path, PATH_SEPARATORS); String[] patternElements = StringUtil.splitc(pattern, PATH_SEPARATORS); return matchTokens(pathElements, patternElements); }
/** * Splits a string in several parts (tokens) that are separated by delimiter * characters. Delimiter may contains any number of character and it is * always surrounded by two strings. * * @param src source to examine * @param d string with delimiter characters * * @return array of tokens */ public static String[] splitc(String src, String d) { if ((d.length() == 0) || (src.length() == 0)) { return new String[] {src}; } return splitc(src, d.toCharArray()); } /**
protected Set<String> createPropertiesSet(final String attrValue, final char propertiesDelimiter) { if (attrValue == null) { return new LinkedHashSet<>(); } String[] properties = StringUtil.splitc(attrValue, propertiesDelimiter); LinkedHashSet<String> set = new LinkedHashSet<>(properties.length); Collections.addAll(set, properties); return set; }
/** * Splits a string in several parts (tokens) that are separated by delimiter * characters. Delimiter may contains any number of character and it is * always surrounded by two strings. * * @param src source to examine * @param d string with delimiter characters * * @return array of tokens */ public static String[] splitc(final String src, final String d) { if ((d.length() == 0) || (src.length() == 0)) { return new String[] {src}; } return splitc(src, d.toCharArray()); } /**
public Object[] join(final Object[] data, final String hints) { if (hints == null) { return data; } return join(data, StringUtil.splitc(hints, ',')); }
protected Map<String, String> createPropertiesMap(final String attrValue, final char propertiesDelimiter, final char valueDelimiter) { if (attrValue == null) { return new LinkedHashMap<>(); } String[] properties = StringUtil.splitc(attrValue, propertiesDelimiter); LinkedHashMap<String, String> map = new LinkedHashMap<>(properties.length); for (String property : properties) { int valueDelimiterIndex = property.indexOf(valueDelimiter); if (valueDelimiterIndex != -1) { String propertyName = property.substring(0, valueDelimiterIndex).trim(); String propertyValue = property.substring(valueDelimiterIndex + 1).trim(); map.put(propertyName, propertyValue); } } return map; }
@Override protected String[] convertStringToArray(String value) { String[] strings = StringUtil.splitc(value, NUMBER_DELIMITERS); int count = 0; for (int i = 0; i < strings.length; i++) { strings[count] = strings[i].trim(); if (strings[count].length() == 0) { continue; } if (!strings[count].startsWith(StringPool.HASH)) { count++; } } if (count != strings.length) { return ArraysUtil.subarray(strings, 0, count); } return strings; }
protected Object resolveValueInSpecialCase(Object value, final String name) { String[] elements = StringUtil.splitc(name, '.'); for (String element : elements) { value = BeanUtil.declaredSilent.getProperty(value, element); if (value instanceof List) { List list = (List) value; value = list.get(list.size() - 1); } } return value; } }
public static String[] splitPathToChunks(final String actionPath) { String path = StringUtil.cutSurrounding(actionPath, StringPool.SLASH); return StringUtil.splitc(path, '/'); }
/** * Checks if some parameter is in GET parameters. */ public boolean isGetParameter(final HttpServletRequest request, String name) { name = URLCoder.encodeQueryParam(name) + '='; String query = request.getQueryString(); String[] nameValuePairs = StringUtil.splitc(query, '&'); for (String nameValuePair : nameValuePairs) { if (nameValuePair.startsWith(name)) { return true; } } return false; }
/** * Parses string of selectors (separated with <b>,</b>). Returns * list of {@link CssSelector} lists in the same order. */ public static List<List<CssSelector>> parse(final String query) { String[] singleQueries = StringUtil.splitc(query, ','); List<List<CssSelector>> selectors = new ArrayList<>(singleQueries.length); for (String singleQuery: singleQueries) { selectors.add(new CSSelly(singleQuery).parse()); } return selectors; }
/** * Parses input dot-separated string that represents a path. */ public static Path parse(final String path) { if (path == null) { return new Path(); } return new Path(StringUtil.splitc(path, '.')); }
protected Object[] resolveSignature(String signature) { String[] data = StringUtil.splitc(signature, '#'); try { data[0] = this.getClass().getPackage().getName() + '.' + data[0]; Class c = ClassLoaderUtil.loadClass(data[0]); Method m = ClassUtil.findMethod(c, data[1]); return new Object[]{c, m}; } catch (Exception e) { throw new RuntimeException(e); } }