private static List<String> extractDependencies(String source) { String[] deps = substringsBetween(source, "import \"", "\";"); return deps == null ? Collections.<String>emptyList() : asList(deps); }
private void validateLabelTemplate() { if (StringUtils.isBlank(labelTemplate)) { addError("labelTemplate", BLANK_LABEL_TEMPLATE_ERROR_MESSAGE); return; } String[] allTokens = substringsBetween(labelTemplate, "${", "}"); if (allTokens == null) { addError("labelTemplate", String.format(LABEL_TEMPLATE_ERROR_MESSAGE, labelTemplate)); return; } for (String token : allTokens) { if (!isValidToken(token)) { break; } } }
String[] results = StringUtils.substringsBetween("[one], [two], [three]", "[", "]"); assertEquals(3, results.length); assertEquals("one", results[0]); results = StringUtils.substringsBetween("[one], [two], three", "[", "]"); assertEquals(2, results.length); assertEquals("one", results[0]); assertEquals("two", results[1]); results = StringUtils.substringsBetween("[one], [two], three]", "[", "]"); assertEquals(2, results.length); assertEquals("one", results[0]); assertEquals("two", results[1]); results = StringUtils.substringsBetween("[one], two], three]", "[", "]"); assertEquals(1, results.length); assertEquals("one", results[0]); results = StringUtils.substringsBetween("one], two], [three]", "[", "]"); assertEquals(1, results.length); assertEquals("three", results[0]); results = StringUtils.substringsBetween("aabhellobabnonba", "ab", "ba"); assertEquals(1, results.length); assertEquals("hello", results[0]); results = StringUtils.substringsBetween("one, two, three", "[", "]"); assertNull(results);
/** * 返回所有在字符串str中从open开始到close结束的子字符串数组,引用org.apache.commons.lang.StringUtils.substringsBetween(String str,String open,String close)方法。<br> * 如果str为null将返回null,如果open或close为null将返回null(没有匹配的),如果open和close为""将返回null(没有匹配的)。<br> * 例:<br> * StringUtil.substringsBetween("[a][b][c]", "[", "]") = ["a","b","c"] <br> * StringUtil.substringsBetween(null, *, *) = null <br> * StringUtil.substringsBetween(*, null, *) = null <br> * StringUtil.substringsBetween(*, *, null) = null <br> * StringUtil.substringsBetween("", "[", "]") = [] <br> * @param str 包含子串的字符串(null将返回null,""将返回"") * @param open 查找子字符串的开始位置(""将返回null) * @param close 查找子字符串的结束位置(""将返回null) * @return String 返回子字符串数组,如果没有匹配的返回null。 */ public static String[] substringsBetween(String str,String open,String close){ return StringUtils.substringsBetween(str, open, close); }
/** * <p>Searches a String for substrings delimited by a start and end tag, * returning all matching substrings in an array.</p> * * <p>A {@code null} input String returns {@code null}. * A {@code null} open/close returns {@code null} (no match). * An empty ("") open/close returns {@code null} (no match).</p> * * <pre> * StringUtils.substringsBetween("[a][b][c]", "[", "]") = ["a","b","c"] * StringUtils.substringsBetween(null, *, *) = null * StringUtils.substringsBetween(*, null, *) = null * StringUtils.substringsBetween(*, *, null) = null * StringUtils.substringsBetween("", "[", "]") = [] * </pre> * * @param str the String containing the substrings, null returns null, empty returns empty * @param open the String identifying the start of the substring, empty returns null * @param close the String identifying the end of the substring, empty returns null * @return a String Array of substrings, or {@code null} if no match * @since 2.3 */ public static String[] substringsBetween(String str, String open, String close) { return org.apache.commons.lang3.StringUtils.substringsBetween(str, open, close); }
public static List<String> getWordsBetweenQuotes(String s) { List<String> result = new ArrayList<String>(); if (s != null) { for (int i = 0; i < QUOTES.length; i++) { String quote = QUOTES[i]; String[] words = StringUtils.substringsBetween(s, quote, quote); if (words != null) { result.addAll(Arrays.asList(words)); } } } return result; } public static String changeCaseExcludeQuotes(String s, boolean upper) {
public static List<String> getWordsBetweenQuotes(String s) { List<String> result = new ArrayList<String>(); if (s != null) { for (int i = 0; i < QUOTES.length; i++) { String quote = QUOTES[i]; String[] words = StringUtils.substringsBetween(s, quote, quote); if (words != null) { result.addAll(Arrays.asList(words)); } } } return result; } public static String changeCaseExcludeQuotes(String s, boolean upper) {
private static String[] getNamesBetweenPlaceholders(String propertiesFilesString, String contextNamePlaceHolder) { final String[] names = StringUtils.substringsBetween( propertiesFilesString, PLACEHOLDER_PREFIX + contextNamePlaceHolder, PLACEHOLDER_SUFFIX); return StringUtils.stripAll(names); }
public static String formatName(String pattern, String firstName, String lastName, String middleName) throws ParseException { if (pattern == null || pattern.length() == 0) throw new ParseException("Pattern error", 0); if (firstName == null || firstName.equals("null")) firstName = ""; if (lastName == null || lastName.equals("null")) lastName = ""; if (middleName == null || middleName.equals("null")) middleName = ""; String[] params = StringUtils.substringsBetween(pattern, "{", "}"); int i; for (i = 0; i < params.length; i++) { pattern = StringUtils.replace(pattern, "{" + params[i] + "}", "{" + i + "}", 1); params[i] = parseParam(params[i], firstName, lastName, middleName); } for (i = 0; i < params.length; i++) { pattern = StringUtils.replace(pattern, "{" + i + "}", params[i], 1); } return pattern; }
String[] wheres = StringUtils.substringsBetween(str, openWhere, closeWhere); if (wheres == null) { return str;
String[] jsToBeMoved = StringUtils.substringsBetween(contents, BEGIN, END); String modifiedContents = contents;
@Override protected Strings handle(Strings input, StringContext stringContext, List<SyntaxNode> params) { Preconditions.checkArgument(params.size() >= 2, "substringsBetween must has 2 parameters at lest"); Object openObject = params.get(1).calculate(stringContext); if (!(openObject instanceof CharSequence)) { throw new IllegalStateException(determineFunctionName() + " second parameter must bu string"); } String closeString = openObject.toString(); if (params.size() >= 3) { Object closeObject = params.get(2).calculate(stringContext); if (!(closeObject instanceof CharSequence)) { throw new IllegalStateException(determineFunctionName() + " second parameter must bu string"); } closeString = closeObject.toString(); } Strings ret = new Strings(); for (String str : input) { Collections.addAll(ret, StringUtils.substringsBetween(str, openObject.toString(), closeString)); } return ret; }
/** * Return a new <code>Properties</code> object loaded from <code>location</code> where the properties are stored in Rice XML style syntax * * @deprecated use loadRiceProps() instead */ @Deprecated public static final Properties loadRiceProperties(String location) { logger.info("Loading Rice properties [{}] encoding={}", location, DEFAULT_XML_ENCODING); String contents = LocationUtils.toString(location, DEFAULT_XML_ENCODING); String config = StringUtils.substringBetween(contents, "<config>", "</config>"); String[] tokens = StringUtils.substringsBetween(config, "<param", "<param"); Properties properties = new Properties(); for (String token : tokens) { String key = StringUtils.substringBetween(token, "name=\"", "\">"); validateRiceProperties(token, key); String value = StringUtils.substringBetween(token + "</param>", "\">", "</param>"); properties.setProperty(key, value); } return properties; }
public static String[] substringsBetween(ActionContext actionContext){ Thing self = actionContext.getObject("self"); String str = (String) self.doAction("getStr", actionContext); String open = (String) self.doAction("getOpen", actionContext); String close = (String) self.doAction("getClose", actionContext); return StringUtils.substringsBetween(str, open, close); }
List<String> tokens = Arrays.asList(StringUtils.substringsBetween(resolvedUserData, "%%", "%%")); List<String> invalidTokens = tokens.stream() .filter(t -> !validTokens.contains(t))
List<String> tokens = Arrays.asList(StringUtils.substringsBetween(resolvedUserData, "%%", "%%")); List<String> invalidTokens = tokens.stream() .filter(t -> !validTokens.contains(t))