Example usage for java.lang Character isLetter

List of usage examples for java.lang Character isLetter

Introduction

In this page you can find the example usage for java.lang Character isLetter.

Prototype

public static boolean isLetter(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a letter.

Usage

From source file:org.openlegacy.utils.StringUtil.java

public static String toDisplayName(String text) {
    if (StringUtils.isAllUpperCase(text)) {
        text = text.toLowerCase();/*from   w  ww. java  2  s .com*/
    }
    char[] chars = text.toCharArray();
    StringBuilder sb = new StringBuilder(text.length());
    for (int i = 0; i < chars.length; i++) {
        char c = chars[i];
        if (Character.isLetter(c) || Character.isDigit(c) || c == ' ' || c == '\\' || c == '/' || c == '.') {
            if (i == 0) {
                sb.append(Character.toUpperCase(c));
            } else {
                // add blank current char is upper case, previous char is blank and not upper case
                if (Character.isUpperCase(c) && chars[i - 1] != ' ' && Character.isLetter(chars[i - 1])
                        && !Character.isUpperCase(chars[i - 1])) {
                    sb.append(' ');
                }
                sb.append(c);
            }
        }

    }
    return StringUtils.strip(sb.toString(), " .");
}

From source file:au.org.ala.bhl.WordLists.java

private static HashSet<String> loadWordList(String resourcePath) {
    HashSet<String> set = new HashSet<String>();
    InputStream is = TaxonGrab.class.getResourceAsStream(resourcePath);
    try {/*from  w  w  w.  j  a va 2  s  .  c o m*/
        @SuppressWarnings("unchecked")
        List<String> lines = IOUtils.readLines(is);
        for (String line : lines) {
            StringBuilder word = new StringBuilder();
            StringBuilder wordAlt = new StringBuilder();

            for (int i = 0; i < line.length(); ++i) {
                char ch = line.charAt(i);
                char chAlt = substitute(ch);

                if (Character.isLetter(chAlt)) {
                    wordAlt.append(chAlt);
                    if (chAlt > 127) {
                        System.err.println(String.format("Non ascii letter: %s", ch));
                    }
                }

                if (Character.isLetter(ch)) {
                    word.append(ch);
                }
            }
            set.add(word.toString().toLowerCase());
            if (!wordAlt.toString().equals(word.toString())) {
                set.add(wordAlt.toString());
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return set;

}

From source file:importer.filters.Filter.java

/**
 * Get the first word of a line/*from w  w  w  . j av  a 2 s .c o  m*/
 * @param line the line in question
 * @return 
 */
protected String getFirstWord(String line) {
    int i;
    int len = line.length();
    for (i = 0; i < line.length(); i++) {
        if (!Character.isWhitespace(line.charAt(i)))
            break;
    }
    int j = i;
    for (; i < len; i++) {
        if (!Character.isLetter(line.charAt(i)) || line.charAt(i) == '-')
            break;
    }
    return line.substring(j, i);
}

From source file:org.opensextant.util.TextUtils.java

/**
 * Checks if non-ASCII and non-LATIN characters are present.
 * //  w w  w . java 2s. com
 * @param data
 *            any textual data
 * @return true if content is strictly ASCII or Latin1 extended.
 */
public final static boolean isLatin(String data) {
    char[] ch = data.toCharArray();
    boolean isLatin = true;
    for (char c : ch) {
        if (isASCII(c)) {
            continue;
        }
        if (!Character.isLetter(c)) {
            continue;
        }
        Character.UnicodeBlock blk = Character.UnicodeBlock.of(c);
        if (blk == Character.UnicodeBlock.LATIN_1_SUPPLEMENT || blk == Character.UnicodeBlock.LATIN_EXTENDED_A
                || blk == Character.UnicodeBlock.LATIN_EXTENDED_B
                || blk == Character.UnicodeBlock.LATIN_EXTENDED_C
                || blk == Character.UnicodeBlock.LATIN_EXTENDED_D
                || blk == Character.UnicodeBlock.LATIN_EXTENDED_ADDITIONAL) {
            continue;
        }

        isLatin = false;
        break;
    }

    //
    return isLatin;
}

From source file:org.energy_home.jemma.ah.internal.hac.lib.HacService.java

private static String replaceIvalidPidChars(String appliancePid) {
    char[] chars = appliancePid.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        if (!Character.isDigit(chars[i]) && !Character.isLetter(chars[i]))
            chars[i] = '-';
    }//from  w w w .ja va2s. c o m
    return new String(chars);
}

From source file:com.teambr.bookshelf.client.gui.component.control.GuiComponentSetNumber.java

/**
 * Used when a key is pressed// w w  w .j ava  2  s  .  co m
 * @param letter The letter
 * @param keyCode The code
 */
@Override
public void keyTyped(char letter, int keyCode) {
    if (Character.isLetter(letter) && (keyCode != 8 && keyCode != 109))
        return;
    if (textField.isFocused())
        textField.textboxKeyTyped(letter, keyCode);
    if (textField.getText() == null || (textField.getText() == "") || !isNumeric(textField.getText())) {
        textField.setTextColor(0xE62E00);
        return;
    }
    if (keyCode == 13)
        textField.setFocused(false);
    textField.setTextColor(0xFFFFFF);
    if (Integer.valueOf(textField.getText()) > ceiling)
        textField.setText(String.valueOf(ceiling));
    else if (Integer.valueOf(textField.getText()) < floor)
        textField.setText(String.valueOf(floor));
    value = Integer.valueOf(textField.getText());
    setValue(value);
}

From source file:xc.mst.services.marcaggregation.matcher.SystemControlNumberMatcher.java

protected String getPrefix(String s) {
    int start, end;
    if (s.contains("(")) {
        start = s.indexOf("(");
        if (s.contains(")")) {
            end = s.indexOf(")");
            LOG.debug(s);// w ww . j a va 2 s  . com
            final String prefix = (s.substring(start + 1, end)).toUpperCase(); // case-insensitive matching MST-538
            Character first = prefix.charAt(0);
            // probably really need to be a 3 alpha prefix but for now make sure it starts with alpha.
            if (prefix != null && prefix.length() > 0) {
                if (Character.isLetter(first)) {
                    LOG.debug("found a prefix of " + prefix);
                    // threads need to lock - critical section
                    synchronized (this) {
                        if (!prefix2id.containsKey(prefix)) {
                            int newId = prefix2id.size();
                            prefix2id.put(prefix, newId);
                            id2prefix.put(newId, prefix);
                            if (MarcAggregationService.hasIntermediatePersistence) {
                                id2prefix_unpersisted.put(newId, prefix);
                            }

                        }
                    }
                    return prefix;
                }
            }
        }
    }
    return "";
}

From source file:org.nuxeo.ecm.core.filesystem.FilesystemServiceImpl.java

protected static String getSuffix(String string) {
    if (string == null) {
        return "";
    }//from ww  w  .  j a  v  a 2  s  .c  o  m
    string = StringUtils.trim(string);
    int pos = string.lastIndexOf('.') + 1;
    int len = string.length() - pos;
    if (pos == 0 || len > SUFFIX_MAX_LEN || len < 1) {
        return "";
    }
    String suffix = string.substring(pos);
    // check only chars
    for (char c : suffix.toCharArray()) {
        if (!Character.isLetter(c) && !Character.isDigit(c)) {
            return "";
        }
    }
    return '.' + suffix;
}

From source file:org.springframework.boot.actuate.system.EmbeddedServerPortFileWriter.java

private boolean isUpperCase(String name) {
    for (int i = 0; i < name.length(); i++) {
        if (Character.isLetter(name.charAt(i)) && !Character.isUpperCase(name.charAt(i))) {
            return false;
        }/*from w  w w.j  a  v  a 2s  .  c om*/
    }
    return true;
}

From source file:org.apache.brooklyn.util.net.Urls.java

/** as {@link #isUrlWithProtocol(String)} but configurable to be strict (false, false) or allow newline chars (if e.g. in an unescaped argument) */
public static boolean isUrlWithProtocol(String x, boolean allowSpacesAfterCharAfterColon,
        boolean allowMultiline) {
    if (x == null)
        return false;
    for (int i = 0; i < x.length(); i++) {
        char c = x.charAt(i);
        if (c == ':') {
            if (i == 0 || i + 1 >= x.length())
                return false;
            char c2 = x.charAt(i + 1);
            // never allow a whitespace or quote mark right after the ':', that is too similar to json/yaml!
            if (Character.isWhitespace(c2) || c2 == '\'' || c2 == '\"')
                return false;
            if (!allowMultiline) {
                if (x.indexOf('\n') >= 0)
                    return false;
                if (x.indexOf('\r') >= 0)
                    return false;
            }/*from   ww w  . j a v  a2s  .c o m*/
            if (!allowSpacesAfterCharAfterColon) {
                if (x.indexOf(' ') >= 0)
                    return false;
                if (x.indexOf('\t') >= 0)
                    return false;
            }
            return true;
        }

        // protocol schema as per https://en.wikipedia.org/wiki/Uniform_Resource_Locator
        if (i == 0) {
            if (!Character.isLetter(c))
                return false;
        } else if (!Character.isAlphabetic(c) && !Character.isDigit(c) && c != '+' && c != '.' && c != '-') {
            return false;
        }
    }
    // no colon found
    return false;
}