List of usage examples for java.lang Character isLetter
public static boolean isLetter(int codePoint)
From source file:org.apache.archiva.redback.policy.rules.AlphaPasswordRule.java
private int countAlphaCharacters(String password) { int count = 0; if (StringUtils.isEmpty(password)) { return count; }//from w w w. j ava 2s . c o m /* TODO: Eventually upgrade to the JDK 1.5 Technique * * // Doing this via iteration of code points to take in account localized passwords. * for ( int i = 0; i < password.length(); i++ ) * { * int codepoint = password.codePointAt( i ); * if ( Character.isLetter( codepoint ) ) * { * count++; * } * } */ // JDK 1.4 Technique - NOT LOCALIZED. for (int i = 0; i < password.length(); i++) { char c = password.charAt(i); if (Character.isLetter(c)) { count++; } } return count; }
From source file:com.gargoylesoftware.htmlunit.source.JQuery173Extractor.java
/** * Generates the java code of the test cases. * @param dir the directory which holds the expectations * @throws IOException if an error occurs. *///ww w .jav a2 s .c o m public static void generateTestCases(final File dir) throws IOException { final Browser[] browsers = Browser.values(); // main browsers regardless of version e.g. FF final List<String> mainNames = new ArrayList<String>(); for (final Browser b : browsers) { final String name = b.name(); if (!"NONE".equals(name) && Character.isLetter(name.charAt(name.length() - 1))) { mainNames.add(name); } } final Map<String, List<String>> browserVersions = new HashMap<String, List<String>>(); for (final Browser b : browsers) { final String name = b.name(); for (final String mainName : mainNames) { if (!name.equals(mainName) && mainName.startsWith(name)) { List<String> list = browserVersions.get(mainName); if (list == null) { list = new ArrayList<String>(); browserVersions.put(mainName, list); } list.add(name); } } } final Map<String, List<String>> browserExpectations = new HashMap<String, List<String>>(); for (final File file : dir.listFiles()) { if (file.isFile() && file.getName().endsWith(".txt")) { for (final Browser b : browsers) { if (file.getName().equals(b.name().replace('_', '.') + ".txt")) { browserExpectations.put(b.name(), FileUtils.readLines(file)); } } } } int testNumber = 0; while (true) { final Map<String, String> testExpectation = new HashMap<String, String>(); for (final Browser b : browsers) { final String name = b.name(); if (browserExpectations.containsKey(name) && testNumber < browserExpectations.get(name).size()) { String expectation = browserExpectations.get(name).get(testNumber); if (expectation != null) { expectation = expectation.substring(expectation.indexOf('.') + 1); if (expectation.charAt(0) == ' ') { expectation = expectation.substring(1); } testExpectation.put(name, expectation.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\\"", "\\\\\"")); } } } if (testExpectation.isEmpty()) { break; } System.out.println(" /**"); System.out.println(" * @throws Exception if an error occurs"); System.out.println(" */"); System.out.println(" @Test"); System.out.print(" @Alerts("); boolean allSame = true; String lastExpect = null; for (final String e : testExpectation.values()) { if (lastExpect == null) { lastExpect = e; } else if (!e.equals(lastExpect)) { allSame = false; break; } } if (allSame) { final String first = testExpectation.keySet().iterator().next(); String expectation = testExpectation.get(first); if (expectation.length() > 100) { expectation = expectation.substring(0, 50) + "\"\n + \"" + expectation.substring(50); } System.out.print("\"" + expectation + '"'); } else { boolean first = true; boolean longLine = false; for (final String browser : testExpectation.keySet()) { if (!first) { System.out.print(","); if (longLine) { System.out.print("\n "); } else { System.out.print(' '); } } String expectation = testExpectation.get(browser); if (expectation.length() > 40) { expectation = expectation.substring(0, 40) + "\"\n + \"" + expectation.substring(40); longLine = true; } else { longLine = false; } System.out.print(browser + " = \"" + expectation + '"'); if (first) { first = false; } } } System.out.println(")"); if (browsers.length - 1 > testExpectation.size()) { //there are @NYI System.out.print(" @NotYetImplemented({ "); boolean first = true; for (final Browser b : browsers) { final String name = b.name(); if (!mainNames.contains(name) && !"NONE".equals(name) && !testExpectation.containsKey(name)) { if (!first) { System.out.print(", "); } System.out.print(name); if (first) { first = false; } } } System.out.println(" })"); } System.out.println(" public void test_" + (testNumber + 1) + "() throws Exception {"); System.out.println(" runTest(" + (testNumber + 1) + ");"); System.out.println(" }"); System.out.println(); testNumber++; } }
From source file:au.org.ala.bhl.WordLists.java
public static List<String> sanitize(String text) { String[] tokens = text.split("\\s"); List<String> words = new ArrayList<String>(); for (String token : tokens) { if (!StringUtils.isEmpty(token)) { StringBuilder b = new StringBuilder(); for (int i = 0; i < token.length(); ++i) { char ch = token.charAt(i); if (".,;:{}[]()&$!@#`~;\"'".indexOf(ch) >= 0) { continue; }/*from w w w . j ava 2s.c o m*/ if (Character.isWhitespace(ch)) { continue; } if ("-".indexOf(ch) >= 0) { if (b.length() > 0) { words.add(b.toString()); } b = new StringBuilder(); continue; } if (!Character.isLetter(ch)) { // Throw away this token because it contains some other non-letter (numbers etc) b = new StringBuilder(); break; } b.append(ch); } // Only consider words greater than one letter. if (b.length() > 1) { words.add(b.toString()); } } } return words; }
From source file:org.sonar.cxx.checks.CommentContainsPatternChecker.java
private 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:br.com.renatoccosta.regexrenamer.element.FilterElement.java
@Override public String convert(String src) { StringBuilder sb = new StringBuilder(); char[] caracs = src.toCharArray(); switch (mode) { case LETTERS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (!Character.isLetter(c)) { sb.append(c);//from ww w . j av a 2 s . c om } } return sb.toString(); case NUMBERS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (!Character.isDigit(c)) { sb.append(c); } } return sb.toString(); case SYMBOLS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (Character.isLetterOrDigit(c) || Character.isSpaceChar(c)) { sb.append(c); } } return sb.toString(); case WHITE_SPACE: return StringUtils.deleteWhitespace(src); } return src; }
From source file:bhl.pages.handler.PagesDocumentsHandler.java
String concoctTitle(String docid) { StringBuilder className = new StringBuilder(); StringBuilder yearName = new StringBuilder(); StringBuilder author = new StringBuilder(); int state = 0; for (int i = 0; i < docid.length(); i++) { char token = docid.charAt(i); switch (state) { case 0: // looking for document classname if (Character.isDigit(token)) { yearName.append(token);//from ww w .j a v a 2 s . c om state = 1; } else className.append(token); break; case 1: // looking for year if (Character.isDigit(token) && yearName.length() < 4) yearName.append(token); else state = 2; break; case 2: // looking for author if (Character.isLetter(token)) author.append(token); break; } } StringBuilder total = new StringBuilder(); total.append(author); total.append(" "); if (className.length() > 0 && className.charAt(className.length() - 1) == 's') className.setLength(className.length() - 1); total.append(className); total.append(" "); total.append(yearName); return total.toString(); }
From source file:org.talend.dataprep.api.dataset.row.RowMetadataUtils.java
private static String toAvroFieldName(ColumnMetadata column) { final char[] chars = column.getName().toCharArray(); final StringBuilder columnName = new StringBuilder(); for (int i = 0; i < chars.length; i++) { final char currentChar = chars[i]; if (i == 0) { if (!Character.isLetter(currentChar)) { columnName.append(DATAPREP_FIELD_PREFIX); }//from www.j av a2 s. c o m columnName.append(currentChar); } if (i > 0) { if (!Character.isJavaIdentifierPart(currentChar)) { columnName.append('_'); } else { columnName.append(currentChar); } } } return columnName.toString(); }
From source file:URLEncoder.java
private static void toHex(StringBuffer buffer, byte[] b) { for (int i = 0; i < b.length; i++) { buffer.append('%'); char ch = Character.forDigit((b[i] >> 4) & 0xF, 16); if (Character.isLetter(ch)) { ch -= 32;// ww w.ja v a 2s . c o m } buffer.append(ch); ch = Character.forDigit(b[i] & 0xF, 16); if (Character.isLetter(ch)) { ch -= 32; } buffer.append(ch); } }
From source file:edu.ku.brc.af.ui.forms.validation.FormattedDateValidator.java
protected char discoverSeparator() { // Here we need to discover what the Date format's separator character is // I could figure out a call in java to get it. String formatStr = scrDateFormat.getSimpleDateFormat().toPattern(); int i = 0;//from ww w . j a v a2s. com while (i < formatStr.length()) { if (!Character.isLetter(formatStr.charAt(i))) { return formatStr.charAt(i); } i++; } return Character.valueOf('/'); }
From source file:Main.java
/** Crea una URI a partir de un nombre de fichero local o una URL. * @param file Nombre del fichero local o URL * @return URI (<code>file://</code>) del fichero local o URL * @throws URISyntaxException Si no se puede crear una URI soportada a partir de la cadena de entrada */ public static URI createURI(final String file) throws URISyntaxException { if (file == null || file.isEmpty()) { throw new IllegalArgumentException("No se puede crear una URI a partir de un nulo"); //$NON-NLS-1$ }/*w ww. j a v a 2s .co m*/ String filename = file.trim(); if (filename.isEmpty()) { throw new IllegalArgumentException("La URI no puede ser una cadena vacia"); //$NON-NLS-1$ } // Cambiamos los caracteres Windows filename = filename.replace('\\', '/'); // Realizamos los cambios necesarios para proteger los caracteres no // seguros // de la URL filename = filename.replace(" ", "%20") //$NON-NLS-1$ //$NON-NLS-2$ .replace("<", "%3C") //$NON-NLS-1$ //$NON-NLS-2$ .replace(">", "%3E") //$NON-NLS-1$ //$NON-NLS-2$ .replace("\"", "%22") //$NON-NLS-1$ //$NON-NLS-2$ .replace("{", "%7B") //$NON-NLS-1$ //$NON-NLS-2$ .replace("}", "%7D") //$NON-NLS-1$ //$NON-NLS-2$ .replace("|", "%7C") //$NON-NLS-1$ //$NON-NLS-2$ .replace("^", "%5E") //$NON-NLS-1$ //$NON-NLS-2$ .replace("[", "%5B") //$NON-NLS-1$ //$NON-NLS-2$ .replace("]", "%5D") //$NON-NLS-1$ //$NON-NLS-2$ .replace("`", "%60"); //$NON-NLS-1$ //$NON-NLS-2$ final URI uri = new URI(filename); // Comprobamos si es un esquema soportado final String scheme = uri.getScheme(); for (final String element : SUPPORTED_URI_SCHEMES) { if (element.equals(scheme)) { return uri; } } // Si el esquema es nulo, aun puede ser un nombre de fichero valido // El caracter '#' debe protegerse en rutas locales if (scheme == null) { filename = filename.replace("#", "%23"); //$NON-NLS-1$ //$NON-NLS-2$ return createURI("file://" + filename); //$NON-NLS-1$ } // Miramos si el esquema es una letra, en cuyo caso seguro que es una // unidad de Windows ("C:", "D:", etc.), y le anado el file:// // El caracter '#' debe protegerse en rutas locales if (scheme.length() == 1 && Character.isLetter((char) scheme.getBytes()[0])) { filename = filename.replace("#", "%23"); //$NON-NLS-1$ //$NON-NLS-2$ return createURI("file://" + filename); //$NON-NLS-1$ } throw new URISyntaxException(filename, "Tipo de URI no soportado"); //$NON-NLS-1$ }