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:Main.java

private static void validateLocalePart(String localePart) {
    for (int i = 0; i < localePart.length(); i++) {
        char ch = localePart.charAt(i);
        if (ch != '_' && ch != ' ' && !Character.isLetterOrDigit(ch)) {
            throw new IllegalArgumentException(
                    "Locale part \"" + localePart + "\" contains invalid characters");
        }// w  ww .ja  v a2  s  .co m
    }
}

From source file:Main.java

public static String stripSplChars(String data) {
    if (data != null) {
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < data.length(); i++) {
            if (Character.isLetterOrDigit(data.charAt(i))) {
                result.append(data.charAt(i));
            }//from w  w  w. j  a va2 s  .  c  o  m
        }
        return result.toString();
    } else {
        return null;
    }
}

From source file:Main.java

static synchronized String toCamelCase(String str) {
    if (str == null)
        return null;
    int pos = 0;/*from ww  w  .  j  a va 2 s. c  o m*/
    boolean doCapitalize = true;
    for (int i = 0; i < str.length(); ++i) {
        char ch = str.charAt(i);
        if (Character.isLetterOrDigit(ch)) {
            if (doCapitalize && Character.isLetter(ch)) {
                ch = Character.toUpperCase(ch);
            }
            sCamelCase[pos] = ch;
            ++pos;
            doCapitalize = false;
        } else if (ch == '_') {
            doCapitalize = true;
        }
    }

    return new String(sCamelCase, 0, pos);
}

From source file:Main.java

/***
 * replaces all non letter and non digit characte from file name
 * /* w w  w  . java2 s  .  co  m*/
 * @param str
 * @param replace
 * @return
 */
public static String createFileName2(String str, char replace) {
    StringBuffer result = new StringBuffer();

    for (int c = 0; c < str.length(); c++) {
        char ch = str.charAt(c);

        if (Character.isLetterOrDigit(ch))
            result.append(ch);
        else
            result.append(replace);
    }

    return result.toString();
}

From source file:TextUtilities.java

/**
 * Locates the start of the word at the specified position.
 * //from   w  ww  .  j  a va2s  .  c o  m
 * @param line
 *           The text
 * @param pos
 *           The position
 */
public static int findWordStart(String line, int pos, String noWordSep) {
    char ch = line.charAt(pos - 1);

    if (noWordSep == null)
        noWordSep = "";
    boolean selectNoLetter = (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1);

    int wordStart = 0;
    for (int i = pos - 1; i >= 0; i--) {
        ch = line.charAt(i);
        if (selectNoLetter ^ (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1)) {
            wordStart = i + 1;
            break;
        }
    }

    return wordStart;
}

From source file:Main.java

/**
 * Return true if the string is alphanum.
 * <code>{letter digit (.) (_) (-) ( ) (?) }</code>
 * /*from w  w w.j av  a2  s  . c o m*/
 **/
public static boolean isAlphaNumeric(String s) {
    int i = 0, len = s.length();
    while (i < len && (Character.isLetterOrDigit(s.charAt(i)) || s.charAt(i) == ' ' || s.charAt(i) == '.'
            || s.charAt(i) == '-' || s.charAt(i) == '_') || s.charAt(i) == '?') {
        i++;
    }
    return (i >= len);
}

From source file:Main.java

/***
 * replaces only white spaces from file name
 *///  w  ww.  ja  va 2 s .  c  o m
public static String createFileName(String str, char whitespaceChar) {
    StringBuffer result = new StringBuffer();

    for (int c = 0; c < str.length(); c++) {
        char ch = str.charAt(c);

        if (Character.isWhitespace(ch) && whitespaceChar != 0)
            result.append(whitespaceChar);
        else if (Character.isLetterOrDigit(ch))
            result.append(ch);
        else if (ch == whitespaceChar)
            result.append(ch);
    }

    return result.toString();
}

From source file:Main.java

static private boolean isCharOkInFileName(char c) {
    if (Character.isLetterOrDigit(c))
        return true;
    return false;
}

From source file:Main.java

public static boolean isValidCharInFolder(char c) {
    if (Character.isLetterOrDigit(c) || c > 128 || c == 32)
        return true;

    return false;
}

From source file:Main.java

/**
 * Converts a string to title casing.//from   w  w  w.  ja v a  2  s .c  o m
 *
 * @param str The string to convert.
 * @return The converted string.
 */
public static String toTitleCase(String str) {
    if (str == null) {
        return null;
    }

    boolean isSeparator = true;
    StringBuilder builder = new StringBuilder(str);
    final int len = builder.length();

    for (int i = 0; i < len; ++i) {
        char c = builder.charAt(i);
        if (isSeparator) {
            if (Character.isLetterOrDigit(c)) {
                // Convert to title case and switch out of whitespace mode.
                builder.setCharAt(i, Character.toTitleCase(c));
                isSeparator = false;
            }
        } else if (!Character.isLetterOrDigit(c)) {
            isSeparator = true;
        } else {
            builder.setCharAt(i, Character.toLowerCase(c));
        }
    }

    return builder.toString();
}