CharMatcher indexIn - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for CharMatcher indexIn method.

This code example shows how to use the following methods:indexIn
        if (value.startsWith(SEPARATOR) || value.endsWith(SEPARATOR)) { 
            throw new InvalidPluginIdException(value, ID_SEPARATOR_ON_START_OR_END); 
        } else if (value.contains(PluginId.SEPARATOR + PluginId.SEPARATOR)) { 
            throw new InvalidPluginIdException(value, DOUBLE_SEPARATOR); 
        } else { 
            int invalidCharIndex = PluginId.INVALID_PLUGIN_ID_CHAR_MATCHER.indexIn(value); 
            if (invalidCharIndex >= 0) { 
                char invalidChar = value.charAt(invalidCharIndex); 
                throw new InvalidPluginIdException(value, invalidPluginIdCharMessage(invalidChar)); 
            } 
        } 
    } 
 
    public static String invalidPluginIdCharMessage(char invalidChar) { 
        return "Plugin id contains invalid char '" + invalidChar + "' (only " + PluginId.PLUGIN_ID_VALID_CHARS_DESCRIPTION + " characters are valid)"; 
    } 
 
    public boolean isQualified() { 
        return value.contains(PluginId.SEPARATOR); 
    } 
6
CodeRank
This code example shows how to use the following methods:indexIn
   public void validate(String name) {
 
      if (name == null || name.length() < min || name.length() > max)
         throw exception(name, "Can't be null or empty. Length must be " + min + " to " + max
                  + " symbols."); 
      if (CharMatcher.JAVA_LETTER_OR_DIGIT.indexIn(name) != 0)
         throw exception(name, "Should start with letter/number");
      if (!name.toLowerCase().equals(name))
         throw exception(name, "Should be only lowercase");
 
      /* 
       * The name must be a valid DNS name. From wikipedia: "The characters allowed in a label are a 
       * subset of the ASCII character set, a and includes the characters a through z, A through Z, 
       * digits 0 through 9". From Azure: Every Dash (-) Must Be Immediately Preceded and Followed 
       * by a Letter or Number. 
       */ 
      CharMatcher range = getAcceptableRange();
      if (!range.matchesAllOf(name))
         throw exception(name, "Should have lowercase ASCII letters, " + "numbers, or dashes");
   } 
6
CodeRank
This code example shows how to use the following methods:indexIn
  } 
 
  @Override 
  public HttpUrlBuilder host(String host) {
    // http://en.wikipedia.org/wiki/Hostname#Restrictions%5Fon%5Fvalid%5Fhost%5Fnames 
    int indexIn = HOST_NAME_ILLEGAL_CHARS.indexIn(host);
    if (indexIn >= 0) {
      throw new IllegalArgumentException("character '" + host.charAt(indexIn) + "' of host name '" + host + "' is invalid (only [a-zA-Z0-9.-] are allowed in host names)");
    } 
    this.host = host;
    return this;
  } 
 
  @Override 
  public HttpUrlBuilder port(int port) {
    if (port == 0 || port < -1) {
      throw new IllegalArgumentException("port must be greater than 0 or exactly -1, is " + port);
    } 
    this.port = port;
    return this;
5
CodeRank
This code example shows how to use the following methods:indexIn
  public static String trimLeadingSlashes(@NotNull String url) {
    return SLASH_MATCHER.trimLeadingFrom(url);
  } 
 
  public static String trimParameters(@NotNull String url) {
    int end = PARAM_CHAR_MATCHER.indexIn(url);
    return end != -1 ? url.substring(0, end) : url;
  } 
 
  /** 
   * Splits the url into 2 parts: the scheme ("http", for instance) and the rest of the URL. <br/> 
   * Scheme separator is not included neither to the scheme part, nor to the url part. <br/> 
   * The scheme can be absent, in which case empty string is written to the first item of the Pair. 
   */ 
  @NotNull 
  public static Pair<String, String> splitScheme(@NotNull String url) {
    ArrayList<String> list = Lists.newArrayList(Splitter.on(URLUtil.SCHEME_SEPARATOR).limit(2).split(url));
    if (list.size() == 1) {
      return Pair.create("", list.get(0));
    } 
4
CodeRank
This code example shows how to use the following methods:indexIn
        assertThat(CharMatcher.DIGIT.countIn("Hello 1234 567")).isEqualTo(7);
    } 
 
    @Test
    public void shouldReturnFirstIndexOfFirstWhitespace() throws Exception {
        assertThat(CharMatcher.WHITESPACE.indexIn("Hello 1234 567")).isEqualTo(5);
    } 
 
    @Test
    public void shouldReturnLastIndexOfFirstWhitespace() throws Exception {
        assertThat(CharMatcher.WHITESPACE.lastIndexIn("Hello 1234 567")).isEqualTo(10);
    } 
 
    @Test
    public void shouldRemoveDigitsBetween3and6() throws Exception {
        assertThat(CharMatcher.inRange('3', '6').removeFrom("Hello 1234 567")).isEqualTo("Hello 12 7");
    } 
 
    @Test
    public void shouldRemoveAllExceptDigitsBetween3and6() throws Exception {
4
CodeRank
This code example shows how to use the following methods:indexIn
public class DocletLinkRenderer extends LinkRenderer { 
 
    @Override 
    public Rendering render(WikiLinkNode node) {
        String url = node.getText().trim();
        int pos = CharMatcher.WHITESPACE.indexIn(url);
        String text = url;
        if ( pos >= 0 ) {
            text = url.substring(pos).trim();
            url = url.substring(0, pos);
        } 
        return new Rendering(url, text);
    } 
} 
4
CodeRank
This code example shows how to use the following methods:indexIn
            report.error(newMsg(data, bundle, "err.format.base64.badLength")
                .putArgument("length", input.length()));
            return; 
        } 
 
        final int index
            = NOT_BASE64.indexIn(PATTERN.matcher(input).replaceFirst(""));
 
        if (index == -1)
            return; 
 
        report.error(newMsg(data, bundle, "err.format.base64.illegalChars")
            .putArgument("character", Character.toString(input.charAt(index)))
            .putArgument("index", index));
    } 
} 
4
CodeRank
This code example shows how to use the following methods:indexIn
    } 
 
    final String userInfo = uri.getUserInfo();
    if (userInfo != null) {
      // the first colon is the delimiter between the username and the password 
      int index = USER_PASS_SEPARATOR.indexIn(userInfo);
      if (index > 0) {
        storage.put(USERNAME, userInfo.substring(0, index));
        storage.put(PASSWORD, userInfo.substring(index+1));
      } else { 
        storage.put(USERNAME, userInfo);
      } 
    } 
  } 
 
  private static void addQuery(URI uri, Map<String, String> storage) {
    String query = uri.getQuery();
    if (query != null) {
      storage.putAll(QUERY_SPLITTER.split(query));
    } 
3
CodeRank
This code example shows how to use the following methods:indexIn
    } 
 
    final String userInfo = uri.getUserInfo();
    if (userInfo != null) {
      // the first colon is the delimiter between the username and the password 
      int index = USER_PASS_SEPARATOR.indexIn(userInfo);
      if (index > 0) {
        storage.put(USERNAME, userInfo.substring(0, index));
        storage.put(PASSWORD, userInfo.substring(index+1));
      } else { 
        storage.put(USERNAME, userInfo);
      } 
    } 
  } 
 
  private static void addQuery(String query, Map<String, String> storage) {
    if (query != null) {
      storage.putAll(QUERY_SPLITTER.split(query));
    } 
  } 
2
CodeRank
indexIn Method Overview
Returns the index of the first matching character in a character sequence, starting from a given position, or -1 if no character matches after that position.
See Code Examples for other Guava CharMatcher Methods: