Guava CharMatcher - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:replaceFrom, trimAndCollapseFrom
This code example shows how to use the following methods:trimFrom
    @Override 
    public Object call(Properties bindings, Object[] args) {
        if (args.length == 1) { 
            Object s1 = args[0]; 
            if (s1 != null && s1 instanceof String) {
                return CharMatcher.WHITESPACE.trimFrom((String) s1);
            } 
        } 
        return new EvalError("Invalid parameters"); 
    } 
    @Override 
    public void write(JSONWriter writer, Properties options)
        throws JSONException {
     
        writer.object();
        writer.key("description"); writer.value("Returns copy of the string, with leading and trailing whitespace omitted.");
        writer.key("params"); writer.value("string s");
        writer.key("returns"); writer.value("string");
        writer.endObject();
    } 
6
CodeRank
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:trimFrom
  @VisibleForTesting 
  static PythonVersion extractPythonVersion( 
      Path pythonPath,
      ProcessExecutor.Result versionResult) {
    if (versionResult.getExitCode() == 0) {
      String versionString = CharMatcher.WHITESPACE.trimFrom(versionResult.getStderr().get());
      Matcher matcher = PYTHON_VERSION_REGEX.matcher(versionString);
      if (!matcher.matches()) {
        throw new HumanReadableException( 
            "`%s --version` returned an invalid version string %s", 
            pythonPath,
            versionString);
      } 
      return new PythonVersion(matcher.group(1));
    } else { 
      throw new HumanReadableException(versionResult.getStderr().get());
    } 
  } 
} 
5
CodeRank
This code example shows how to use the following methods:removeFrom
    { 
    } 
 
    public static boolean isBlank(final String str)
    { 
        return CharMatcher.WHITESPACE.removeFrom(Strings.nullToEmpty(str)).length() == 0;
    } 
} 
5
CodeRank
This code example shows how to use the following methods:trimTrailingFrom
	protected String indent(String text, int amount) {
		return IndentUtils.indent(text, amount);
	} 
	 
	protected String trimEnd(String string) {
		return CharMatcher.WHITESPACE.trimTrailingFrom(string);
	} 
 
} 
5
CodeRank
This code example shows how to use the following methods:trimLeadingFrom
		} 
		return string;
	} 
  
	public static int baseIndentation(String text) {
		return text.length() - INDENTATION_MATCHER.trimLeadingFrom(text).length();
	} 
 
	public static boolean containsNesting(String text) {
		return text.contains("\n" + spaces(baseIndentation(text)+1));
	} 
 
	public static boolean hasContentOnFirstLine(String text) {
		int endOfFirstLine = text.contains("\n") ? text.indexOf('\n') : text.length();
		return StringUtils.isNotBlank(text.substring(0, endOfFirstLine));
	} 
 
	public static String describe(boolean isIndentWithTabs, int indentationSize) {
		return indentationSize + (isIndentWithTabs ? " tab" : " space") + (indentationSize == 1 ? "" : "s");
	} 
5
CodeRank
This code example shows how to use the following methods:or
  } 
 
  private static final CharMatcher BASH_SPECIAL_CHARS =
      CharMatcher
          .anyOf("<>|!?*[]$\\(){}\"'`&;=")
          .or(CharMatcher.WHITESPACE);
 
  /** 
   * Bash quoting {@link com.google.common.base.Function Function} which can be passed to 
   * {@link com.google.common.collect.Iterables#transform Iterables.transform()}. 
   */ 
  public static final Function<String, String> BASH_ESCAPER =
      escaper(Quoter.SINGLE, BASH_SPECIAL_CHARS);
 
  public static final Function<String, String> JAVA_ESCAPER =
      new Function<String, String>() { 
        @Override 
        public String apply(String input) { 
          return escapeAsJavaString(input); 
        } 
5
CodeRank
This code example shows how to use the following methods:matchesAllOf, negate
                .putArgument("actual", input.length())
                .putArgument("expected", length));
            return; 
        } 
 
        if (HEX_CHARS.matchesAllOf(input))
            return; 
 
        final int index = HEX_CHARS.negate().indexIn(input);
 
        report.error(newMsg(data, bundle, "err.format.hexString.illegalChar")
            .putArgument("character", Character.toString(input.charAt(index)))
            .putArgument("index", index));
    } 
} 
5
CodeRank
See Code Examples for Guava CharMatcher Methods: