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:org.archive.io.hdfs.HDFSWriterDocument.java

/**
 * Parses the Content-Type HTTP header//from ww w  . ja  v  a  2  s .c  o m
 */
private void parseContentType(ByteScan.State bss) {

    if (!ByteScan.SkipWhitespace(bss))
        return;

    if (bss.buf[bss.offset] == '"')
        bss.offset++;

    if (!ByteScan.SkipWhitespace(bss))
        return;

    bss.mark();

    while (!bss.eob() && (Character.isLetterOrDigit(bss.buf[bss.offset]) || bss.buf[bss.offset] == '/'
            || bss.buf[bss.offset] == '-' || bss.buf[bss.offset] == '+' || bss.buf[bss.offset] == '.'))
        bss.offset++;

    contentType = bss.toString().toLowerCase().trim();
    if (contentType != null && contentType.indexOf("/") == -1)
        contentType = null;

    if (!ByteScan.Find(bss, ';'))
        return;

    if (!bss.eob()) {
        bss.mark();
        bss.offset = bss.end;
        String inputStr = bss.toString().toLowerCase();
        String paramStr;
        StringTokenizer st = new StringTokenizer(inputStr, ";");

        while (st.hasMoreTokens()) {
            paramStr = st.nextToken().trim();
            if (paramStr.startsWith("charset")) {
                int eqOff = paramStr.indexOf('=', 7);
                if (eqOff >= 0) {
                    charset = paramStr.substring(eqOff + 1).trim().toUpperCase();
                    charset = cleanCharset(charset);
                }
            }
        }
    }
}

From source file:org.qedeq.base.utility.StringUtility.java

/**
 * Get a byte array of a hex string representation.
 *
 * @param   hex     Hex string representation of data.
 * @return  Data array.//w  ww  .j av a  2 s. com
 * @throws  IllegalArgumentException Padding wrong or illegal hexadecimal character.
 */
public static byte[] hex2byte(final String hex) {

    StringBuffer buffer = new StringBuffer(hex.length());
    char c;
    for (int i = 0; i < hex.length(); i++) {
        c = hex.charAt(i);
        if (!Character.isWhitespace(c)) {
            if (!Character.isLetterOrDigit(c)) {
                throw new IllegalArgumentException("Illegal hex char");
            }
            buffer.append(c);
        }
    }
    if (buffer.length() % 2 != 0) {
        throw new IllegalArgumentException("Bad padding");
    }
    byte[] result = new byte[buffer.length() / 2];
    for (int i = 0; i < buffer.length() / 2; i++) {
        try {
            result[i] = (byte) Integer.parseInt(buffer.substring(2 * i, 2 * i + 2), 16);
        } catch (Exception e) {
            throw new IllegalArgumentException("Illegal hex char");
        }
    }
    return result;
}

From source file:org.jboss.pnc.indyrepositorymanager.RepositoryManagerDriver.java

/**
 * Converts characters in a given string considered as illegal by Indy to underscores.
 *
 * @param name repository name/*w  ww .j  av a 2 s .c  o m*/
 * @return string with converted characters
 */
private String convertIllegalCharacters(String name) {
    char[] result = new char[name.length()];
    for (int i = 0; i < name.length(); i++) {
        char checkedChar = name.charAt(i);
        if (Character.isLetterOrDigit(checkedChar) || checkedChar == '+' || checkedChar == '-'
                || checkedChar == '.') {
            result[i] = checkedChar;
        } else {
            result[i] = '_';
        }
    }
    return String.valueOf(result);
}

From source file:de.innovationgate.wgpublisher.url.TitlePathManager.java

public String normalizeShareTitle(String title) throws UnsupportedEncodingException {

    // Need to "normalize" String cause MacOS-DAV uses "decomposed" UTF-8 which breaks strings on database storage
    // title = com.ibm.icu.text.Normalizer.compose(title, true);
    title = WGUtils.normalizeUnicode(title);

    StringBuffer name = new StringBuffer();

    for (int i = 0; i < title.length(); i++) {
        char c = title.charAt(i);

        // Unmodified chars
        if (Character.isLetterOrDigit(c)) {
            name.append(c);//  www .ja va 2 s.  c  o  m
        } else if (_allowAllCharacters || SHARE_NAME_SPECIAL_CHARS.indexOf(c) != -1) {
            name.append(c);
        } else {
            name.append('?');
        }
    }

    return name.toString();
}

From source file:org.jembi.rhea.impl.ApelonServiceImpl.java

private static String buildQueryString(String query, boolean exact) {
    StringBuilder scrubbed = new StringBuilder();
    for (int i = 0; i < query.length(); i++) {
        if (Character.isLetterOrDigit(query.charAt(i)) || Character.isWhitespace(query.charAt(i)))
            scrubbed.append(query.charAt(i));
    }//from  ww  w .j av  a 2s. c o  m

    if (exact)
        return scrubbed.toString();

    StringBuilder res = new StringBuilder();
    res.append("*");
    for (String s : scrubbed.toString().split("\\s+"))
        res.append(s + "*");
    return res.toString();
}

From source file:org.appspot.apprtc.util.ThumbnailsCacheManager.java

public static String getFirstLetter(String name) {
    for (Character c : name.toCharArray()) {
        if (Character.isLetterOrDigit(c)) {
            return c.toString();
        }// w  w  w . j  a  v a2s .  c o  m
    }
    return "X";
}

From source file:org.archive.io.hdfs.HDFSWriterDocument.java

private String cleanCharset(String charset) {
    if (charset.startsWith("\"") && charset.endsWith("\""))
        charset = charset.substring(1, charset.length() - 1);
    char[] csetChars = charset.toCharArray();
    int len = 0;/*from w  w  w . java2 s  .  co m*/
    while (len < csetChars.length && (Character.isLetterOrDigit(csetChars[len]) || csetChars[len] == '-'))
        len++;
    if (len < csetChars.length)
        charset = new String(csetChars, 0, len);
    if (!charset.startsWith("ISO-") && ((charset.endsWith("8859-1") || charset.endsWith("8859_1")))) {
        charset = "ISO-8859-1";
    } else if (charset.endsWith("UTF8")) {
        charset = "UTF-8";
    }
    return charset;
}

From source file:org.executequery.gui.editor.autocomplete.QueryEditorAutoCompletePopupProvider.java

public void popupSelectionMade() {

    AutoCompleteListItem selectedListItem = (AutoCompleteListItem) autoCompletePopup.getSelectedItem();

    if (selectedListItem == null || selectedListItem.isNothingProposed()) {

        return;//ww w.j  ava 2  s.  c o  m
    }

    String selectedValue = selectedListItem.getInsertionValue();

    try {

        JTextComponent textComponent = queryEditorTextComponent();
        Document document = textComponent.getDocument();

        int caretPosition = textComponent.getCaretPosition();
        String wordAtCursor = queryEditor.getWordToCursor();

        if (StringUtils.isNotBlank(wordAtCursor)) {

            int wordAtCursorLength = wordAtCursor.length();
            int insertionIndex = caretPosition - wordAtCursorLength;

            if (selectedListItem.isKeyword() && isAllLowerCase(wordAtCursor)) {

                selectedValue = selectedValue.toLowerCase();
            }

            if (!Character.isLetterOrDigit(wordAtCursor.charAt(0))) {

                // cases where you might have a.column_name or similar

                insertionIndex++;
                wordAtCursorLength--;

            } else if (wordAtCursor.contains(".")) {

                int index = wordAtCursor.indexOf(".");
                insertionIndex += index + 1;
                wordAtCursorLength -= index + 1;
            }

            document.remove(insertionIndex, wordAtCursorLength);
            document.insertString(insertionIndex, selectedValue, null);

        } else {

            document.insertString(caretPosition, selectedValue, null);
        }

    } catch (BadLocationException e) {

        debug("Error on autocomplete insertion", e);

    } finally {

        autoCompletePopup.hidePopup();
    }

}

From source file:org.apache.cocoon.transformation.TraxTransformer.java

/**
 * Test if the name is a valid parameter name for XSLT
 *//*from w w w  .j  av  a 2 s.com*/
static boolean isValidXSLTParameterName(String name) {
    if (name.length() == 0) {
        return false;
    }

    char c = name.charAt(0);
    if (!(Character.isLetter(c) || c == '_')) {
        return false;
    }

    for (int i = name.length() - 1; i > 1; i--) {
        c = name.charAt(i);
        if (!(Character.isLetterOrDigit(c) || c == '-' || c == '_' || c == '.')) {
            return false;
        }
    }
    return true;
}

From source file:org.exoplatform.services.cms.impl.Utils.java

/**
 * Clean string./*from www.j  av  a  2  s. c o  m*/
 *
 * @param str the str
 *
 * @return the string
 */
public static String cleanString(String str) {
    Transliterator accentsconverter = Transliterator
            .getInstance("Latin; NFD; [:Nonspacing Mark:] Remove; NFC;");
    str = accentsconverter.transliterate(str);
    //the character ? seems to not be changed to d by the transliterate function
    StringBuffer cleanedStr = new StringBuffer(str.trim());
    // delete special character
    for (int i = 0; i < cleanedStr.length(); i++) {
        char c = cleanedStr.charAt(i);
        if (c == ' ') {
            if (i > 0 && cleanedStr.charAt(i - 1) == '-') {
                cleanedStr.deleteCharAt(i--);
            } else {
                c = '-';
                cleanedStr.setCharAt(i, c);
            }
            continue;
        }
        if (i > 0 && !(Character.isLetterOrDigit(c) || c == '-')) {
            cleanedStr.deleteCharAt(i--);
            continue;
        }
        if (i > 0 && c == '-' && cleanedStr.charAt(i - 1) == '-')
            cleanedStr.deleteCharAt(i--);
    }
    while (StringUtils.isNotEmpty(cleanedStr.toString()) && !Character.isLetterOrDigit(cleanedStr.charAt(0))) {
        cleanedStr.deleteCharAt(0);
    }
    String clean = cleanedStr.toString().toLowerCase();
    if (clean.endsWith("-")) {
        clean = clean.substring(0, clean.length() - 1);
    }

    return clean;
}