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

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

Introduction

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

Prototype

CharMatcher JAVA_LETTER

To view the source code for com.google.common.base CharMatcher JAVA_LETTER.

Click Source Link

Document

Determines whether a character is a letter according to Character#isLetter(char) Java's definition .

Usage

From source file:org.apromore.util.VersionUtil.java

/**
 * Extract the version number from a string.
 * @param versionNumber the version number (eg. 1.2, 1.3-beta)
 * @return an Array of strings that contain the version.
 *//*  www. j ava 2 s.c o m*/
public static String[] extractVersionNumber(final String versionNumber) {
    List<String> version = new ArrayList<>();
    char previousChar = '\0';

    for (char c : versionNumber.toCharArray()) {
        if (CharMatcher.JAVA_DIGIT.matches(c)) {
            if (CharMatcher.JAVA_DIGIT.matches(previousChar)) {
                // We have a number greater than 9.
                String tmp = (version.get(version.size() - 1)) + c;
                version.remove(version.size() - 1);
                version.add(tmp);
            } else if (CharMatcher.JAVA_LETTER.matches(previousChar)) {
                // We have a number besides a letter? what to do here.
                version.add(String.valueOf(c));
            } else {
                version.add(String.valueOf(c));
            }
        }
        previousChar = c;
    }

    return version.toArray(new String[version.size()]);
}

From source file:fr.putnami.pwt.plugin.code.client.token.evaluator.DefaultWordDetector.java

@Override
public boolean isWordStart(char c) {
    return CharMatcher.JAVA_LETTER.matches(c);
}

From source file:fr.putnami.pwt.plugin.code.client.token.evaluator.DefaultWordDetector.java

@Override
public boolean isWordPart(char c) {
    return CharMatcher.JAVA_LETTER.matches(c);
}

From source file:cake.bootstrap.util.ParameterNames.java

static String stripGenerics(String str) {
    // fix for K, V, V[]
    if (CharMatcher.JAVA_LETTER.negate().trimFrom(str).length() == 1) {
        return "Object" + str.substring(1);
    }//from   w  w w.j a  va  2  s. co  m
    int i = str.indexOf('<');
    return i >= 0 ? str.substring(0, i) : str;
}

From source file:org.aliuge.crawler.extractor.selector.action.string.StringFilterAction.java

/**
 * //from  w  w  w. j  a  va2 s  .  c o  m
 */
@Override
public String doAction(String content) {
    for (CharType ct : set) {
        switch (ct) {
        case INVISIBLE:
            content = CharMatcher.INVISIBLE.removeFrom(content);

        case BREAKING_WHITESPACE:
            content = CharMatcher.BREAKING_WHITESPACE.removeFrom(content);
        case DIGIT:
            content = CharMatcher.DIGIT.removeFrom(content);
        case LETTER:
            content = CharMatcher.JAVA_LETTER.removeFrom(content);
        default:
            break;
        }
    }
    if (StringUtils.isNotBlank(filterString)) {
        content = CharMatcher.anyOf(filterString).removeFrom(content);
    }
    return content;
}

From source file:lu.list.itis.dkd.aig.util.Soundex.java

/**
 * Method used to remove accents and code points from a text.
 *
 * @param text/*  www .  j av a2  s .  co  m*/
 *        The text to clean.
 * @return The cleaned text.
 */
private synchronized static @Nullable String cleanText(final String text) {
    return CharMatcher.JAVA_LETTER.retainFrom(Normalizer.normalize(text, Normalizer.Form.NFD));
}

From source file:com.google.appinventor.common.utils.StringUtils.java

/**
 * Create a name safe for use in file paths from the provided String {@code
 * str}. It is fairly conservative to attempt, not guarantee, maximum
 * compatability for most operating systems.
 *//*ww w  .j av a2s  .c o  m*/
public static String normalizeForFilename(String str) {
    String normalized = VALID_FILENAME_CHARS.retainFrom(str);
    if (!normalized.isEmpty()) {
        while (normalized.length() > 2 && !CharMatcher.JAVA_LETTER.matches(normalized.charAt(0))) {
            normalized = normalized.substring(1);
        }
        if (CharMatcher.JAVA_LETTER.matches(normalized.charAt(0))) {
            return normalized;
        }
    }
    return null;
}

From source file:edu.cmu.lti.oaqa.knn4qa.annotators.GoodTokens.java

/**
 * //from   www . j ava2s .co m
 * A good word should start from the letter: it may contain a letter,
 * a dash, or an apostrophe. 
 * 
 * @param text        input
 * @param isStrict    if true, use a stricter definition of a good term.    
 * @return true if a good word.
 */
private boolean isGoodWord(String text, boolean isStrict) {
    if (text.isEmpty())
        return false;
    CharMatcher m = isStrict ? CharMatcher.JAVA_LETTER : CharMatcher.JAVA_LETTER_OR_DIGIT;
    if (!m.matches(text.charAt(0)))
        return false;
    for (int i = 0; i < text.length(); ++i) {
        char c = text.charAt(i);
        if (c != '-' && c != '\'' && !m.matches(c)) {
            return false;
        }
    }

    return true;
}

From source file:pt.ist.fenixedu.integration.task.exportData.santanderCardGeneration.SantanderBatchFillerWorker.java

private String purgeString(final String name) {
    if (!CharMatcher.JAVA_LETTER.or(CharMatcher.WHITESPACE).matchesAllOf(name)) {
        final char[] ca = new char[name.length()];
        int j = 0;
        for (int i = 0; i < name.length(); i++) {
            final char c = name.charAt(i);
            if (Character.isLetter(c) || c == ' ') {
                ca[j++] = c;/*  w  w w  .ja v a2 s.  c om*/
            }
        }
        return new String(ca);
    }
    return name;
}

From source file:org.openhealthtools.mdht.mdmi.util.DateUtil.java

/**
 * For outputting dates, tries to match the output precision with the input precision.
 * This has been tested with quoted and unquoted literals and supports varying expressions
 * of the same precision.// w ww.j  a  v a  2  s . c o m
 * TODO: Differing expressions of precision (e.g., from day as digit to day as name)
 *  has not been tested because the engine has a bug in which it always passes the destination
 *  format string, not the source.
 *
 * @param outFormat The maximal precision output format.
 * @param originalFormat The orginalFormat of the date, from the date wrapper.
 * @return A truncation of outFormat to match the precision of the originalFormat
 */
public static String matchPrecision(String outFormat, String originalFormat) {
    // Check for nulls
    if (originalFormat == null || originalFormat.equals("") || originalFormat.equals("DATE"))
        return outFormat;

    // Use our static data and a string matcher to add all the weird precision overlaps
    originalFormat = originalFormat.replaceAll("'.*'", ""); // Remove quoted literals
    String newOF_src = outFormat.replaceAll("'.*'", "");
    StringBuilder newOF_trg = new StringBuilder();
    for (int i = 0; i < dateParts.length; i++) {
        if (dateParts[i].matchesAnyOf(originalFormat))
            newOF_trg.append(dateParts[i].retainFrom(newOF_src));
    }

    // Use Guava's charmatcher to deal with everything but single-quoted literals
    CharMatcher matcher = CharMatcher.anyOf(newOF_trg).or(CharMatcher.JAVA_LETTER.negate());
    // bugfix 2/9/15 - remove trailing non-format chars (e.g. :)
    if (!outFormat.contains("'"))
        return CharMatcher.JAVA_LETTER.negate().trimTrailingFrom(matcher.retainFrom(outFormat));
    else {
        // There are single-quoted literals. Yuck.
        StringBuilder newOut = new StringBuilder();
        boolean instring = false;
        for (int i = 0; i < outFormat.length(); i++) {
            char current = outFormat.charAt(i);
            if (current == '\'') {
                if (instring == false)
                    instring = true;
                else
                    instring = false;
            }
            if (instring || matcher.matches(current))
                newOut.append(current);
        }
        return newOut.toString();
    }
}