org.apache.commons.lang3.StringUtils.indexOfIgnoreCase()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(19.0k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中org.apache.commons.lang3.StringUtils.indexOfIgnoreCase()方法的一些代码示例,展示了StringUtils.indexOfIgnoreCase()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.indexOfIgnoreCase()方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:indexOfIgnoreCase

StringUtils.indexOfIgnoreCase介绍

[英]Case in-sensitive find of the first index within a CharSequence.

A null CharSequence will return -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.

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

[中]字符序列中第一个索引的区分大小写的查找。
空字符序列将返回-1。负起始位置被视为零。空(“”)搜索字符序列始终匹配。大于字符串长度的起始位置仅与空搜索字符序列匹配。

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

代码示例

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * <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);
}

代码示例来源:origin: skylot/jadx

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;
}

代码示例来源:origin: apache/nifi

/**
 * 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;
}

代码示例来源:origin: org.apache.commons/commons-lang3

@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", ""));
}

代码示例来源:origin: org.apache.commons/commons-lang3

@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));
}

代码示例来源:origin: virjar/vscrawler

@Override
protected int handleIndex(CharSequence str, CharSequence searchStr, int startPos) {
  return StringUtils.indexOfIgnoreCase(str, searchStr, startPos);
}

代码示例来源:origin: de.knightsoft-net/gwt-commons-lang3

/**
 * <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);
}

代码示例来源:origin: io.virtdata/virtdata-lib-curves4

/**
 * <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);
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

/**
 * <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);
}

代码示例来源:origin: torakiki/sejda

/**
 * 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());
}

代码示例来源:origin: torakiki/sejda

/**
 * 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());
}

代码示例来源:origin: com.atlassian.hibernate/hibernate.adapter

/**
 * 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;
}

代码示例来源:origin: CloudSlang/cs-actions

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 "";
  }
}

代码示例来源:origin: lzh-boy/cskit

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;
}

代码示例来源:origin: lzh-boy/cskit

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;
}

代码示例来源:origin: org.apache.nifi/nifi-security-utils

/**
 * 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;
}

代码示例来源:origin: org.apache.nifi.registry/nifi-registry-security-utils

/**
 * 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;
}

代码示例来源:origin: org.xwiki.platform/xwiki-platform-query-manager

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;
  }
}

代码示例来源:origin: org.xworker/xworker_core

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);
}

代码示例来源:origin: org.openbase.bco/ontology.lib

/**
 * 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);
  }
}

相关文章

微信公众号

最新文章

更多

StringUtils类方法