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:Utils.java

/**
 * Capitlize each word in a string (journal titles, etc)
 * //w  w w  . j  a  v  a2s.c o  m
 * @param text
 *          Text to inspect
 * @return Capitalized text
 */
public static String capitalize(String text) {
    StringBuilder resultText;
    char previousC;

    resultText = new StringBuilder();
    previousC = '.';

    for (int i = 0; i < text.length(); i++) {
        char c = text.charAt(i);

        if (Character.isLetter(c) && !Character.isLetter(previousC)) {
            resultText.append(Character.toUpperCase(c));
        } else {
            resultText.append(c);
        }
        previousC = c;
    }
    return resultText.toString();
}

From source file:org.jboss.dashboard.commons.text.JavaNamesFormatter.java

/**
 * Description of the Method//from w w  w.j a  v a  2s .c  o m
 *
 * @param name                   Description of the Parameter
 * @param firstLetterIsUpperCase Description of the Parameter
 * @return Description of the Return Value
 */
public static String toJavaName(String name, boolean firstLetterIsUpperCase) {

    StringBuffer res = new StringBuffer();

    boolean nextIsUpperCase = firstLetterIsUpperCase;

    for (int i = 0; i < name.length(); i++) {
        char c = name.charAt(i);

        if (nextIsUpperCase) {
            c = Character.toUpperCase(c);
        }

        if (Character.isLetter(c)) {
            res.append(c);
            nextIsUpperCase = false;
        } else {
            nextIsUpperCase = true;
        }
    }

    return res.toString();
}

From source file:Main.java

/**
 * <p>Checks if the String contains only unicode letters.</p>
 *
 * <p><code>null</code> will return <code>false</code>.
 * An empty String ("") will return <code>true</code>.</p>
 *
 * <pre>/*from w ww.  j a v a2s .  com*/
 * StringUtils.isAlpha(null)   = false
 * StringUtils.isAlpha("")     = true
 * StringUtils.isAlpha("  ")   = false
 * StringUtils.isAlpha("abc")  = true
 * StringUtils.isAlpha("ab2c") = false
 * StringUtils.isAlpha("ab-c") = false
 * </pre>
 *
 * @param str  the String to check, may be null
 * @return <code>true</code> if only contains letters, and is non-null
 */
public static boolean isAlpha(String str) {
    if (str == null) {
        return false;
    }
    int sz = str.length();
    for (int i = 0; i < sz; i++) {
        if (Character.isLetter(str.charAt(i)) == false) {
            return false;
        }
    }
    return true;
}

From source file:org.zeroturnaround.isjrebel.IsJRebel.java

private static String dropPunctuation(String input) {
    return input.codePoints()
            .filter(c -> Character.isLetter(c) || Character.isDigit(c) || Character.isWhitespace(c))
            .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append).toString();
}

From source file:Main.java

/**
 * Return the original object if no cleanup is done, or for example "" if there are zero characters worth
 * keeping after cleanup//from   www. j a  v a 2s. co m
 * <p>
 * Cleanup means conformance to "#tagnumberlowercasedigitsnotinfirstposition"
 *
 * @param value
 * @return
 */
@NonNull
public static String cleanupTag(@NonNull final Object value, final char firstCharacter) {
    final String tag = ((String) value);
    String cleanedTag = tag.trim().toLowerCase();

    while (cleanedTag.startsWith("##") || cleanedTag.startsWith("@@")) {
        cleanedTag = cleanedTag.substring(1);
    }
    final StringBuffer sb = new StringBuffer(cleanedTag.length());
    boolean first = true;
    for (char c : cleanedTag.toCharArray()) {
        if (!Character.isLetter(c)) {
            // Is not a letter
            if (!first && Character.isDigit(c)) {
                sb.append(c);
            }
            continue;
        }
        sb.append(c);
        first = false;
    }
    String s = sb.toString();
    if (!s.startsWith("" + firstCharacter)) {
        s = firstCharacter + s;
    }
    if (!s.equals(tag)) {
        return s;
    }

    return tag;
}

From source file:hr.fer.spocc.export.DotExporter.java

public static String toDotString(ParseTree parseTree, String graphName) {
    Validate.isTrue(!graphName.isEmpty() && StringUtils.isAlphanumeric(graphName)
            && Character.isLetter(graphName.charAt(0)));
    StringBuilder dotString = new StringBuilder();
    dotString.append("digraph ").append(graphName).append(" {\n");
    Map<ParseTreeNode, String> nodePrefixMap = new LinkedHashMap<ParseTreeNode, String>();
    toDotNodes(parseTree.getRoot(), new StringBuilder(), nodePrefixMap, dotString);
    toDotEdges(parseTree.getRoot(), nodePrefixMap, dotString);
    dotString.append("}\n");
    return dotString.toString();
}

From source file:org.sonar.css.checks.CommentContainsPatternChecker.java

private static boolean isLetterAround(String line, String pattern) {
    int start = StringUtils.indexOfIgnoreCase(line, pattern);
    int end = start + pattern.length();

    boolean pre = start > 0 && Character.isLetter(line.charAt(start - 1));
    boolean post = end < line.length() - 1 && Character.isLetter(line.charAt(end));

    return pre || post;
}

From source file:org.sonar.updatecenter.common.PluginKeyUtils.java

private static String keepLettersAndDigits(String key) {
    StringBuilder sb = new StringBuilder();
    for (int index = 0; index < key.length(); index++) {
        char character = key.charAt(index);
        if (Character.isLetter(character) || Character.isDigit(character)) {
            sb.append(character);//from   ww  w.jav  a  2  s  .  com
        }
    }
    return sb.toString();
}

From source file:org.apache.archiva.web.startup.Banner.java

public static String encode(String raw) {
    // Canonicalize line ends to make them easier to process
    raw = raw.replace("\r\n", "\n").replace("\r", "\n");

    StringBuilder encoded = new StringBuilder();
    int rawlen = raw.length();

    for (int i = 0; i < rawlen; i++) {
        char c = raw.charAt(i);
        if (c == '\\') {
            encoded.append("$.");
        } else if (c == '$') {
            encoded.append("$$");
        } else if (c == '\n') {
            encoded.append("$n");
        } else if (Character.isDigit(c)) {
            encoded.append(c);//from  www  . j a  va 2s . c  o  m
        } else if (Character.isLetter(c)) {
            encoded.append(rot13(c));
        } else if (i < raw.length() - 1) {
            char nc;
            boolean done = false;
            int count = 0;
            for (int n = i; !done; n++) {
                if (n >= rawlen) {
                    break;
                }

                nc = raw.charAt(n);

                if (nc != c) {
                    done = true;
                } else {
                    count++;
                }
            }
            if (count < 3) {
                encoded.append(c);
            } else {
                encoded.append("$").append(String.valueOf(count)).append(c);
                i += count - 1;
            }
        } else {
            encoded.append(c);
        }
    }

    return encoded.toString();
}

From source file:exm.stc.tclbackend.tree.Proc.java

/**
 * Check that there are no invalid characters
 *//*from  w w w  .j  av a 2 s.  c om*/
private static void checkTclFunctionName(String name) {
    for (int i = 0; i < name.length(); i++) {
        char c = name.charAt(i);
        if (Character.isLetter(c) || Character.isDigit(c) || c == ':' || c == '_' || c == '=' || c == '-'
                || c == '<' || c == '>') {
            // Whitelist of characters
        } else {
            throw new STCRuntimeError("Bad character '" + c + "' in tcl function name " + name);
        }
    }
}