/** * <p>Search a CharSequence to find the first index of any * character in the given set of characters.</p> * * <p>A {@code null} String will return {@code -1}. * A {@code null} search string will return {@code -1}.</p> * * <pre> * StringUtils.indexOfAny(null, *) = -1 * StringUtils.indexOfAny("", *) = -1 * StringUtils.indexOfAny(*, null) = -1 * StringUtils.indexOfAny(*, "") = -1 * StringUtils.indexOfAny("zzabyycdxx", "za") = 0 * StringUtils.indexOfAny("zzabyycdxx", "by") = 3 * StringUtils.indexOfAny("aba","z") = -1 * </pre> * * @param cs the CharSequence to check, may be null * @param searchChars the chars to search for, may be null * @return the index of any of the chars, -1 if no match or null input * @since 2.0 * @since 3.0 Changed signature from indexOfAny(String, String) to indexOfAny(CharSequence, String) */ public static int indexOfAny(final CharSequence cs, final String searchChars) { if (isEmpty(cs) || isEmpty(searchChars)) { return INDEX_NOT_FOUND; } return indexOfAny(cs, searchChars.toCharArray()); }
/** * See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html */ @Test public void testIndexOfAny_StringCharArrayWithSupplementaryChars() { assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000.toCharArray())); assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001.toCharArray())); assertEquals(0, StringUtils.indexOfAny(CharU20000, CharU20000.toCharArray())); assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001.toCharArray())); }
/** * See http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html */ @Test public void testIndexOfAny_StringStringWithSupplementaryChars() { assertEquals(0, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20000)); assertEquals(2, StringUtils.indexOfAny(CharU20000 + CharU20001, CharU20001)); assertEquals(0, StringUtils.indexOfAny(CharU20000, CharU20000)); assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU20001)); }
@Test public void testIndexOfAny_StringCharArray() { assertEquals(-1, StringUtils.indexOfAny(null, (char[]) null)); assertEquals(-1, StringUtils.indexOfAny(null, new char[0])); assertEquals(-1, StringUtils.indexOfAny(null, 'a','b')); assertEquals(-1, StringUtils.indexOfAny("", (char[]) null)); assertEquals(-1, StringUtils.indexOfAny("", new char[0])); assertEquals(-1, StringUtils.indexOfAny("", 'a','b')); assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", (char[]) null)); assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", new char[0])); assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", 'z','a')); assertEquals(3, StringUtils.indexOfAny("zzabyycdxx", 'b','y')); assertEquals(-1, StringUtils.indexOfAny("ab", 'z')); }
@Test public void testIndexOfAny_StringString() { assertEquals(-1, StringUtils.indexOfAny(null, (String) null)); assertEquals(-1, StringUtils.indexOfAny(null, "")); assertEquals(-1, StringUtils.indexOfAny(null, "ab")); assertEquals(-1, StringUtils.indexOfAny("", (String) null)); assertEquals(-1, StringUtils.indexOfAny("", "")); assertEquals(-1, StringUtils.indexOfAny("", "ab")); assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", (String) null)); assertEquals(-1, StringUtils.indexOfAny("zzabyycdxx", "")); assertEquals(0, StringUtils.indexOfAny("zzabyycdxx", "za")); assertEquals(3, StringUtils.indexOfAny("zzabyycdxx", "by")); assertEquals(-1, StringUtils.indexOfAny("ab", "z")); }
@Test public void testIndexOfAny_StringStringArray() { assertEquals(-1, StringUtils.indexOfAny(null, (String[]) null)); assertEquals(-1, StringUtils.indexOfAny(null, FOOBAR_SUB_ARRAY)); assertEquals(-1, StringUtils.indexOfAny(FOOBAR, (String[]) null)); assertEquals(2, StringUtils.indexOfAny(FOOBAR, FOOBAR_SUB_ARRAY)); assertEquals(-1, StringUtils.indexOfAny(FOOBAR, new String[0])); assertEquals(-1, StringUtils.indexOfAny(null, new String[0])); assertEquals(-1, StringUtils.indexOfAny("", new String[0])); assertEquals(-1, StringUtils.indexOfAny(FOOBAR, new String[] {"llll"})); assertEquals(0, StringUtils.indexOfAny(FOOBAR, new String[] {""})); assertEquals(0, StringUtils.indexOfAny("", new String[] {""})); assertEquals(-1, StringUtils.indexOfAny("", new String[] {"a"})); assertEquals(-1, StringUtils.indexOfAny("", new String[] {null})); assertEquals(-1, StringUtils.indexOfAny(FOOBAR, new String[] {null})); assertEquals(-1, StringUtils.indexOfAny(null, new String[] {null})); }
public static String packageOf(String fullyQualifiedType) { int indexOfClassName = indexOfAny(fullyQualifiedType, CAPITAL_LETTERS); if (indexOfClassName > 0) { return fullyQualifiedType.substring(0, indexOfClassName - 1); } // primitive valueType => no package return ""; }
protected static String[] splitOperator(String value) { int first = StringUtils.indexOfAny(value, '=', '>', '<'); int last = StringUtils.lastIndexOfAny(value, "=", ">", "<"); if (first == StringUtils.INDEX_NOT_FOUND) { throw new IllegalArgumentException("Malformed filter. Expected <KEY><OP><VALUE>"); } return new String[]{value.substring(0, first), value.substring(first, last + 1), value.substring(last + 1)}; }
public static int getTailingNumber(String s, int defaultValue) { int numberStart = StringUtils.indexOfAny(s, "123456789"); if (numberStart == StringUtils.INDEX_NOT_FOUND) { return defaultValue; } return NumberUtils.toInt(s.substring(numberStart), defaultValue); }
public String detectPossibleDateTimeString(String text) { String possibleDate = StringUtils.substringBefore(text, "\n"); int dateStart = StringUtils.indexOfAny(possibleDate, VALID_WORK_YEARS_ARRAY); if (dateStart == StringUtils.INDEX_NOT_FOUND) { dateStart = StringUtils.indexOfAny(possibleDate, VALID_WORK_YEARS_SHORT_ARRAY); if (dateStart != StringUtils.INDEX_NOT_FOUND) { // OK for years possibleDate = "20" + possibleDate.substring(dateStart); if (possibleDate.matches("20[0-9][0-9][\\-\\./年]?\\d+.+")) { dateStart = 0; } } } if (dateStart < 0 || dateStart >= possibleDate.length()) { return null; } int dateEnd = Math.min(possibleDate.length(), dateStart + MAX_DATE_TIME_STR_LENGTH); possibleDate = possibleDate.substring(dateStart, dateEnd); possibleDate = possibleDate.replaceAll("[\\./年月]", "-").trim(); return possibleDate; }
/** * <p>Search a CharSequence to find the first index of any * character in the given set of characters.</p> * * <p>A {@code null} String will return {@code -1}. * A {@code null} search string will return {@code -1}.</p> * * <pre> * StringUtils.indexOfAny(null, *) = -1 * StringUtils.indexOfAny("", *) = -1 * StringUtils.indexOfAny(*, null) = -1 * StringUtils.indexOfAny(*, "") = -1 * StringUtils.indexOfAny("zzabyycdxx", "za") = 0 * StringUtils.indexOfAny("zzabyycdxx", "by") = 3 * StringUtils.indexOfAny("aba","z") = -1 * </pre> * * @param cs the CharSequence to check, may be null * @param searchChars the chars to search for, may be null * @return the index of any of the chars, -1 if no match or null input * @since 2.0 * @since 3.0 Changed signature from indexOfAny(String, String) to indexOfAny(CharSequence, String) */ public static int indexOfAny(final CharSequence cs, final String searchChars) { if (isEmpty(cs) || isEmpty(searchChars)) { return INDEX_NOT_FOUND; } return indexOfAny(cs, searchChars.toCharArray()); }
/** * Gets a type name without any dots in it if they are present -- this is for nested classes * @param typeName String name of the type * @return Type without any {@code '.'} characters */ public static String getTypeNameWithoutDots(String typeName) { int indexOfClassName = indexOfAny(typeName, CAPITAL_LETTERS); final String typeSimpleNameWithOuterClass; if (indexOfClassName > 0) { typeSimpleNameWithOuterClass = typeName.substring(indexOfClassName); } else { // primitive valueType => no package typeSimpleNameWithOuterClass = typeName; } return remove(typeSimpleNameWithOuterClass, "."); }
/** * <p>Search a CharSequence to find the first index of any * character in the given set of characters.</p> * * <p>A {@code null} String will return {@code -1}. * A {@code null} search string will return {@code -1}.</p> * * <pre> * StringUtils.indexOfAny(null, *) = -1 * StringUtils.indexOfAny("", *) = -1 * StringUtils.indexOfAny(*, null) = -1 * StringUtils.indexOfAny(*, "") = -1 * StringUtils.indexOfAny("zzabyycdxx", "za") = 0 * StringUtils.indexOfAny("zzabyycdxx", "by") = 3 * StringUtils.indexOfAny("aba","z") = -1 * </pre> * * @param cs the CharSequence to check, may be null * @param searchChars the chars to search for, may be null * @return the index of any of the chars, -1 if no match or null input * @since 2.0 * @since 3.0 Changed signature from indexOfAny(String, String) to indexOfAny(CharSequence, String) */ public static int indexOfAny(final CharSequence cs, final String searchChars) { if (isEmpty(cs) || isEmpty(searchChars)) { return INDEX_NOT_FOUND; } return indexOfAny(cs, searchChars.toCharArray()); }
/** * <p>Search a CharSequence to find the first index of any * character in the given set of characters.</p> * * <p>A {@code null} String will return {@code -1}. * A {@code null} search string will return {@code -1}.</p> * * <pre> * StringUtils.indexOfAny(null, *) = -1 * StringUtils.indexOfAny("", *) = -1 * StringUtils.indexOfAny(*, null) = -1 * StringUtils.indexOfAny(*, "") = -1 * StringUtils.indexOfAny("zzabyycdxx", "za") = 0 * StringUtils.indexOfAny("zzabyycdxx", "by") = 3 * StringUtils.indexOfAny("aba","z") = -1 * </pre> * * @param cs the CharSequence to check, may be null * @param searchChars the chars to search for, may be null * @return the index of any of the chars, -1 if no match or null input * @since 2.0 * @since 3.0 Changed signature from indexOfAny(String, String) to indexOfAny(CharSequence, String) */ public static int indexOfAny(final CharSequence cs, final String searchChars) { if (isEmpty(cs) || isEmpty(searchChars)) { return INDEX_NOT_FOUND; } return indexOfAny(cs, searchChars.toCharArray()); }
public static String generateConcatForXPath(String xpathString) { String returnString = ""; String searchString = xpathString; char[] quoteChars = new char[] { '\'', '"' }; int quotePos = StringUtils.indexOfAny(searchString, quoteChars); if (quotePos == -1) { returnString = "'" + searchString + "'"; } else { returnString = "concat("; LOGGER.debug("Current concatenation: " + returnString); while (quotePos != -1) { String subString = searchString.substring(0, quotePos); returnString += "'" + subString + "', "; LOGGER.debug("Current concatenation: " + returnString); if (searchString.substring(quotePos, quotePos + 1).equals("'")) { returnString += "\"'\", "; LOGGER.debug("Current concatenation: " + returnString); } else { returnString += "'\"', "; LOGGER.debug("Current concatenation: " + returnString); } searchString = searchString.substring(quotePos + 1, searchString.length()); quotePos = StringUtils.indexOfAny(searchString, quoteChars); } returnString += "'" + searchString + "')"; LOGGER.debug("Concatenation result: " + returnString); } return returnString; }
public static String generateConcatForXPath(String xpathString) { String returnString = ""; String searchString = xpathString; char[] quoteChars = new char[] { '\'', '"' }; int quotePos = StringUtils.indexOfAny(searchString, quoteChars); if (quotePos == -1) { returnString = "'" + searchString + "'"; } else { returnString = "concat("; LOGGER.debug("Current concatenation: " + returnString); while (quotePos != -1) { String subString = searchString.substring(0, quotePos); returnString += "'" + subString + "', "; LOGGER.debug("Current concatenation: " + returnString); if (searchString.substring(quotePos, quotePos + 1).equals("'")) { returnString += "\"'\", "; LOGGER.debug("Current concatenation: " + returnString); } else { returnString += "'\"', "; LOGGER.debug("Current concatenation: " + returnString); } searchString = searchString.substring(quotePos + 1, searchString.length()); quotePos = StringUtils.indexOfAny(searchString, quoteChars); } returnString += "'" + searchString + "')"; LOGGER.debug("Concatenation result: " + returnString); } return returnString; }
OrderElem elem = it.next(); String expr = evaluateExpression(elem.getExpr(), ValueType.STRING); if (StringUtils.indexOfAny(expr, aggregateFuncs) != -1) { continue;
int urlRemainderPos = StringUtils.indexOfAny(path, '?', '#'); if (urlRemainderPos >= 0) { urlRemainder = path.substring(urlRemainderPos);
public static int indexOfAny(ActionContext actionContext){ Thing self = actionContext.getObject("self"); CharSequence cs1 = (CharSequence) self.doAction("getCs1", actionContext); String searchChars = (String) self.doAction("getSearchChars", actionContext); return StringUtils.indexOfAny(cs1,searchChars); }
public static int indexOfAnyStr(ActionContext actionContext){ Thing self = actionContext.getObject("self"); CharSequence cs = (CharSequence) self.doAction("getCs", actionContext); CharSequence[] invalidChars = (CharSequence[]) self.doAction("getSearchStrs", actionContext); return StringUtils.indexOfAny(cs, invalidChars); }