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:net.sf.jabref.logic.labelPattern.LabelPatternUtil.java

private static String keepLettersAndDigitsOnly(String in) {
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < in.length(); i++) {
        if (Character.isLetterOrDigit(in.charAt(i))) {
            stringBuilder.append(in.charAt(i));
        }/*ww w. j  a va2s  .  c  o m*/
    }
    return stringBuilder.toString();
}

From source file:org.dasein.cloud.rackspace.compute.CloudServers.java

private String validateName(String name, boolean safeName) throws InternalException, CloudException {
    if (safeName) {
        name = name.toLowerCase().replaceAll(" ", "-");
    }//from   ww  w.ja  v  a  2  s .  co  m
    if (name.length() > NAME_LIMIT) {
        name = name.substring(0, NAME_LIMIT);
    }
    StringBuilder str = new StringBuilder();

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

        if (!safeName) {
            if (Character.isLetterOrDigit(c) || c == '-' || c == ' ') {
                if (str.length() > 0 || Character.isLetter(c)) {
                    str.append(c);
                }
            }
        } else {
            if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-') {
                if (str.length() > 0 || Character.isLetter(c)) {
                    str.append(c);
                }
            }
        }
    }
    if (str.length() < 1) {
        return makeUpName(name);
    }
    name = str.toString();
    while (!Character.isLetterOrDigit(name.charAt(name.length() - 1))) {
        if (name.length() < 2) {
            return makeUpName(name);
        }
        name = name.substring(0, name.length() - 1);
    }
    if (serverExists(name)) {
        return makeUpName(name);
    }
    return name;
}

From source file:gov.llnl.lc.smt.command.SmtCommand.java

public static String convertSpecialFileName(String fname) {
    if ((fname == null) || (fname.length() < 2))
        return null;

    String fileName = fname;/*from w ww  . j  av  a  2s .c o  m*/

    if (fname.startsWith("~"))
        fileName = System.getProperty("user.home") + fname.substring(1);
    if (fname.startsWith("%h"))
        fileName = System.getProperty("user.home") + fname.substring(2);
    if (fname.startsWith("%t"))
        fileName = System.getProperty("java.io.tmpdir") + fname.substring(2);

    // finally, if the file name is just the file name, assume path is current directory
    if (Character.isLetterOrDigit(fname.charAt(0)))
        fileName = System.getProperty("user.dir") + FILE_SEPARATOR + fname;
    return fileName;
}

From source file:org.xcmis.search.lucene.LuceneQueryBuilder.java

/**
 * Transform Like pattern to regular expression.
 * /*from   w  w w.ja v a  2s .  co m*/
 * @param pattern Like pattern
 * @return String regular expression
 */
private String likePatternToRegex(final String pattern) {
    // - escape all non alphabetic characters
    // - escape constructs like \<alphabetic char> into \\<alphabetic char>
    // - replace non escaped _ % into . and .*
    final StringBuffer regexp = new StringBuffer();
    regexp.append("^");
    boolean escaped = false;
    for (int i = 0; i < pattern.length(); i++) {
        if (pattern.charAt(i) == LIKE_ESCAPE_CHAR) {
            if (escaped) {
                regexp.append("\\\\");
                escaped = false;
            } else {
                escaped = true;
            }
        } else {
            if (Character.isLetterOrDigit(pattern.charAt(i))) {
                if (escaped) {
                    regexp.append(pattern.charAt(i)); // append("\\\\")
                    escaped = false;
                } else {
                    regexp.append(pattern.charAt(i));
                }
            } else {
                if (escaped) {
                    regexp.append('\\').append(pattern.charAt(i));
                    escaped = false;
                } else {
                    switch (pattern.charAt(i)) {
                    case LIKE_MATCH_ONE_CHAR:
                        regexp.append('.');
                        break;
                    case LIKE_MATCH_ZERO_OR_MORE_CHAR:
                        regexp.append(".*");
                        break;
                    default:
                        regexp.append('\\').append(pattern.charAt(i));
                    }
                }
            }
        }
    }
    regexp.append("$");
    return regexp.toString();
}

From source file:r.parser.RLexer.java

private int consumeSymbolValue(int c) {

    StringBuffer buffer = new StringBuffer();

    do {/*from w w w  .j  ava2  s  .  c o m*/
        buffer.appendCodePoint(c);
    } while ((c = xxgetc()) != R_EOF && (Character.isLetterOrDigit(c) || c == '.' || c == '_'));

    xxungetc(c);

    int keyword;
    if ((keyword = lookupKeyword(buffer.toString())) != 0) {
        if (keyword == FUNCTION) {
            parseState.getFunctionSource().descend();
        }
        return keyword;
    }
    yylval = install(buffer.toString());
    return SYMBOL;
}

From source file:org.zaproxy.zap.extension.zest.ZestZapUtils.java

public static boolean isValidVariableName(String name) {
    if (name == null || name.length() == 0) {
        return false;
    }/* w ww  .  j  a  v  a  2 s. com*/
    if (!Character.isLetter(name.charAt(0))) {
        // Seams reasonable to require it starts with a character
        return false;
    }
    for (char chr : name.toCharArray()) {
        if (!Character.isLetterOrDigit(chr) && ZEST_VAR_VALID_CHRS.indexOf(chr) == -1) {
            return false;
        }
    }
    return true;
}

From source file:com.ringdroid.RingdroidEditActivity.java

private String makeRingtoneFilename(CharSequence title, String extension) {
    String parentdir;/* www .  jav  a  2 s .  c o  m*/
    switch (mNewFileKind) {
    default:
    case FileSaveDialog.FILE_KIND_MUSIC:
        parentdir = "/sdcard/media/audio/music";
        break;
    case FileSaveDialog.FILE_KIND_ALARM:
        parentdir = "/sdcard/media/audio/alarms";
        break;
    case FileSaveDialog.FILE_KIND_NOTIFICATION:
        parentdir = "/sdcard/media/audio/notifications";
        break;
    case FileSaveDialog.FILE_KIND_RINGTONE:
        parentdir = "/sdcard/media/audio/ringtones";
        break;
    }

    // Create the parent directory
    File parentDirFile = new File(parentdir);
    parentDirFile.mkdirs();

    // If we can't write to that special path, try just writing
    // directly to the sdcard
    if (!parentDirFile.isDirectory()) {
        parentdir = "/sdcard";
    }

    // Turn the title into a filename
    String filename = "";
    for (int i = 0; i < title.length(); i++) {
        if (Character.isLetterOrDigit(title.charAt(i))) {
            filename += title.charAt(i);
        }
    }

    // Try to make the filename unique
    String path = null;
    for (int i = 0; i < 100; i++) {
        String testPath;
        if (i > 0)
            testPath = parentdir + "/" + filename + i + extension;
        else
            testPath = parentdir + "/" + filename + extension;

        try {
            RandomAccessFile f = new RandomAccessFile(new File(testPath), "r");
        } catch (Exception e) {
            // Good, the file didn't exist
            path = testPath;
            break;
        }
    }

    return path;
}

From source file:com.tsp.clipsy.audio.RingdroidEditActivity.java

private String makeRingtoneFilename(CharSequence title, String extension) {
    String parentdir = "/sdcard/media/audio/clipsy";

    // Create the parent directory
    File parentDirFile = new File(parentdir);
    parentDirFile.mkdirs();//from w  ww.ja  v  a 2 s . c o m

    // If we can't write to that special path, try just writing
    // directly to the sdcard
    if (!parentDirFile.isDirectory()) {
        parentdir = "/sdcard";
    }

    // Turn the title into a filename
    String filename = "";
    for (int i = 0; i < title.length(); i++) {
        if (Character.isLetterOrDigit(title.charAt(i))) {
            filename += title.charAt(i);
        }
    }

    // Try to make the filename unique
    String path = null;
    for (int i = 0; i < 100; i++) {
        String testPath;
        if (i > 0)
            testPath = parentdir + "/" + filename + i + extension;
        else
            testPath = parentdir + "/" + filename + extension;

        try {
            RandomAccessFile f = new RandomAccessFile(new File(testPath), "r");
        } catch (Exception e) {
            // Good, the file didn't exist
            path = testPath;
            break;
        }
    }

    return path;
}

From source file:org.sakaiproject.tool.assessment.ui.bean.delivery.ItemContentsBean.java

public boolean isNotEmpty(String wyzText) {

    if (wyzText != null && !wyzText.equals("null")) {
        int index = 0;
        String t = wyzText.trim();
        while (index < t.length()) {
            char c = t.charAt(index);
            if (Character.isLetterOrDigit(c)) {
                return true;
            }//from   ww  w . ja  v a  2  s  .  c o  m
            index++;
        }
    }
    return false;
}

From source file:com.juick.android.JuickMessagesAdapter.java

public static boolean isNickPart(char c) {
    return Character.isLetterOrDigit(c) || c == '_' || c == '-' || c == '@';
}