List of usage examples for java.lang Character isLetter
public static boolean isLetter(int codePoint)
From source file:Main.java
/** * @brief Converting the url to lower case. * /* w w w . ja v a2 s . co m*/ * @param strUrl [IN] url path * * @return Return modificated url string */ public static String fixUrl(String inUrl) { if (inUrl == null) { return null; } int colon = inUrl.indexOf(':'); boolean allLower = true; if (colon == -1) { inUrl = "http://" + inUrl; } for (int index = 0; index < colon; index++) { char ch = inUrl.charAt(index); if (!Character.isLetter(ch)) { break; } allLower &= Character.isLowerCase(ch); if (index == colon - 1 && !allLower) { inUrl = inUrl.substring(0, colon).toLowerCase() + inUrl.substring(colon); } } if (inUrl.startsWith("http://") || inUrl.startsWith("https://")) return inUrl; if (inUrl.startsWith("http:") || inUrl.startsWith("https:")) { if (inUrl.startsWith("http:/") || inUrl.startsWith("https:/")) { inUrl = inUrl.replaceFirst("/", "//"); } else inUrl = inUrl.replaceFirst(":", "://"); } return inUrl; }
From source file:Main.java
/** * capitalize first letter//from ww w . ja v a2 s . co m * * <pre> * capitalizeFirstLetter(null) = null; * capitalizeFirstLetter("") = ""; * capitalizeFirstLetter("2ab") = "2ab" * capitalizeFirstLetter("a") = "A" * capitalizeFirstLetter("ab") = "Ab" * capitalizeFirstLetter("Abc") = "Abc" * </pre> * * @param str * @return */ 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:edu.illinois.cs.cogcomp.ner.StringStatisticsUtils.MyString.java
public static String cleanPunctuation(String s) { StringBuilder res = new StringBuilder(s.length()); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (Character.isLetter(c) || Character.isDigit(c)) res.append(c);/*w w w . ja v a 2s.c om*/ } return res.toString(); }
From source file:Main.java
private static String capitalize(String str) { if (TextUtils.isEmpty(str)) { return str; }/*from w ww . ja va 2s .co m*/ char[] arr = str.toCharArray(); boolean capitalizeNext = true; String phrase = ""; for (char c : arr) { if (capitalizeNext && Character.isLetter(c)) { phrase += Character.toUpperCase(c); capitalizeNext = false; continue; } else if (Character.isWhitespace(c)) { capitalizeNext = true; } phrase += c; } return phrase; }
From source file:Main.java
public static int countLetters(String str) { int len = str.length(); int chars = 0; for (int i = 0; i < len; i++) { if (Character.isLetter(str.charAt(i))) chars++;//from ww w .j a v a 2s. c o m } return chars; }
From source file:Main.java
/** * Return a valid element name from the given string. * * <p>Letters are put to lower case and other characters are replaced by hyphens. * If the first character is not a letter it is replaced by 'x'. * * @param name The candidate element name * * @return A valid element name//from w w w . j a v a 2 s . c o m */ public static String toElementName(String name) { if (name == null) return null; char[] elementAsChars = name.toCharArray(); if (!Character.isLetter(elementAsChars[0])) { elementAsChars[0] = 'x'; } else { elementAsChars[0] = Character.toLowerCase(elementAsChars[0]); } for (int i = 1; i < elementAsChars.length; i++) { if (!Character.isLetter(elementAsChars[i])) { elementAsChars[i] = '-'; } else { elementAsChars[i] = Character.toLowerCase(elementAsChars[i]); } } return new String(elementAsChars); }
From source file:Main.java
/** * Uses the value returned via the component's getText() method to set a Mnemonic key. * The character following the first '&' charcater is used as Mnemonic key, * but this only works for characters in the range a..Z * If a Mnemonic key is found, the '&' character is removed from the text. * @param textComponent/* w ww .j av a 2 s . co m*/ */ public static void setMnemonic(AbstractButton textComponent) { String label = textComponent.getText(); if (label == null || label.isEmpty() || !label.contains("&") || label.indexOf('&') == label.length() - 1) { return; } char ch = label.charAt(label.indexOf('&') + 1); if (!Character.isLetter(ch)) { return; } int ke = getKeyEvent(ch); if (ke != Integer.MIN_VALUE) { label = label.substring(0, label.indexOf('&')) + label.substring(label.indexOf('&') + 1, label.length()); textComponent.setText(label); textComponent.setMnemonic(ke); } }
From source file:Main.java
public static boolean isXMLName(String text) { if (text == null || text.length() <= 0) return false; if (!Character.isLetter(text.charAt(0))) return false; for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); if (Character.isLetter(ch)) continue; if (Character.isDigit(ch)) continue; if (ch == '.' || ch == ':' || ch == '_' || ch == '-') continue; return false; }/* ww w. j a v a 2s. com*/ return true; }
From source file:Main.java
private static final String capitalize(String str) { if (TextUtils.isEmpty(str)) { return str; }//from w ww . ja va2 s. c o m final char[] arr = str.toCharArray(); boolean capitalizeNext = true; String phrase = ""; for (final char c : arr) { if (capitalizeNext && Character.isLetter(c)) { phrase += Character.toUpperCase(c); capitalizeNext = false; continue; } else if (Character.isWhitespace(c)) { capitalizeNext = true; } phrase += c; } return phrase; }
From source file:Main.java
/** * Find the first character matching the input character in the given * string where the character has no letter preceding it. * //w ww. j a va2 s . co m * @param text the string to test for the presence of the input character * @param inputChar the test character * @param fromIndex the index position of the string to start from * @return the position of the first character matching the input character * in the given string where the character has no letter preceding it. */ public static int firstCharAt(String text, int inputChar, int fromIndex) { int result = 0; while (result >= 0) { result = text.indexOf(inputChar, fromIndex); if (result == 0) { return result; } else if (result > 0) { // Check there is a whitespace or symbol before the hit character if (Character.isLetter(text.codePointAt(result - 1))) { // The pre-increment is used in if and else branches. if (++fromIndex >= text.length()) { return -1; } else { // Test again from next candidate character // This isn't the first letter of this word result = text.indexOf(inputChar, fromIndex); } } else { return result; } } } return result; }