Example usage for java.lang Character isLetterOrDigit

List of usage examples for java.lang Character isLetterOrDigit

Introduction

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

Prototype

public static boolean isLetterOrDigit(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a letter or digit.

Usage

From source file:com.limegroup.gnutella.gui.GUIUtils.java

private static int getAmpersandPosition(String text) {
    int index = -1;
    while ((index = text.indexOf('&', index + 1)) != -1) {
        if (index < text.length() - 1 && Character.isLetterOrDigit(text.charAt(index + 1))) {
            break;
        }/*from   www .ja  va2 s  .  com*/
    }
    return index;
}

From source file:edu.uga.cs.fluxbuster.db.PostgresDBInterface.java

/**
 * Filter characters out of a domain name.  All characters are
 * filtered except for [a-zA-Z0-9+-.].  
 *
 * @param domainName the domain name to filter
 * @return the filtered domain name/*from w  ww . ja  va  2s. co m*/
 */
private String filterChars(String domainName) {
    String returnValue = "";

    for (char val : domainName.toCharArray()) {
        if (Character.isLetterOrDigit(val) || val == '+' || val == '-' || val == '.') {
            returnValue += val;
        }
    }

    return returnValue;
}

From source file:org.executequery.gui.editor.QueryEditorTextPane.java

private int indexOfWordStartFromIndex(int index) {

    int start = -1;
    int end = index;

    char[] chars = getText().toCharArray();
    for (int i = end - 1; i >= 0; i--) {

        if (!Character.isLetterOrDigit(chars[i]) && chars[i] != '_' && chars[i] != '.') {

            start = i;//from   www. ja va2 s .  c  om
            break;
        }

    }

    return start;
}

From source file:org.executequery.gui.editor.QueryEditorTextPane.java

private String getWordEndingAt(int position) {

    String text = getText();/*from  ww  w .j  a  v a  2 s .  c  o  m*/

    if (MiscUtils.isNull(text)) {

        return Constants.EMPTY;
    }

    char[] chars = text.toCharArray();

    int start = -1;
    int end = position;

    for (int i = end - 1; i >= 0; i--) {

        if (!Character.isLetterOrDigit(chars[i]) && chars[i] != '_' && chars[i] != '.') {

            start = i;
            break;
        }

    }

    if (start < 0) {

        start = 0;
    }

    return text.substring(start, end).trim();
}

From source file:org.alfresco.web.bean.wizard.NewUserWizard.java

/**
 * Validate password field data is acceptable
 *//*from www.j a  va2s .c  o  m*/
public void validatePassword(FacesContext context, UIComponent component, Object value)
        throws ValidatorException {
    String pass = (String) value;
    if (pass.length() < 5 || pass.length() > 12) {
        String err = "Password must be between 5 and 12 characters in length.";
        throw new ValidatorException(new FacesMessage(err));
    }

    for (int i = 0; i < pass.length(); i++) {
        if (Character.isLetterOrDigit(pass.charAt(i)) == false) {
            String err = "Password can only contain characters or digits.";
            throw new ValidatorException(new FacesMessage(err));
        }
    }
}

From source file:com.xpn.xwiki.util.Util.java

/**
 * Removes all non alpha numerical characters from the passed text. First tries to convert accented chars to their
 * alpha numeric representation.//ww  w  . j a  va2s  . c o  m
 * 
 * @param text the text to convert
 * @return the alpha numeric equivalent
 */
public static String convertToAlphaNumeric(String text) {
    // Start by removing accents
    String textNoAccents = Util.noaccents(text);

    // Now remove all non alphanumeric chars
    StringBuffer result = new StringBuffer(textNoAccents.length());
    char[] testChars = textNoAccents.toCharArray();
    for (char testChar : testChars) {
        if (Character.isLetterOrDigit(testChar) && testChar < 128) {
            result.append(testChar);
        }
    }

    return result.toString();
}

From source file:org.apache.hadoop.hive.metastore.MetaStoreUtils.java

private static boolean isValidTypeChar(char c) {
    return Character.isLetterOrDigit(c) || c == '_';
}

From source file:org.alfresco.web.bean.wizard.NewUserWizard.java

/**
 * Validate Username field data is acceptable
 *///w ww .  ja  v a2 s. c o m
public void validateUsername(FacesContext context, UIComponent component, Object value)
        throws ValidatorException {
    String pass = (String) value;
    if (pass.length() < 5 || pass.length() > 12) {
        String err = "Username must be between 5 and 12 characters in length.";
        throw new ValidatorException(new FacesMessage(err));
    }

    for (int i = 0; i < pass.length(); i++) {
        if (Character.isLetterOrDigit(pass.charAt(i)) == false) {
            String err = "Username can only contain characters or digits.";
            throw new ValidatorException(new FacesMessage(err));
        }
    }
}

From source file:org.nuxeo.ecm.platform.query.nxql.NXQLQueryBuilder.java

/**
 * @since 8.4/*from  w w  w.  j ava 2  s .  c o  m*/
 */
public static String buildPattern(String pattern, String key, String replacement) {
    int index = pattern.indexOf(key);
    while (index >= 0) {
        // All keys not prefixed by a letter or a digit has to be replaced, because
        // It could be part of a schema name
        if (!Character.isLetterOrDigit(pattern.charAt(index - 1)) && (index + key.length() == pattern.length()
                || !Character.isLetterOrDigit(pattern.charAt(index + key.length())))) {
            pattern = pattern.substring(0, index) + pattern.substring(index).replaceFirst(key, replacement);
        }
        index = pattern.indexOf(key, index + 1);
    }
    return pattern;
}

From source file:com.ecyrd.jspwiki.parser.JSPWikiMarkupParser.java

/**
 *  Escapes XML entities in a HTML-compatible way (i.e. does not escape
 *  entities that are already escaped)./* ww  w .ja  v  a  2  s.  c o m*/
 *
 *  @param buf
 *  @return An escaped string.
 */
private String escapeHTMLEntities(String buf) {
    StringBuilder tmpBuf = new StringBuilder(buf.length() + 20);

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

        if (ch == '<') {
            tmpBuf.append("&lt;");
        } else if (ch == '>') {
            tmpBuf.append("&gt;");
        } else if (ch == '\"') {
            tmpBuf.append("&quot;");
        } else if (ch == '&') {
            //
            //  If the following is an XML entity reference (&#.*;) we'll
            //  leave it as it is; otherwise we'll replace it with an &amp;
            //

            boolean isEntity = false;
            StringBuilder entityBuf = new StringBuilder();

            if (i < buf.length() - 1) {
                for (int j = i; j < buf.length(); j++) {
                    char ch2 = buf.charAt(j);

                    if (Character.isLetterOrDigit(ch2) || (ch2 == '#' && j == i + 1) || ch2 == ';'
                            || ch2 == '&') {
                        entityBuf.append(ch2);

                        if (ch2 == ';') {
                            isEntity = true;
                            break;
                        }
                    } else {
                        break;
                    }
                }
            }

            if (isEntity) {
                tmpBuf.append(entityBuf);
                i = i + entityBuf.length() - 1;
            } else {
                tmpBuf.append("&amp;");
            }

        } else {
            tmpBuf.append(ch);
        }
    }

    return tmpBuf.toString();
}