List of usage examples for java.lang Character isLetter
public static boolean isLetter(int codePoint)
From source file:Main.java
public static String getFirstChar(String value) { if (value != null) { for (int i = 0; i < value.length(); i++) { char ch = value.charAt(i); if (Character.isLetter(ch)) { return String.valueOf(ch).toUpperCase(); }//from ww w . ja v a 2 s. c o m } } return String.valueOf(" "); }
From source file:Main.java
private static String capitalizeAllWords(String str) { String phrase = ""; boolean capitalize = true; for (char c : str.toLowerCase().toCharArray()) { if (Character.isLetter(c) && capitalize) { phrase += Character.toUpperCase(c); capitalize = false;//from w ww . j av a2s . c o m continue; } else if (c == ' ') { capitalize = true; } phrase += c; } return phrase; }
From source file:Main.java
public static boolean isLegalName(String n) { if (n.length() == 0) return false; if (!Character.isLetter(n.charAt(0))) return false; for (int i = 0; i < n.length(); i++) { char c = n.charAt(i); if (Character.isLetterOrDigit(c)) continue; if (c == '_') continue; if (c == '.') continue; return false; }//from ww w .j a v a2 s . c om if (n.length() > 1) { String n2 = n.substring(0, 2); if (n2.equalsIgnoreCase("JS")) return false; } if (n.indexOf("__") >= 0) return false; if (reservedWords.contains(n)) return false; return true; }
From source file:Main.java
public static String randomStr(long strLen) { char freshChar; String freshString;/*from w w w .jav a 2 s. c o m*/ freshString = ""; while (freshString.length() < (strLen - 1)) { freshChar = (char) (Math.random() * 128); if (Character.isLetter(freshChar)) { freshString += freshChar; } } return (freshString); }
From source file:Main.java
private static String __getNextWord(String s, int pos) { int i = 0;//from www .j a v a 2 s . com StringBuilder sb = new StringBuilder(); while (pos + i < s.length()) { char c = s.charAt(pos + i); if (Character.isLetter(c)) { sb.append(c); } else { break; } i++; } if (sb.length() == 0) return null; return sb.toString(); }
From source file:Main.java
public static String computePhraseShape(String x) { StringBuilder buf = new StringBuilder(); char lastc = 0; for (int i = 0; i < x.length(); i++) { char c = x.charAt(i); if (Character.isDigit(c)) c = '0'; else if (Character.isLetter(c)) c = Character.isLowerCase(c) ? 'a' : 'A'; else if (Character.isWhitespace(c) || Character.isSpaceChar(c)) c = ' '; if (c != lastc) buf.append(c);/*from w ww. j a v a 2 s . c o m*/ lastc = c; } return buf.toString(); }
From source file:Main.java
/** * @param str str/* ww w . ja va 2 s . co m*/ * @return String */ public static String capitalizeFirstLetter(String str) { if (isEmpty(str)) { return str; } char c = str.charAt(0); return (!Character.isLetter(c) || Character.isUpperCase(c)) ? str : new StringBuilder(str.length()).append(Character.toUpperCase(c)).append(str.substring(1)) .toString(); }
From source file:Main.java
public static String trimToId(String aName) { String result = aName;/*from w w w. j a v a 2s . co m*/ // if no name was given, generate an id if (result == null || result.isEmpty()) { return "id_" + java.util.UUID.randomUUID().toString(); } // must be at least 2 characters long,must start with a letter else if (result.length() < 2 || !Character.isLetter(result.charAt(0))) { result = "id_" + result; } // capitalize, except first char (lower case) String[] words = result.split("\\W+"); // split into words result = ""; // reset result and build new for (int i = 0; i < words.length; i++) { result += (i == 0) ? // keep first word as is words[i] : // following words capitalize first char words[i].substring(0, 1).toUpperCase() + words[i].substring(1); } // umlauts, whitespaces and periods are not allowed result = result.replaceAll("\\s", "").replaceAll("\\.", "").replaceAll("\\u00c4", "Ae") .replaceAll("\\u00e4", "ae").replaceAll("\\u00d6", "Oe").replaceAll("\\u00f6", "oe") .replaceAll("\\u00dc", "Ue").replaceAll("\\u00fc", "ue").replaceAll("\\u00df", "ss"); return result; }
From source file:Main.java
public static boolean isXmlNameStartChar(char chr) { // [4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | // [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | // [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] // http://www.w3.org/TR/REC-xml/#NT-Name return Character.isLetter(chr) || chr == ':' || chr == '_' || isInRange(chr, 0xC0, 0xD6) || isInRange(chr, 0xD8, 0xF6) || isInRange(chr, 0xF8, 0x2FF) || isInRange(chr, 0x370, 0x37D) || isInRange(chr, 0x37F, 0x1FFF) || isInRange(chr, 0x200C, 0x200D) || isInRange(chr, 0x2070, 0x218F) || isInRange(chr, 0x2C00, 0x2FEF) || isInRange(chr, 0x3001, 0xD7FF) || isInRange(chr, 0xF900, 0xFDCF) || isInRange(chr, 0xFDF0, 0xFFFD) || isInRange(chr, 0x10000, 0xEFFFF); }
From source file:Main.java
private static String addSpaceIfRequired(String value, int index) { if (index == 0) return VOID_STRING; char precedingChar = value.charAt(index - 1); char thisChar = value.charAt(index); if (Character.isLowerCase(precedingChar) && Character.isUpperCase(thisChar) || Character.isLetter(precedingChar) && Character.isDigit(thisChar) || Character.isDigit(precedingChar) && Character.isLetter(thisChar)) { return SPACE; }/*from w w w. j av a2s. c o m*/ if (index + 1 == value.length()) return VOID_STRING; char nextChar = value.charAt(index + 1); if (Character.isUpperCase(precedingChar) && Character.isUpperCase(thisChar) && Character.isLowerCase(nextChar)) { return SPACE; } return VOID_STRING; }