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

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

Introduction

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

Prototype

@CheckReturnValue
public String trimFrom(CharSequence sequence) 

Source Link

Document

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

Usage

From source file:org.eclipse.mylyn.internal.wikitext.markdown.core.GfmIdGenerationStrategy.java

@Override
public String generateId(String headingText) {
    String id = headingText.toLowerCase(Locale.getDefault());
    id = id.replaceAll("[^a-z0-9_-]", "-"); //$NON-NLS-1$//$NON-NLS-2$
    CharMatcher hyphenMatcher = CharMatcher.is('-');
    id = hyphenMatcher.trimFrom(hyphenMatcher.collapseFrom(id, '-'));
    return id;/*from   ww w.jav  a2  s .c om*/
}

From source file:com.infinities.nova.views.AbstractViewBuilder.java

protected String osPathJoin(String... strings) {
    checkNotNull(strings);/* ww  w.  j  a  v a  2 s.c  o m*/
    checkArgument(strings.length > 0);
    final CharMatcher joinCharMatcher = CharMatcher.is('/');
    return Joiner.on('/').join(Iterables.transform(Arrays.asList(strings), new Function<String, String>() {

        @Override
        public String apply(final String input) {
            return joinCharMatcher.trimFrom(input);
        }
    }));
}

From source file:com.infinities.swift.versions.views.ViewBuilder.java

private String osPathJoin(String... strings) {
    checkNotNull(strings);/*from w  w  w . j a va2s  . c  om*/
    checkArgument(strings.length > 0);
    final CharMatcher joinCharMatcher = CharMatcher.is('/');
    return Joiner.on('/').join(Iterables.transform(Arrays.asList(strings), new Function<String, String>() {

        @Override
        public String apply(final String input) {
            return joinCharMatcher.trimFrom(input);
        }
    }));
}

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

/**
 * This is a both way strip.//  w  w w . j  a v  a 2 s  .c  om
 *
 * @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;
}