List of usage examples for java.lang Character isLetter
public static boolean isLetter(int codePoint)
From source file:org.talend.repository.json.util.JSONUtil.java
public static boolean validateLabelForJSON(String label) { if (label == null) { return false; }//from www.j a va 2s .co m if (label.length() < 1) { return false; } char firstChar = label.charAt(0); // see bug 10359,support begin with "_". if (!Character.isLetter(firstChar) && !('_' == firstChar)) { return false; } // if (label.toLowerCase().startsWith("xml")) { //$NON-NLS-1$ // return false; // } char[] array = label.toCharArray(); for (char element : array) { if (Character.isSpaceChar(element) || Character.isWhitespace(element)) { return false; } } return true; }
From source file:org.artificer.common.ArtifactType.java
/** * Returns true if the given artifact type is valid. It must be alphanumeric only. * @param artifactType the artifact type * @return true if valid/*from ww w . j av a 2 s . com*/ */ public static final boolean isValid(String artifactType) { for (int i = 0; i < artifactType.length(); i++) { char c = artifactType.charAt(i); if (!(Character.isLetter(c) || Character.isDigit(c))) { return false; } } return true; }
From source file:Strings.java
/** * Returns a title-cased version of the specified word, * which involves capitalizing the first character in * the word if it is a letter./*from w ww . j a v a 2 s . co m*/ * * @param word The word to convert to title case. * @return Title cased version of specified word. */ public static String titleCase(String word) { if (word.length() < 1) return word; if (!Character.isLetter(word.charAt(0))) return word; return Character.toUpperCase(word.charAt(0)) + word.substring(1); }
From source file:edu.stanford.muse.util.SloppyDates.java
private static Triple<Integer, Integer, Integer> parseDate(String s) { // separate into month and date // "jan10", "10jan", "jan 10" "10 jan" should all work s = s.toLowerCase();//from w ww . j av a 2s . c o m s = s.trim(); StringBuilder sb = new StringBuilder(); // detect when string changes from alpha to num or vice versa and ensure a whitespace there boolean prevCharDigit = false, prevCharLetter = false; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (Character.isWhitespace(c)) { sb.append(c); prevCharDigit = prevCharLetter = false; continue; } // treat apostrophe like a space if (c == '\'') { sb.append(' '); prevCharDigit = prevCharLetter = false; continue; } if (Character.isLetter(c)) { if (prevCharDigit) sb.append(' '); sb.append(c); prevCharLetter = true; prevCharDigit = false; } else if (Character.isDigit(c)) { if (prevCharLetter) sb.append(' '); sb.append(c); prevCharDigit = true; prevCharLetter = false; } else throw new RuntimeException(); } String newS = sb.toString(); log.info("string " + s + " parsed to " + newS); StringTokenizer st = new StringTokenizer(newS); int nTokens = st.countTokens(); if (nTokens == 0 || nTokens > 3) return new Triple<Integer, Integer, Integer>(-1, -1, -1); int mm = -1, dd = -1, yy = -1; while (st.hasMoreTokens()) { String token = st.nextToken(); boolean isNumber = true; int num = -1; try { num = Integer.parseInt(token); } catch (NumberFormatException nfe) { isNumber = false; } if (isNumber && num < 0) return new Triple<Integer, Integer, Integer>(-1, -1, -1); if (isNumber) { if (dd == -1 && num > 0 && num <= 31) dd = num; else if (yy == -1) { yy = num; if (yy < 100) { yy = (yy > 12) ? (1900 + yy) : (2000 + yy); } if (yy < 1900 || yy > 2015) return new Triple<Integer, Integer, Integer>(-1, -1, -1); } else return new Triple<Integer, Integer, Integer>(-1, -1, -1); } else { int x = SloppyDates.uniquePrefixIdx(token, monthNames); if (x >= 0 && mm == -1) mm = x; else return new Triple<Integer, Integer, Integer>(-1, -1, -1); } } return new Triple<Integer, Integer, Integer>(dd, mm, yy); }
From source file:org.slc.sli.api.security.oauth.TokenGeneratorTest.java
@Test public void testIdGeneratorLargeLength() { String string = TokenGenerator.generateToken(1000); assertEquals(1000, string.length()); for (int i = 0; i < string.length(); i++) { assertTrue(Character.isDigit(string.charAt(i)) || Character.isLetter(string.charAt(i))); }/* w ww .ja v a2 s.c om*/ }
From source file:org.openhie.openempi.transformation.function.SoundexUtils.java
/** * Cleans up the input string before Soundex processing by only returning * upper case letters./*from w w w . ja v a2 s.com*/ * * @param str * The String to clean. * @return A clean String. */ static String clean(String str) { if (str == null || str.length() == 0) { return str; } int len = str.length(); char[] chars = new char[len]; int count = 0; for (int i = 0; i < len; i++) { if (Character.isLetter(str.charAt(i))) { chars[count++] = str.charAt(i); } } if (count == len) { return str.toUpperCase(java.util.Locale.ENGLISH); } return new String(chars, 0, count).toUpperCase(java.util.Locale.ENGLISH); }
From source file:edu.illinois.cs.cogcomp.wikifier.utils.spelling.SurfaceFormSpellChecker.java
public static String getCorrection(String text) { // All uppercase normalization HONG KONG => Hong Kong String noPunc = text.replaceAll("[^A-Z0-9]*", ""); if (StringUtils.isAllUpperCase(noPunc) && noPunc.length() > 3) { char[] letters = text.toLowerCase().toCharArray(); for (int i = 0; i < letters.length; i++) { if (i == 0 || !Character.isLetter(letters[i - 1]) && Character.isLetter(letters[i])) { letters[i] = Character.toUpperCase(letters[i]); }// ww w .j a va2s . com } return new String(letters); } // Spell check if (correctionCache.get(text) != null) { return String.valueOf(correctionCache.get(text)); } else { if (caching) { String correction = getGoogleCorrection(text); correctionCache.put(text, correction); return correction; } } return text; }
From source file:Main.java
/** * Checking whether a peer ID is Shadow style or not is a bit tricky. * //from ww w.j a v a 2 s . c o m * The BitTornado peer ID convention code is explained here: * http://forums.degreez.net/viewtopic.php?t=7070 * * The main thing we are interested in is the first six characters. * Although the other characters are base64 characters, there's no * guarantee that other clients which follow that style will follow * that convention (though the fact that some of these clients use * BitTornado in the core does blur the lines a bit between what is * "style" and what is just common across clients). * * So if we base it on the version number information, there's another * problem - there isn't the use of absolute delimiters (no fixed dash * character, for example). * * There are various things we can do to determine how likely the peer * ID is to be of that style, but for now, I'll keep it to a relatively * simple check. * * We'll assume that no client uses the fifth version digit, so we'll * expect a dash. We'll also assume that no client has reached version 10 * yet, so we expect the first two characters to be "letter,digit". * * We've seen some clients which don't appear to contain any version * information, so we need to allow for that. */ public static boolean isShadowStyle(String peer_id) { if (peer_id.charAt(5) != '-') { return false; } if (!Character.isLetter(peer_id.charAt(0))) { return false; } if (!(Character.isDigit(peer_id.charAt(1)) || peer_id.charAt(1) == '-')) { return false; } // Find where the version number string ends. int last_ver_num_index = 4; for (; last_ver_num_index > 0; last_ver_num_index--) { if (peer_id.charAt(last_ver_num_index) != '-') { break; } } // For each digit in the version string, check it is a valid version identifier. char c; for (int i = 1; i <= last_ver_num_index; i++) { c = peer_id.charAt(i); if (c == '-') { return false; } if (decodeAlphaNumericChar(c) == null) { return false; } } return true; }
From source file:com.iadams.sonarqube.puppet.checks.CommentContainsPatternChecker.java
private static boolean isLetterAround(String line, String pattern) { int start = StringUtils.indexOfIgnoreCase(line, pattern); int end = start + pattern.length(); boolean pre = start > 0 ? Character.isLetter(line.charAt(start - 1)) : false; boolean post = end < line.length() - 1 ? Character.isLetter(line.charAt(end)) : false; return pre || post; }
From source file:org.gbif.portal.web.controller.AlphabetBrowserController.java
/** * Sorts the alphabet so that it consists of alpha characters first, numeric chars * and then other characters such as parentheses. * /*w w w . ja v a2 s . c om*/ * @param alphabet */ public static List<Character> sortAlphabetForDisplay(List<Character> alphabet) { List<Character> listOfAlpha = new ArrayList<Character>(); List<Character> listOfNumeric = new ArrayList<Character>(); List<Character> listOfNonAlphaNumeric = new ArrayList<Character>(); for (Character theCharacter : alphabet) { if (Character.isDigit(theCharacter)) { listOfNumeric.add(theCharacter); } else if (Character.isLetter(theCharacter)) { listOfAlpha.add(theCharacter); } else { listOfNonAlphaNumeric.add(theCharacter); } } sortChars(listOfAlpha); sortChars(listOfNumeric); sortChars(listOfNonAlphaNumeric); listOfAlpha.addAll(listOfNumeric); listOfAlpha.addAll(listOfNonAlphaNumeric); return listOfAlpha; }