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:org.jboss.dashboard.commons.text.StringUtil.java

/**
 * Checks if the specified string is a valid java identifier.
 *
 * @param str <i>(required)</i>.
 * @return Returns <code>true</code> iff the specified string is a valid java
 *         identifier./*from  w  w  w.  j  a v  a 2  s .  co m*/
 */
public static boolean isJavaIdentifier(String str) {
    boolean valid = (str != null) && (str.length() > 0);
    if (valid) {
        char c = str.charAt(0);
        valid = Character.isJavaIdentifierStart(c);
        for (int i = str.length(); valid && (--i >= 1);) {
            valid = Character.isJavaIdentifierPart(c);
        }
    }
    return valid && !isJavaKeyword(str);
}

From source file:jp.co.acroquest.jsonic.JSON.java

private Object parseLiteral(Context context, InputSource s, int level, boolean any)
        throws IOException, JSONException {
    int point = 0; // 0 'IdStart' 1 'IdPart' ... !'IdPart' E
    StringBuilder sb = context.getCachedBuffer();

    int n = -1;//from ww  w . j  a  v  a 2 s  . co m
    loop: while ((n = s.next()) != -1) {
        char c = (char) n;
        if (c == 0xFEFF)
            continue;

        if (c == '\\') {
            s.back();
            c = parseEscape(s);
        }

        if (point == 0 && Character.isJavaIdentifierStart(c)) {
            sb.append(c);
            point = 1;
        } else if (point == 1 && (Character.isJavaIdentifierPart(c) || c == '.')) {
            sb.append(c);
        } else {
            s.back();
            break loop;
        }
    }

    String str = sb.toString();

    if ("null".equals(str))
        return null;
    if ("true".equals(str))
        return true;
    if ("false".equals(str))
        return false;

    if (!any) {
        throw createParseException(getMessage("json.parse.UnrecognizedLiteral", str), s);
    }

    return str;
}

From source file:org.apache.maven.plugin.javadoc.JavadocUtil.java

private static boolean isValidClassName(String str) {
    if (StringUtils.isEmpty(str) || !Character.isJavaIdentifierStart(str.charAt(0))) {
        return false;
    }/*from   ww w  .jav a2s . c  om*/

    for (int i = str.length() - 1; i > 0; i--) {
        if (!Character.isJavaIdentifierPart(str.charAt(i))) {
            return false;
        }
    }

    return true;
}

From source file:org.apache.manifoldcf.agents.output.solr.HttpPoster.java

/** See CONNECTORS-956.  Make a safe lucene field name from a possibly
* unsafe input field name from a repository connector.
*/// w  ww  .j  a v a 2s  .  c om
protected static String makeSafeLuceneField(String inputField) {
    StringBuilder sb = new StringBuilder();
    boolean isFirst = true;
    for (int i = 0; i < inputField.length(); i++) {
        char x = inputField.charAt(i);
        if (isFirst && !Character.isJavaIdentifierStart(x) || !isFirst && !Character.isJavaIdentifierPart(x)) {
            // Check for exceptions for Lucene
            if (!isFirst && (x == '.' || x == '-'))
                sb.append(x);
            else
                sb.append('_');
        } else {
            // Check for exceptions for Lucene
            if (isFirst && x == '$')
                sb.append('_');
            else
                sb.append(x);
        }
        isFirst = false;
    }
    return sb.toString();
}

From source file:org.regenstrief.util.Util.java

/**
 * Looks up a Class name in a cache, adding it if it is not present
 * //from  w  w w .  ja  v a 2  s. c  o m
 * @param c the Class
 * @return the name String
 **/
public static final String lookupClassName(final Class<?> c) {
    String name = classMap.get(c);

    if (name == null) {
        name = c.getName();
        int i = name.lastIndexOf('$') + 1;
        final int size = name.length();

        for (; i < size; i++) {
            if (Character.isJavaIdentifierStart(name.charAt(i))) {
                break;
            }
        }

        if (i > 0) {
            name = name.substring(i);
        }
        classMap.put(c, name);
    }

    return name;
}