List of usage examples for java.lang Character isDigit
public static boolean isDigit(int codePoint)
From source file:ai.susi.mind.SusiPhrase.java
public static String extractMeat(String expression) { if (isRegularExpression(expression)) return ""; // the meatsize of a regular expression is zero StringBuffer sb = new StringBuffer(); for (int i = 0; i < expression.length(); i++) { char c = expression.charAt(i); if (Character.isLetter(c) || Character.isDigit(c) || c == ' ') sb.append(c);// ww w .jav a 2 s.co m } return sb.toString(); }
From source file:edu.chalmers.dat076.moviefinder.service.TitleParser.java
public int checkForYear(CharSequence cs) { int year = 0; if (cs.length() == 4) { for (int i = 0; i < 4; i++) { if (Character.isDigit(cs.charAt(i))) { year = year * 10;/*w w w.j ava 2 s. c o m*/ year = year + Character.getNumericValue(cs.charAt(i)); } else { return -1; } } } return year; }
From source file:net.jimj.automaton.commands.QuoteCommand.java
protected boolean isMetaWord(String word) { if (StringUtils.isBlank(word)) { return false; }//from w w w . j av a 2 s . co m return !(Character.isAlphabetic(word.codePointAt(0)) || Character.isDigit(word.codePointAt(0))); }
From source file:com.microsoft.tfs.util.FileHelpers.java
/** * Check if the specified name is in the list of reserved NTFS names. * * @param name/* w ww. j a v a2 s. co m*/ * the file name to check * @return true if name is a reserved NTFS file name */ public static boolean isReservedName(final String name) { /* * This method gets called *often* and is written for speed, even to the * point of being fragile with respect to changes to the reservedNames * and reservedNamesLength3 lists. Changes to the list of reserved names * will likely require code changes here. */ // LPT1 -> LPT9, COM1 -> COM9 are reserved names. // LPT0 and COM0 are NOT reserved names. if (name.length() == 4 && Character.isDigit(name.charAt(3)) && name.charAt(3) != '0') { final String firstThree = name.substring(0, 3); if (firstThree.equalsIgnoreCase("LPT") || firstThree.equalsIgnoreCase("COM")) //$NON-NLS-1$ //$NON-NLS-2$ { return true; } } // All of the strings in reservedNamesLength3 are length 3. if (name.length() == 3) { for (int i = 0; i < RESERVED_NAMES_LENGTH3.length; i++) { if (name.equalsIgnoreCase(RESERVED_NAMES_LENGTH3[i])) { return true; } } } return false; }
From source file:com.portmods.handlers.crackers.dictionary.Wordlist.java
@Override public void run() { try {/* w ww . ja v a 2 s . co m*/ System.out.println("Loading Dictionary"); InputStream fileStream = null; if (config.getUseCustomDictionary()) { try { fileStream = new FileInputStream(config.getCustomDictionary()); } catch (Exception e) { JOptionPane.showMessageDialog(null, e, "Error with Dictonary File.", JOptionPane.ERROR_MESSAGE); System.exit(1); } } else { fileStream = Main.class.getResourceAsStream("/com/portmods/files/words.txt"); } BufferedReader reader = new BufferedReader(new InputStreamReader(fileStream, "UTF-8")); /* declaring storage list */ wordlist = new ArrayList<String>(); String text = ""; String line = reader.readLine(); while (line != null) //wait for ever { text = line; line = reader.readLine(); if (text.length() < 9 && text.length() > 2) { wordlist.add(text); } } } catch (UnsupportedEncodingException e) { System.out.println("Error Loading Dictionary"); } catch (IOException e) { System.out.println("Error Loading Dictionary"); } System.out.println("Finished Loading Dictionary"); System.out.println("Rule 1 : Do nothing to word"); for (String s : wordlist) { String hash = UnixCrypt.crypt(s, "aa"); for (User u : pw.getUsers()) { if (u.getHash().equals(hash)) { System.out.println("Found password " + s + " for user " + u.getUserName()); fp.addPassword(u.getUserName(), s); } } } System.out.println("Rule 2 : Toggle case of every character"); /* Chaning word characters one at time lowerecase to Uppercase and vice Veser. */ for (String s : wordlist) { for (int i = 0; i < s.length(); i++) { char C = s.charAt(i); //take character from the word StringBuilder sbuilder = new StringBuilder(s); //word we want to inject the character into if (Character.isUpperCase(C)) { sbuilder.setCharAt(i, Character.toLowerCase(C)); //changing the character to lowercase } else if (Character.isLowerCase(C)) { sbuilder.setCharAt(i, Character.toUpperCase(C)); // change to uppercase } String hash = UnixCrypt.crypt(sbuilder.toString(), "aa"); for (User u : pw.getUsers()) { if (u.getHash().equals(hash)) { System.out .println("Found password " + sbuilder.toString() + " for user " + u.getUserName()); fp.addPassword(u.getUserName(), sbuilder.toString()); } } } } System.out.println("Rule 3 : adding random numbers and leters into the word"); /* generating number and adding to the words*/ for (String s : wordlist) { for (int i = 0; i < 10; i++) { StringBuilder sb = new StringBuilder(s); sb.append(i); //add an integer to each word. String out = sb.toString(); if (out.length() <= 8) { String hash = UnixCrypt.crypt(out, "aa"); for (User u : pw.getUsers()) { if (u.getHash().equals(hash)) { System.out.println("Found password " + sb.toString() + " for user " + u.getUserName()); fp.addPassword(u.getUserName(), sb.toString()); } } } } } System.out.println("Rule 4: Toggle one charater at a time and replace a number"); /* trying to toggle one charater at a time and replace a number*/ for (String s : wordlist) { for (int j = 0; j < s.length(); j++) { for (int i = 0; i < 10; i++) { char C = s.charAt(j); //take character from the word StringBuilder sbuilder = new StringBuilder(s); //word we want to inject the character into if (Character.isAlphabetic(C)) { sbuilder.deleteCharAt(j); //remove character sbuilder.insert(j, i); // add digit String hash = UnixCrypt.crypt(sbuilder.toString(), "aa"); for (User u : pw.getUsers()) { if (u.getHash().equals(hash)) { System.out.println( "Found password " + sbuilder.toString() + " for user " + u.getUserName()); fp.addPassword(u.getUserName(), sbuilder.toString()); } } } } for (int x = 65; x < 123; x++) { char C1 = (char) x; char C = s.charAt(j); //take character from the word StringBuilder sbuilder = new StringBuilder(s); //word we want to inject the character into if (Character.isDigit(C)) { sbuilder.setCharAt(j, C1); String hash = UnixCrypt.crypt(sbuilder.toString(), "aa"); for (User u : pw.getUsers()) { if (u.getHash().equals(hash)) { System.out.println( "Found password " + sbuilder.toString() + " for user " + u.getUserName()); fp.addPassword(u.getUserName(), sbuilder.toString()); } } } } } } System.out.println("Rule 5 : Adding random letters and numbers to the end"); /* adding ascii values to a text string */ for (String s : wordlist) { int x = 1; StringBuilder sb = new StringBuilder(s); for (int i = 33; i < 123; i++) { char L1 = (char) i; String out = sb.toString(); String out1 = out + L1; if (out1.length() > 8) { break; } else { String hash = UnixCrypt.crypt(out1, "aa"); for (User u : pw.getUsers()) { if (u.getHash().equals(hash)) { System.out.println("Found password " + out1 + " for user " + u.getUserName()); fp.addPassword(u.getUserName(), out1); } } } for (int j = 33; j < 123; j++) { char L2 = (char) j; String out2 = out + L1 + L2; if (out2.length() > 8) { break; } else { String hash = UnixCrypt.crypt(out2, "aa"); for (User u : pw.getUsers()) { if (u.getHash().equals(hash)) { System.out.println("Found password " + out2 + " for user " + u.getUserName()); fp.addPassword(u.getUserName(), out2); } } } for (int k = 33; k < 123; k++) { char L3 = (char) k; String out3 = out + L1 + L2 + L3; if (out3.length() > 8) { break; } else { String hash = UnixCrypt.crypt(out3, "aa"); for (User u : pw.getUsers()) { if (u.getHash().equals(hash)) { System.out.println("Found password " + out3 + " for user " + u.getUserName()); fp.addPassword(u.getUserName(), out3); } } } for (int l = 33; l < 123; l++) { char L4 = (char) l; String out4 = out + L1 + L2 + L3 + L4; if (out4.length() > 8) { break; } else { String hash = UnixCrypt.crypt(out4, "aa"); for (User u : pw.getUsers()) { if (u.getHash().equals(hash)) { System.out .println("Found password " + out4 + " for user " + u.getUserName()); fp.addPassword(u.getUserName(), out4); } } } } } } if (out.length() < 8) { } else { System.out.println(out); break; } } } config.setDicModeFin(true); }
From source file:com.squarespace.template.GeneralUtils.java
/** * Indicates if the string consists of all digits. *///w w w. j av a2 s . co m private static boolean allDigits(String str) { for (int i = 0, len = str.length(); i < len; i++) { if (!Character.isDigit(str.charAt(i))) { return false; } } return true; }
From source file:com.legstar.pli2cob.util.CobolNameResolver.java
/** * Determines if this is a valid first character in a cobol word. * @param c the character to check// w w w . j ava 2 s. c o m * @return true if this is a valid first character */ private boolean isValidFirst(final char c) { if (c == '-' || Character.isDigit(c)) { return false; } return true; }
From source file:io.github.seleniumquery.utils.SelectorUtils.java
/** * Escapes a CSS identifier./* ww w .ja v a 2s . c om*/ * * Future references for CSS escaping: * http://mathiasbynens.be/notes/css-escapes * http://mothereff.in/css-escapes * https://github.com/mathiasbynens/mothereff.in/blob/master/css-escapes/eff.js * * @param unescapedSelector The CSS selector to escape * @return The CSS selector escaped */ public static String escapeSelector(String unescapedSelector) { String escapedSelector = unescapedSelector; if (Character.isDigit(unescapedSelector.charAt(0))) { escapedSelector = "\\\\3" + unescapedSelector.charAt(0) + " " + escapedSelector.substring(1); } escapedSelector = escapedSelector.replace(":", "\\:"); if (escapedSelector.charAt(0) == '-') { if (escapedSelector.length() == 1 || (escapedSelector.length() > 1 && (Character.isDigit(escapedSelector.charAt(1)) || escapedSelector.charAt(1) == '-'))) { escapedSelector = "\\" + escapedSelector; } } return escapedSelector; }
From source file:org.carewebframework.common.StrUtil.java
/** * Extracts an integer portion at the beginning of a string. Parsing stops when a non-digit * character or the end of the string is encountered. * /* w ww . j a va 2 s.c o m*/ * @param value String value to parse * @return The integer prefix (as a string) of the parsed string. */ public static String extractIntPrefix(String value) { int pos = 0; if (StringUtils.isEmpty(value)) { return ""; } if (value.startsWith("+") || value.startsWith("-")) { pos++; } while (pos < value.length()) { if (Character.isDigit(value.charAt(pos))) { pos++; } else { break; } } return value.substring(0, pos); }
From source file:edu.cwru.apo.Directory.java
private String removeNonDigits(String phoneNumber) { StringBuilder ans = new StringBuilder(); char currentChar; for (int i = 0; i < phoneNumber.length(); ++i) { currentChar = phoneNumber.charAt(i); if (Character.isDigit(currentChar)) { ans.append(currentChar);/* w w w . jav a 2 s .c o m*/ } } return ans.toString(); }