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

static synchronized String toCamelCase(String str) {
    if (str == null)
        return null;
    int pos = 0;//  w w  w  .j  ava2  s . com
    boolean doCapitalize = true;
    for (int i = 0; i < str.length(); ++i) {
        char ch = str.charAt(i);
        if (Character.isLetterOrDigit(ch)) {
            if (doCapitalize && Character.isLetter(ch)) {
                ch = Character.toUpperCase(ch);
            }
            sCamelCase[pos] = ch;
            ++pos;
            doCapitalize = false;
        } else if (ch == '_') {
            doCapitalize = true;
        }
    }

    return new String(sCamelCase, 0, pos);
}

From source file:Main.java

/**
 * Starts reading the encoding from the first valid character until an
 * invalid encoding character occurs./*  w ww.jav a2 s. co m*/
 */
public static String encodingCleanup(String str) {
    StringBuilder sb = new StringBuilder();
    boolean startedWithCorrectString = false;
    for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        if (Character.isDigit(c) || Character.isLetter(c) || c == '-' || c == '_') {
            startedWithCorrectString = true;
            sb.append(c);
            continue;
        }

        if (startedWithCorrectString)
            break;
    }
    return sb.toString().trim();
}

From source file:Main.java

/**
 * Starts reading the encoding from the first valid character until an
 * invalid encoding character occurs.//www.j a  v a2s .com
 */
public static String encodingCleanup(String str) {
    StringBuilder sb = new StringBuilder(str.length());
    boolean startedWithCorrectString = false;
    for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        if (Character.isDigit(c) || Character.isLetter(c) || c == '-' || c == '_') {
            startedWithCorrectString = true;
            sb.append(c);
            continue;
        }

        if (startedWithCorrectString)
            break;
    }
    return sb.toString().trim();
}

From source file:Main.java

/**
 * Return true if an element/attribute name is a valid NCName (Non Colon Name).
 * /*from www.ja  va2s  .c o  m*/
 * @param name Non-qualified (no colon) name for an element/attribute.
 * @return True if an element/attribute name is a valid NCName.
 */
public static boolean isValidNCName(String name) {
    if (name == null || name.length() <= 0)
        return false;
    if (name.equalsIgnoreCase("XML"))
        return false;
    char c = name.charAt(0);
    if (!Character.isLetter(c) && c != '_')
        return false;
    for (int i = 1; i < name.length(); i++) {
        c = name.charAt(i);
        if (!Character.isLetter(c) && !Character.isDigit(c) && c != '_' && c != '.' && c != '-')
            return false;
    }
    return true;
}

From source file:Main.java

public static String createXmlName(String str) {
    StringBuffer result = new StringBuffer();
    boolean skipped = false;
    boolean numbersOnly = true;

    for (int c = 0; c < str.length(); c++) {
        char ch = str.charAt(c);

        if (Character.isLetter(ch) || ch == '_' || ch == '-' || ch == '.') {
            if (skipped)
                result.append(Character.toUpperCase(ch));
            else//  www  .  ja v  a  2s .co  m
                result.append(ch);
            numbersOnly = false;
            skipped = false;
        } else if (Character.isDigit(ch)) {
            result.append(ch);
            skipped = false;
        } else {
            skipped = true;
        }
    }

    str = result.toString();
    if (numbersOnly && str.length() > 0)
        str = "_" + str;

    return str;
}

From source file:Main.java

/**
 * Checks that the first letter in the string is a letter and not a digit.
 * If this is true is returns the untouched properyName
 * <p/>/*from   w  ww. j  a v a2  s  . c o  m*/
 * If it starts with something other then a letter then it prepends an 'n'
 * character to the front of the string.
 * 
 * @param propertyName
 * @return a property name that started with 'n' is it starts with something
 *         other then a letter.
 */

public static String getCleanPropertyName(String propertyName) {
    StringBuilder sb = new StringBuilder();
    if (propertyName != null && propertyName.length() > 0) {
        char firstValue = propertyName.charAt(0);
        if (Character.isDigit(firstValue) || !Character.isLetter(firstValue)) {
            // propertyName = "n" + propertyName;
            sb.append('n');
        }
        for (int i = 0; i < propertyName.length(); i++) {
            char iChar = propertyName.charAt(i);
            if (Character.isLetterOrDigit(iChar) || iChar == '.' || iChar == '-' || iChar == '_'
                    || iChar == ':') {
                sb.append(iChar);
            }
        }
    }

    return sb.toString();

}

From source file:Main.java

/**
 *
 * @param data A binary array of bytes./*from  ww w .  java  2s.  c o  m*/
 * @return A hex-encoded string with double length.
 */
public static String hexEncode(byte[] data) {
    if (data == null)
        return null;

    StringBuilder sb = new StringBuilder();
    for (byte b : data) {
        // hex encoding same way as java.net.URLEncoder.
        char ch = Character.forDigit((b >> 4) & 0xF, 16);
        // to uppercase
        if (Character.isLetter(ch)) {
            ch -= caseDiff;
        }
        sb.append(ch);
        ch = Character.forDigit(b & 0xF, 16);
        if (Character.isLetter(ch)) {
            ch -= caseDiff;
        }
        sb.append(ch);
    }
    return sb.toString();
}

From source file:Main.java

/**
 * Escapes the contents a string to be used as a safe scheme name in the URI according to
 * http://tools.ietf.org/html/rfc3986#section-3.1
 *
 * This does not ensure that the first character is a letter (which is required by the RFC).
 *///w  w  w  .j  a  v a  2s.  c  om
@VisibleForTesting
public static String escapeForSchemeName(String s) {
    // According to the RFC, scheme names are case-insensitive.
    s = s.toLowerCase();

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (Character.isLetter(c) || Character.isDigit(c) || ('-' == c) || ('.' == c)) {
            // Safe - use as is.
            sb.append(c);
        } else if ('+' == c) {
            // + is used as our escape character, so double it up.
            sb.append("++");
        } else {
            // Unsafe - escape.
            sb.append('+').append((int) c);
        }
    }
    return sb.toString();
}

From source file:Main.java

protected static boolean checkNameStartChar(char ch) {
    if (Character.isLetter(ch))
        return true;
    if (ch == '_')
        return true;
    return false;
}

From source file:org.talend.dataquality.semantic.model.MainCategory.java

public static MainCategory getMainCategory(String str) {
    if (str == null) {
        return MainCategory.NULL;
    } // else//from  w ww  . j a  va 2 s  .c o  m
    if (StringUtils.trim(str).equals(StringUtils.EMPTY)) {
        return MainCategory.BLANK;
    } // else

    boolean notAlpha = false;
    boolean notNumeric = false;

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

        if (Character.isDigit(ch)) {
            notAlpha = true;
        } else if (Character.isLetter(ch)) {
            notNumeric = true;
        }
        if (notAlpha && notNumeric) {
            return MainCategory.AlphaNumeric;
        }
    }

    if (notAlpha) {
        return MainCategory.Numeric;
    } // else
    if (notNumeric) {
        return MainCategory.Alpha;
    }

    return MainCategory.UNKNOWN;
}