/** * <p>Case in-sensitive find of the first index within a CharSequence.</p> * * <p>A {@code null} CharSequence will return {@code -1}. * A negative start position is treated as zero. * An empty ("") search CharSequence always matches. * A start position greater than the string length only matches * an empty search CharSequence.</p> * * <pre> * StringUtils.indexOfIgnoreCase(null, *) = -1 * StringUtils.indexOfIgnoreCase(*, null) = -1 * StringUtils.indexOfIgnoreCase("", "") = 0 * StringUtils.indexOfIgnoreCase("aabaabaa", "a") = 0 * StringUtils.indexOfIgnoreCase("aabaabaa", "b") = 2 * StringUtils.indexOfIgnoreCase("aabaabaa", "ab") = 1 * </pre> * * @param str the CharSequence to check, may be null * @param searchStr the CharSequence to find, may be null * @return the first index of the search CharSequence, * -1 if no match or {@code null} string input * @since 2.5 * @since 3.0 Changed signature from indexOfIgnoreCase(String, String) to indexOfIgnoreCase(CharSequence, CharSequence) */ public static int indexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) { return indexOfIgnoreCase(str, searchStr, 0); }
private int searchNext(FlowableEmitter<CodeNode> emitter, String text, JavaNode javaClass, String code, int startPos, boolean ignoreCase) { int pos; if (ignoreCase) { pos = StringUtils.indexOfIgnoreCase(code, text, startPos); } else { pos = code.indexOf(text, startPos); } if (pos == -1) { return -1; } int lineStart = 1 + code.lastIndexOf(CodeWriter.NL, pos); int lineEnd = code.indexOf(CodeWriter.NL, pos + text.length()); StringRef line = StringRef.subString(code, lineStart, lineEnd == -1 ? code.length() : lineEnd); emitter.onNext(new CodeNode(nodeCache.makeFrom(javaClass), -pos, line.trim())); return lineEnd; }
/** * Extracts the username from the specified DN. If the username cannot be extracted because the CN is in an unrecognized format, the entire CN is returned. If the CN cannot be extracted because * the DN is in an unrecognized format, the entire DN is returned. * * @param dn the dn to extract the username from * @return the exatracted username */ public static String extractUsername(String dn) { String username = dn; // ensure the dn is specified if (StringUtils.isNotBlank(dn)) { // determine the separate final String separator = StringUtils.indexOfIgnoreCase(dn, "/cn=") > 0 ? "/" : ","; // attempt to locate the cd final String cnPattern = "cn="; final int cnIndex = StringUtils.indexOfIgnoreCase(dn, cnPattern); if (cnIndex >= 0) { int separatorIndex = StringUtils.indexOf(dn, separator, cnIndex); if (separatorIndex > 0) { username = StringUtils.substring(dn, cnIndex + cnPattern.length(), separatorIndex); } else { username = StringUtils.substring(dn, cnIndex + cnPattern.length()); } } } return username; }
@Test public void testIndexOfIgnoreCase_String() { assertEquals(-1, StringUtils.indexOfIgnoreCase(null, null)); assertEquals(-1, StringUtils.indexOfIgnoreCase(null, "")); assertEquals(-1, StringUtils.indexOfIgnoreCase("", null)); assertEquals(0, StringUtils.indexOfIgnoreCase("", "")); assertEquals(0, StringUtils.indexOfIgnoreCase("aabaabaa", "a")); assertEquals(0, StringUtils.indexOfIgnoreCase("aabaabaa", "A")); assertEquals(2, StringUtils.indexOfIgnoreCase("aabaabaa", "b")); assertEquals(2, StringUtils.indexOfIgnoreCase("aabaabaa", "B")); assertEquals(1, StringUtils.indexOfIgnoreCase("aabaabaa", "ab")); assertEquals(1, StringUtils.indexOfIgnoreCase("aabaabaa", "AB")); assertEquals(0, StringUtils.indexOfIgnoreCase("aabaabaa", "")); }
@Test public void testIndexOfIgnoreCase_StringInt() { assertEquals(1, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", -1)); assertEquals(1, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 0)); assertEquals(1, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 1)); assertEquals(4, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 2)); assertEquals(4, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 3)); assertEquals(4, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 4)); assertEquals(-1, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 5)); assertEquals(-1, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 6)); assertEquals(-1, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 7)); assertEquals(-1, StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 8)); assertEquals(1, StringUtils.indexOfIgnoreCase("aab", "AB", 1)); assertEquals(5, StringUtils.indexOfIgnoreCase("aabaabaa", "", 5)); assertEquals(-1, StringUtils.indexOfIgnoreCase("ab", "AAB", 0)); assertEquals(-1, StringUtils.indexOfIgnoreCase("aab", "AAB", 1)); assertEquals(-1, StringUtils.indexOfIgnoreCase("abc", "", 9)); }
@Override protected int handleIndex(CharSequence str, CharSequence searchStr, int startPos) { return StringUtils.indexOfIgnoreCase(str, searchStr, startPos); }
/** * <p>Case in-sensitive find of the first index within a CharSequence.</p> * * <p>A {@code null} CharSequence will return {@code -1}. * A negative start position is treated as zero. * An empty ("") search CharSequence always matches. * A start position greater than the string length only matches * an empty search CharSequence.</p> * * <pre> * StringUtils.indexOfIgnoreCase(null, *) = -1 * StringUtils.indexOfIgnoreCase(*, null) = -1 * StringUtils.indexOfIgnoreCase("", "") = 0 * StringUtils.indexOfIgnoreCase("aabaabaa", "a") = 0 * StringUtils.indexOfIgnoreCase("aabaabaa", "b") = 2 * StringUtils.indexOfIgnoreCase("aabaabaa", "ab") = 1 * </pre> * * @param str the CharSequence to check, may be null * @param searchStr the CharSequence to find, may be null * @return the first index of the search CharSequence, * -1 if no match or {@code null} string input * @since 2.5 * @since 3.0 Changed signature from indexOfIgnoreCase(String, String) to indexOfIgnoreCase(CharSequence, CharSequence) */ public static int indexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) { return indexOfIgnoreCase(str, searchStr, 0); }
/** * <p>Case in-sensitive find of the first index within a CharSequence.</p> * * <p>A {@code null} CharSequence will return {@code -1}. * A negative start position is treated as zero. * An empty ("") search CharSequence always matches. * A start position greater than the string length only matches * an empty search CharSequence.</p> * * <pre> * StringUtils.indexOfIgnoreCase(null, *) = -1 * StringUtils.indexOfIgnoreCase(*, null) = -1 * StringUtils.indexOfIgnoreCase("", "") = 0 * StringUtils.indexOfIgnoreCase("aabaabaa", "a") = 0 * StringUtils.indexOfIgnoreCase("aabaabaa", "b") = 2 * StringUtils.indexOfIgnoreCase("aabaabaa", "ab") = 1 * </pre> * * @param str the CharSequence to check, may be null * @param searchStr the CharSequence to find, may be null * @return the first index of the search CharSequence, * -1 if no match or {@code null} string input * @since 2.5 * @since 3.0 Changed signature from indexOfIgnoreCase(String, String) to indexOfIgnoreCase(CharSequence, CharSequence) */ public static int indexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) { return indexOfIgnoreCase(str, searchStr, 0); }
/** * <p>Case in-sensitive find of the first index within a CharSequence.</p> * * <p>A {@code null} CharSequence will return {@code -1}. * A negative start position is treated as zero. * An empty ("") search CharSequence always matches. * A start position greater than the string length only matches * an empty search CharSequence.</p> * * <pre> * StringUtils.indexOfIgnoreCase(null, *) = -1 * StringUtils.indexOfIgnoreCase(*, null) = -1 * StringUtils.indexOfIgnoreCase("", "") = 0 * StringUtils.indexOfIgnoreCase("aabaabaa", "a") = 0 * StringUtils.indexOfIgnoreCase("aabaabaa", "b") = 2 * StringUtils.indexOfIgnoreCase("aabaabaa", "ab") = 1 * </pre> * * @param str the CharSequence to check, may be null * @param searchStr the CharSequence to find, may be null * @return the first index of the search CharSequence, * -1 if no match or {@code null} string input * @since 2.5 * @since 3.0 Changed signature from indexOfIgnoreCase(String, String) to indexOfIgnoreCase(CharSequence, CharSequence) */ public static int indexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) { return indexOfIgnoreCase(str, searchStr, 0); }
/** * Extracts the password part from the specified input * * @param filePathAndPassword * input containing file path concatenated using {@value #PASSWORD_SEPARATOR_CHARACTER} with (optional) password * @return the password part */ static String extractPassword(String filePathAndPassword) { if (!StringUtils.containsIgnoreCase(filePathAndPassword, PDF_EXTENSION_AND_PASSWORD_SEPARATOR)) { return ""; } return filePathAndPassword.substring(StringUtils.indexOfIgnoreCase(filePathAndPassword, PDF_EXTENSION_AND_PASSWORD_SEPARATOR) + 1 + PDF_EXTENSION.length()); }
/** * Extracts the file path part from the specified input * * @param filePathAndPassword * input containing file path concatenated using {@value #PASSWORD_SEPARATOR_CHARACTER} with (optional) password * @return file path part */ static String extractFilePath(String filePathAndPassword) { if (!StringUtils.containsIgnoreCase(filePathAndPassword, PDF_EXTENSION_AND_PASSWORD_SEPARATOR)) { return filePathAndPassword; } return filePathAndPassword.substring(0, StringUtils.indexOfIgnoreCase(filePathAndPassword, PDF_EXTENSION_AND_PASSWORD_SEPARATOR) + PDF_EXTENSION.length()); }
/** * Find the names of a query's named parameters. */ private static List<String> findQueryParameterNames(final String queryString) { final List<String> list = new ArrayList<>(); int i = StringUtils.indexOfIgnoreCase(queryString, "where"); while (i != -1) { final int start = queryString.indexOf(":", i); final int end = findParameterNameEnd(queryString, start); if (end != -1) { list.add(queryString.substring(start + 1, end)); } i = end != -1 ? end : -1; } return list; }
public String cropValue(String stdOut, String begin, String end) { if (containsIgnoreCase(stdOut, begin)) { return trimToEmpty(substring(stdOut, indexOfIgnoreCase(stdOut, begin) + length(begin), max(0, indexOfIgnoreCase(stdOut, end, indexOfIgnoreCase(stdOut, begin) + length(begin))))); } else { return ""; } }
private String parseMatcherSql(String matcherSql) { String aliasName = ""; String[] strings; if (StringUtils.isEmpty(matcherSql)) { strings = BOUND_SQL.substring(StringUtils.indexOfIgnoreCase(BOUND_SQL, "FROM") + 4).trim().split("\\s+"); if (1 == strings.length) return strings[0].trim(); else return strings[strings.length - 1]; } strings = matcherSql.split("\\s+"); if (1 == strings.length) return strings[0]; if (2 == strings.length || 3 == strings.length) aliasName = strings[1].trim(); else if (4 == strings.length && !FIXED_PREFIX.contains(strings[2].substring(0, strings[2].indexOf("_") + 1))) { aliasName = strings[2].trim(); } else if (5 == strings.length && !FIXED_PREFIX.contains(strings[3].substring(0, strings[3].indexOf("_") + 1))) aliasName = strings[3].trim(); return aliasName; }
private String parseSql(String matcherSql) { if (BOUND_SQL.lastIndexOf(matcherSql.concat(".").concat(TENANT_KEY.trim()).concat(String.valueOf(SYS_COMPANY_ID))) > 0) return BOUND_SQL; if (StringUtils.isNotBlank(matcherSql) && BOUND_SQL.lastIndexOf(matcherSql.concat(".").concat(TENANT_KEY.trim()).concat(String.valueOf(SYS_COMPANY_ID)).concat(" AND ")) < 0 && StringUtils.indexOfIgnoreCase(BOUND_SQL, WHERE_KEY.trim()) > 0) TENANT_KEY = matcherSql.concat(".").concat(TENANT_KEY.trim()).concat(String.valueOf(SYS_COMPANY_ID)).concat(" AND "); else if (StringUtils.isNotBlank(matcherSql)) TENANT_KEY = matcherSql.concat(".").concat(TENANT_KEY.trim()).concat(String.valueOf(SYS_COMPANY_ID)); else if (StringUtils.indexOfIgnoreCase(BOUND_SQL, WHERE_KEY.trim()) > 0) TENANT_KEY = TENANT_KEY.trim().concat(String.valueOf(SYS_COMPANY_ID)).concat(" AND "); else TENANT_KEY = TENANT_KEY.trim().concat(String.valueOf(SYS_COMPANY_ID)); if (StringUtils.indexOfIgnoreCase(BOUND_SQL, WHERE_KEY.trim()) > 0 && StringUtils.indexOfIgnoreCase(BOUND_SQL, TENANT_KEY.trim()) < 0) { BOUND_SQL = StringUtils.replaceIgnoreCase(BOUND_SQL, WHERE_KEY.trim(), WHERE_KEY.concat(TENANT_KEY)); } else if(StringUtils.indexOfIgnoreCase(BOUND_SQL, WHERE_KEY.trim()) < 0 && StringUtils.indexOfIgnoreCase(BOUND_SQL, LIMIT_KEY.trim()) > 0) { BOUND_SQL = StringUtils.replaceIgnoreCase(BOUND_SQL, LIMIT_KEY, WHERE_KEY.concat(TENANT_KEY.concat(LIMIT_KEY))); } else if (StringUtils.indexOfIgnoreCase(BOUND_SQL, TENANT_KEY.trim()) < 0) { BOUND_SQL = BOUND_SQL.concat(WHERE_KEY.concat(TENANT_KEY)); } TENANT_KEY = TENANT_KEY_TEMP; return BOUND_SQL; }
/** * Extracts the username from the specified DN. If the username cannot be extracted because the CN is in an unrecognized format, the entire CN is returned. If the CN cannot be extracted because * the DN is in an unrecognized format, the entire DN is returned. * * @param dn the dn to extract the username from * @return the exatracted username */ public static String extractUsername(String dn) { String username = dn; // ensure the dn is specified if (StringUtils.isNotBlank(dn)) { // determine the separate final String separator = StringUtils.indexOfIgnoreCase(dn, "/cn=") > 0 ? "/" : ","; // attempt to locate the cd final String cnPattern = "cn="; final int cnIndex = StringUtils.indexOfIgnoreCase(dn, cnPattern); if (cnIndex >= 0) { int separatorIndex = StringUtils.indexOf(dn, separator, cnIndex); if (separatorIndex > 0) { username = StringUtils.substring(dn, cnIndex + cnPattern.length(), separatorIndex); } else { username = StringUtils.substring(dn, cnIndex + cnPattern.length()); } } } return username; }
/** * Extracts the username from the specified DN. If the username cannot be extracted because the CN is in an unrecognized format, the entire CN is returned. If the CN cannot be extracted because * the DN is in an unrecognized format, the entire DN is returned. * * @param dn the dn to extract the username from * @return the exatracted username */ public static String extractUsername(String dn) { String username = dn; // ensure the dn is specified if (StringUtils.isNotBlank(dn)) { // determine the separate final String separator = StringUtils.indexOfIgnoreCase(dn, "/cn=") > 0 ? "/" : ","; // attempt to locate the cd final String cnPattern = "cn="; final int cnIndex = StringUtils.indexOfIgnoreCase(dn, cnPattern); if (cnIndex >= 0) { int separatorIndex = StringUtils.indexOf(dn, separator, cnIndex); if (separatorIndex > 0) { username = StringUtils.substring(dn, cnIndex + cnPattern.length(), separatorIndex); } else { username = StringUtils.substring(dn, cnIndex + cnPattern.length()); } } } return username; }
private List<String> getFilterableColumns(String statement) { List<String> columns = new ArrayList<>(); String selectClause = statement.substring("select ".length(), StringUtils.indexOfIgnoreCase(statement, " from ")).trim(); selectClause = StringUtils.removeStartIgnoreCase(selectClause, "distinct "); for (String column : COLUMN_SEPARATOR.split(selectClause)) { // Remove the column alias. String columnWithoutAlias = column; int aliasPosition = column.lastIndexOf(" as "); if (aliasPosition > 0) { columnWithoutAlias = column.substring(0, aliasPosition).trim(); String alias = column.substring(aliasPosition + 4).trim(); if (alias.startsWith("unfilterable")) { continue; } } columns.add(columnWithoutAlias); } return columns; } }
public static int indexOfIgnoreCase(ActionContext actionContext){ Thing self = actionContext.getObject("self"); CharSequence cs1 = (CharSequence) self.doAction("getCs1", actionContext); CharSequence cs2 = (CharSequence) self.doAction("getCs2", actionContext); Integer startPos = (Integer) self.doAction("getStartPos", actionContext); return StringUtils.indexOfIgnoreCase(cs1, cs2, startPos); }
/** * Method extracts the service type name of the input state method name (e.g. getPowerState to powerStateService). * * @param stateMethodName is the state method name, which includes the needed service type name. * @return the service type name in camel case (first char lower case, e.g. powerStateService) * @throws NotAvailableException is thrown in case the input is null or no valid state (name). */ static String getServiceTypeNameFromStateMethodName(final String stateMethodName) throws NotAvailableException { Preconditions.checkNotNull(stateMethodName, "Couldn't get service type name, cause input string is null."); String serviceTypeName = stateMethodName; if (StringUtils.containsIgnoreCase(serviceTypeName, MethodRegEx.GET.getName())) { final int indexOfGet = StringUtils.indexOfIgnoreCase(serviceTypeName, MethodRegEx.GET.getName()); final int lengthOfGet = MethodRegEx.GET.getName().length(); serviceTypeName = serviceTypeName.substring(indexOfGet + lengthOfGet); serviceTypeName = firstCharToLowerCase(serviceTypeName); if (StringUtils.contains(serviceTypeName, MethodRegEx.STATE.getName())) { final int indexOfState = serviceTypeName.indexOf(MethodRegEx.STATE.getName()); final int lengthOfState = MethodRegEx.STATE.getName().length(); serviceTypeName = serviceTypeName.substring(0, indexOfState + lengthOfState); serviceTypeName += MethodRegEx.SERVICE.getName(); } } if (OntConfig.SERVICE_NAME_MAP.keySet().contains(serviceTypeName)) { return serviceTypeName; } else { throw new NotAvailableException("Input string is no state (method) name! " + serviceTypeName); } }