Example usage for java.lang Character isJavaIdentifierPart

List of usage examples for java.lang Character isJavaIdentifierPart

Introduction

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

Prototype

public static boolean isJavaIdentifierPart(int codePoint) 

Source Link

Document

Determines if the character (Unicode code point) may be part of a Java identifier as other than the first character.

Usage

From source file:Main.java

public static void main(String[] args) {
    char ch1 = '3', ch2 = '_';

    boolean b1 = Character.isJavaIdentifierPart(ch1);
    boolean b2 = Character.isJavaIdentifierPart(ch2);

    System.out.println(b1);/*  ww w .j  av  a  2  s .  c  om*/
    System.out.println(b2);
}

From source file:Main.java

public static void main(String[] args) throws java.io.IOException {
    char c = 'a';

    System.out.println("Character = " + (int) c);
    System.out.println("Defined = " + Character.isDefined(c));
    System.out.println("Digit = " + Character.isDigit(c));
    System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
    System.out.println("ISO control = " + Character.isISOControl(c));
    System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
    System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
    System.out.println("Letter = " + Character.isLetter(c));
    System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
    System.out.println("Lowercase = " + Character.isLowerCase(c));
    System.out.println("Space = " + Character.isSpaceChar(c));
    System.out.println("Titlecase = " + Character.isTitleCase(c));
    System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
    System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
    System.out.println("Uppercase = " + Character.isUpperCase(c));
    System.out.println("White space = " + Character.isWhitespace(c));

    byte[] types = { Character.COMBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION, Character.CONTROL,
            Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION, Character.DECIMAL_DIGIT_NUMBER,
            Character.ENCLOSING_MARK, Character.END_PUNCTUATION, Character.FORMAT, Character.LETTER_NUMBER,
            Character.LINE_SEPARATOR, Character.LOWERCASE_LETTER, Character.MATH_SYMBOL,
            Character.MODIFIER_SYMBOL, Character.NON_SPACING_MARK, Character.OTHER_LETTER,
            Character.OTHER_NUMBER, Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL,
            Character.PARAGRAPH_SEPARATOR, Character.PRIVATE_USE, Character.SPACE_SEPARATOR,
            Character.START_PUNCTUATION, Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
            Character.UPPERCASE_LETTER };

    String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control", "Currency symbol",
            "Dash punctuation", "Decimal digit number", "Enclosing mark", "End punctuation", "Format",
            "Letter number", "Line separator", "Lowercase letter", "Math symbol", "Modifier symbol",
            "Non spacing mark", "Other letter", "Other number", "Other punctuation", "Other symbol",
            "Paragraph separator", "Private use", "Space separator", "Start punctuation", "Surrogate",
            "Titlecase letter", "Unassigned", "Uppercase letter" };

    int type = Character.getType(c);

    for (int i = 0; i < types.length; i++)
        if (type == types[i]) {
            System.out.println("Type name = " + typeNames[i]);
            break;
        }/* w  w w . j  a v  a  2 s  . com*/

    System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}

From source file:Classify.java

public static void main(String[] args) throws java.io.IOException {
    char c = '\u0beb'; // Tamil digit.

    System.out.println("Character = " + (int) c);
    System.out.println("Defined = " + Character.isDefined(c));
    System.out.println("Digit = " + Character.isDigit(c));
    System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
    System.out.println("ISO control = " + Character.isISOControl(c));
    System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
    System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
    System.out.println("Letter = " + Character.isLetter(c));
    System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
    System.out.println("Lowercase = " + Character.isLowerCase(c));
    System.out.println("Space = " + Character.isSpaceChar(c));
    System.out.println("Titlecase = " + Character.isTitleCase(c));
    System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
    System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
    System.out.println("Uppercase = " + Character.isUpperCase(c));
    System.out.println("White space = " + Character.isWhitespace(c));

    byte[] types = { Character.COMBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION, Character.CONTROL,
            Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION, Character.DECIMAL_DIGIT_NUMBER,
            Character.ENCLOSING_MARK, Character.END_PUNCTUATION, Character.FORMAT, Character.LETTER_NUMBER,
            Character.LINE_SEPARATOR, Character.LOWERCASE_LETTER, Character.MATH_SYMBOL,
            Character.MODIFIER_SYMBOL, Character.NON_SPACING_MARK, Character.OTHER_LETTER,
            Character.OTHER_NUMBER, Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL,
            Character.PARAGRAPH_SEPARATOR, Character.PRIVATE_USE, Character.SPACE_SEPARATOR,
            Character.START_PUNCTUATION, Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
            Character.UPPERCASE_LETTER };

    String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control", "Currency symbol",
            "Dash punctuation", "Decimal digit number", "Enclosing mark", "End punctuation", "Format",
            "Letter number", "Line separator", "Lowercase letter", "Math symbol", "Modifier symbol",
            "Non spacing mark", "Other letter", "Other number", "Other punctuation", "Other symbol",
            "Paragraph separator", "Private use", "Space separator", "Start punctuation", "Surrogate",
            "Titlecase letter", "Unassigned", "Uppercase letter" };

    int type = Character.getType(c);

    for (int i = 0; i < types.length; i++)
        if (type == types[i]) {
            System.out.println("Type name = " + typeNames[i]);
            break;
        }//from   ww  w.  j  av a 2  s  .  com

    System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}

From source file:Main.java

public static boolean isJavaIdentifier(String s) {
    if (s.length() == 0 || !Character.isJavaIdentifierStart(s.charAt(0))) {
        return false;
    }/*from  w ww.j a v  a2  s . co  m*/
    for (int i = 1; i < s.length(); i++) {
        if (!Character.isJavaIdentifierPart(s.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

/**
 * @param source//from w  w w . j  av  a 2s .  c  o  m
 * @return Identifier that stands for tag name or tag attribute at the start
 *         of specified string.
 */
public static String getIdentifier(String source) {
    if (source.length() == 0) {
        return null;
    }

    StringBuilder buffer = new StringBuilder();
    int index = 0;
    int len = source.length();
    boolean charOk;
    do {
        char ch = source.charAt(index);
        charOk = (index == 0 && Character.isJavaIdentifierStart(ch))
                || (Character.isJavaIdentifierPart(ch) || ch == '-' || ch == ':' || ch == '.');
        if (charOk) {
            buffer.append(ch);
        }
        index++;
    } while (charOk && index < len);

    String identifier = buffer.toString();
    return identifier.length() > 0 ? identifier : null;
}

From source file:Main.java

/**
 * Returns normalized name from display name.
 * The normalized name should be used in the Ant properties and external files.
 * @param displayName/*  ww  w.j  a v  a 2 s .  c o  m*/
 * @return String
 */
public static String normalizeName(String displayName) {
    StringBuilder normalizedName = new StringBuilder();
    for (int i = 0; i < displayName.length(); i++) {
        char c = displayName.charAt(i);
        if (Character.isJavaIdentifierPart(c) || c == '-' || c == '.') {
            normalizedName.append(c);
        } else {
            normalizedName.append('_');
        }
    }
    return normalizedName.toString();
}

From source file:Main.java

/**
 * Parse the given name./*from ww  w .  j ava  2 s  . c o  m*/
 *
 * @param sourceName
 * @param separator
 * @return some stuff parsed from the name
 */
private static List<String> parseName(String sourceName, char separator) {
    List<String> result = new ArrayList<String>();
    if (sourceName != null) {
        StringBuilder currentWord = new StringBuilder(64);
        boolean lastIsLower = false;
        int index;
        int length;
        for (index = 0, length = sourceName.length(); index < length; ++index) {
            char curChar = sourceName.charAt(index);
            if (!Character.isJavaIdentifierPart(curChar)) {
                curChar = separator;
            }
            if (Character.isUpperCase(curChar) || (!lastIsLower && Character.isDigit(curChar))
                    || curChar == separator) {

                if (lastIsLower && currentWord.length() > 1
                        || curChar == separator && currentWord.length() > 0) {
                    result.add(currentWord.toString());
                    currentWord = new StringBuilder(64);
                }
                lastIsLower = false;
            } else {
                if (!lastIsLower) {
                    int currentWordLength = currentWord.length();
                    if (currentWordLength > 1) {
                        char lastChar = currentWord.charAt(--currentWordLength);
                        currentWord.setLength(currentWordLength);
                        result.add(currentWord.toString());
                        currentWord = new StringBuilder(64);
                        currentWord.append(lastChar);
                    }
                }
                lastIsLower = true;
            }

            if (curChar != separator) {
                currentWord.append(curChar);
            }
        }

        result.add(currentWord.toString());
    }
    return result;
}

From source file:Main.java

/**
 * Determines if the specified string is permissible as a Java identifier.
 * Returns true if the string is non-null, non-zero length with a Java
 * identifier start as the first character and Java identifier parts in all
 * remaining characters.//from w  w w .  j a  v a  2 s.  com
 * @param test the string to be tested.
 * @return true if the string is a Java identifier, false otherwise.
 * @see java.lang.Character#isJavaIdentifierPart(char)
 * @see java.lang.Character#isJavaIdentifierStart(char)
 */
public static boolean isJavaIdentifier(String test) {
    if (test == null || test.length() == 0) {
        return false;
    }

    if (!Character.isJavaIdentifierStart(test.charAt(0)) && test.charAt(0) != '_') {
        return false;
    }

    for (int i = 1; i < test.length(); i++) {
        if (!Character.isJavaIdentifierPart(test.charAt(i)) && test.charAt(i) != '_') {
            return false;
        }
    }

    return true;
}

From source file:com.moz.fiji.schema.util.JavaIdentifiers.java

/**
 * Determines whether a string is a valid Java identifier.
 *
 * <p>A valid Java identifier may not start with a number, but may contain any
 * combination of letters, digits, underscores, or dollar signs.</p>
 *
 * <p>See the <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.8">
 * Java Language Specification</a></p>
 *
 * @param identifier The identifier to test for validity.
 * @return Whether the identifier was valid.
 *//*from w w  w .  j a  va  2s  . c  o  m*/
public static boolean isValidIdentifier(String identifier) {
    if (identifier.isEmpty() || !Character.isJavaIdentifierStart(identifier.charAt(0))) {
        return false;
    }
    for (int i = 1; i < identifier.length(); i++) {
        if (!Character.isJavaIdentifierPart(identifier.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

public static boolean isValidScriptName(String s) {
    // an empty or null string cannot be a valid identifier
    if (s == null || s.length() == 0) {
        return false;
    }/*from   ww  w  . ja  v  a2s  .  c o m*/

    char[] c = s.toCharArray();
    if (!Character.isJavaIdentifierStart(c[0])) {
        return false;
    }

    for (int i = 1; i < c.length; i++) {
        if (!Character.isJavaIdentifierPart(c[i])) {
            return false;
        }
    }

    return true;
}