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

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

Introduction

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

Prototype

@CheckReturnValue
public String collapseFrom(CharSequence sequence, char replacement) 

Source Link

Document

Returns a string copy of the input character sequence, with each group of consecutive characters that match this matcher replaced by a single replacement character.

Usage

From source file:io.v.impl.google.naming.NamingUtil.java

/**
 * Reduces multiple adjacent slashes to a single slash and removes any trailing slash.
 *///w w w. j  a v  a 2s.  c  o  m
public static String clean(String name) {
    CharMatcher slashMatcher = CharMatcher.is('/');
    name = slashMatcher.collapseFrom(name, '/');
    if ("/".equals(name)) {
        return name;
    }
    return slashMatcher.trimTrailingFrom(name);
}

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 w  ww.  j a  va  2  s  .  c  o  m*/
}