Example usage for java.lang Character isJavaIdentifierStart

List of usage examples for java.lang Character isJavaIdentifierStart

Introduction

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

Prototype

public static boolean isJavaIdentifierStart(int codePoint) 

Source Link

Document

Determines if the character (Unicode code point) is permissible as the first character in a Java identifier.

Usage

From source file:Main.java

public static void main(String[] argv) {
    System.out.println("is Java identifier start:" + Character.isJavaIdentifierStart('a'));

}

From source file:Main.java

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

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

    System.out.println(b1);//from   w  w  w.  j a  va  2 s  . c o  m
    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;
        }//from  www  .j  a  v a 2 s. c  o m

    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   w ww.jav a  2 s  .  co  m*/

    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;
    }/*ww  w. j  a  va2  s  . c o m*/
    for (int i = 1; i < s.length(); i++) {
        if (!Character.isJavaIdentifierPart(s.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

public static boolean isPrintable(char c) {
    if (Character.isJavaIdentifierStart(c)) {
        // Letters and $ _
        return true;
    }/*from w  w w . ja v  a2 s .co m*/
    if (Character.isDigit(c)) {
        return true;
    }
    switch (Character.getType(c)) {
    case Character.MODIFIER_SYMBOL:
        return true; // ` ^
    case Character.DASH_PUNCTUATION:
        return true; // -
    case Character.MATH_SYMBOL:
        return true; // = ~ + | < >
    case Character.OTHER_PUNCTUATION:
        return true; // !@#%&*;':",./?
    case Character.START_PUNCTUATION:
        return true; // ( [ {
    case Character.END_PUNCTUATION:
        return true; // ) ] }
    }
    return false;
}

From source file:Main.java

/**
 * @param source//from   www.j ava2  s .  com
 * @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

/**
 * 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 ww w  .  j av a  2s.  co  m*/
 * @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 v a 2s.com*/
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;
    }//www .  j  av a 2  s .  com

    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;
}