Example usage for com.google.common.base CharMatcher trimLeadingFrom

List of usage examples for com.google.common.base CharMatcher trimLeadingFrom

Introduction

In this page you can find the example usage for com.google.common.base CharMatcher trimLeadingFrom.

Prototype

@CheckReturnValue
public String trimLeadingFrom(CharSequence sequence) 

Source Link

Document

Returns a substring of the input character sequence that omits all characters this matcher matches from the beginning of the string.

Usage

From source file:com.android.mail.lib.base.StringUtil.java

/**
 * This is a both way strip./*from  w  w w . j  av a2 s. co  m*/
 *
 * @param str the string to strip
 * @param left strip from left
 * @param right strip from right
 * @param what character(s) to strip
 * @return the stripped string
 * @deprecated ensure the string is not null and use
 *  <ul>
 *    <li> {@code CharMatcher.anyOf(what).trimFrom(str)}
 *        if {@code left == true} and {@code right == true}
 *    <li> {@code CharMatcher.anyOf(what).trimLeadingFrom(str)}
 *        if {@code left == true} and {@code right == false}
 *    <li> {@code CharMatcher.anyOf(what).trimTrailingFrom(str)}
 *        if {@code left == false} and {@code right == true}
 *  </ul>
 */
@Deprecated
public static String megastrip(String str, boolean left, boolean right, String what) {
    if (str == null) {
        return null;
    }

    CharMatcher matcher = CharMatcher.anyOf(what);
    if (left) {
        if (right) {
            return matcher.trimFrom(str);
        }
        return matcher.trimLeadingFrom(str);
    }
    if (right) {
        return matcher.trimTrailingFrom(str);
    }
    return str;
}