List of usage examples for java.lang Character isLetterOrDigit
public static boolean isLetterOrDigit(int codePoint)
From source file:Main.java
/** Convert a byte array to a human-readable String for debugging purposes. *//* ww w .java2s. c om*/ public static String hexDump(byte[] data) { byte byte_value; StringBuffer str = new StringBuffer(data.length * 3); str.append("Hex dump:\n"); for (int i = 0; i < data.length; i += 16) { // dump the header: 00000000: String offset = Integer.toHexString(i); // "0" left pad offset field so it is always 8 char's long. for (int offlen = offset.length(); offlen < 8; offlen++) str.append("0"); str.append(offset); str.append(":"); // dump hex version of 16 bytes per line. for (int j = 0; (j < 16) && ((i + j) < data.length); j++) { byte_value = data[i + j]; // add spaces between every 2 bytes. if ((j % 2) == 0) str.append(" "); // dump a single byte. byte high_nibble = (byte) ((byte_value & 0xf0) >>> 4); byte low_nibble = (byte) (byte_value & 0x0f); str.append(hex_table[high_nibble]); str.append(hex_table[low_nibble]); } // dump ascii version of 16 bytes str.append(" "); for (int j = 0; (j < 16) && ((i + j) < data.length); j++) { char char_value = (char) data[i + j]; // RESOLVE (really want isAscii() or isPrintable()) if (Character.isLetterOrDigit(char_value)) str.append(String.valueOf(char_value)); else str.append("."); } // new line str.append("\n"); } return (str.toString()); }
From source file:net.prasenjit.auth.validation.StrongPasswordValidator.java
/** {@inheritDoc} */ @Override/*from w ww . j av a 2 s . c o m*/ public boolean isValid(String value, ConstraintValidatorContext context) { if (!StringUtils.hasText(value)) return true; int upperCount = 0; int specialCount = 0; int lowerCount = 0; int numericCount = 0; for (int i = 0; i < value.length(); i++) { char current = value.charAt(i); if (Character.isDigit(current)) numericCount = 1; if (Character.isUpperCase(current)) upperCount = 1; if (Character.isLowerCase(current)) lowerCount = 1; if (!Character.isLetterOrDigit(current)) specialCount = 1; } return upperCount + lowerCount + numericCount + specialCount >= 2; }
From source file:ws.moor.bt.util.ByteArray.java
public String toStringWithRaw() { StringBuilder result = new StringBuilder(4 * bytes.length); for (byte b : bytes) { if (Character.isLetterOrDigit(b)) { result.append((char) b); } else {/*from w ww.j a v a 2 s . c o m*/ result.append("."); } } result.append(" (").append(Hex.encodeHex(bytes)).append(")"); return result.toString(); }
From source file:org.ardverk.gibson.EventUtils.java
private static void keywords(String value, Set<String> dst) { int length = value.length(); StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { char ch = value.charAt(i); if (!Character.isLetterOrDigit(ch)) { if (sb.length() >= MIN_KEYWORD_LENGTH) { dst.add(sb.toString());/* ww w.java 2 s . c o m*/ } sb.setLength(0); continue; } sb.append(Character.toLowerCase(ch)); } if (sb.length() >= MIN_KEYWORD_LENGTH) { dst.add(sb.toString()); } }
From source file:org.openhie.openempi.util.ValidationUtil.java
public static Boolean isNormal(String str, boolean allowUnderscore, boolean allowLeadingDigit, boolean allowLowercase, boolean allowDash) { for (int ii = 0; ii < str.length(); ii++) { char ch = str.charAt(ii); if (ch == '_') { // allow underscore in certain cases if (ii == 0 || !allowUnderscore) { // but not as the first character return false; } else { continue; }/*from ww w. j av a2s .c o m*/ } if (ch == '-') { // allow dash in certain cases if (ii == 0 || !allowDash) { // but not as the first character return false; } else { continue; } } if (!Character.isLetterOrDigit(ch)) return false; if (!allowLowercase) { if (Character.isLowerCase(ch)) return false; } if (!allowLeadingDigit && ii == 0 && Character.isDigit(ch)) // Do not allow digit as a leading character return false; if (Character.isWhitespace(ch)) return false; } return true; }
From source file:org.jboss.tools.openshift.common.core.utils.StringUtils.java
public static boolean isAlphaNumeric(String value) { for (int i = 0; i < value.length(); ++i) { final char c = value.charAt(i); if (!Character.isLetterOrDigit(c)) { return false; }// www .j a v a 2 s .c o m } return true; }
From source file:com.techcavern.wavetact.ircCommands.fun.Say.java
@Override public void onCommand(String command, User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception { String channelname = null;/*from w w w . j ava 2s . c om*/ if (!isPrivate) { channelname = prefix + channel.getName(); } else { channelname = user.getNick(); } if (args.length > 1 && args[0].startsWith("#")) { channelname = args[0]; args = ArrayUtils.remove(args, 0); } if (command.equalsIgnoreCase("act") || command.equalsIgnoreCase("do") || command.equalsIgnoreCase("a")) { Registry.messageQueue.get(network) .add("PRIVMSG " + channelname + " :\u0001ACTION " + StringUtils.join(args, " ") + "\u0001"); } else if (command.equalsIgnoreCase("prism")) { Registry.messageQueue.get(network) .add("PRIVMSG " + channelname + " :" + GeneralUtils.prism(StringUtils.join(args, " "))); } else { if (args.length > 1 && !Character.isLetterOrDigit(args[0].charAt(0)) && args[0].charAt(1) == "#".charAt(0)) { channelname = args[0]; args = ArrayUtils.remove(args, 0); } Registry.messageQueue.get(network).add("PRIVMSG " + channelname + " :" + StringUtils.join(args, " ")); } }
From source file:org.vietspider.server.handler.cms.metas.FilterContentHandler.java
public String handle(final HttpRequest request, final HttpResponse response, final HttpContext context, String... params) throws Exception { String pattern = params[1];/* ww w. j av a 2 s .com*/ int idx = pattern.indexOf('='); if (idx < 0 || idx >= pattern.length() - 1) { throw new IndexOutOfBoundsException("Incorrect parammeter"); } String filter = URLDecoder.decode(pattern.substring(idx + 1), "UTF-8"); MetaList metas = new MetaList(); metas.setAction("FILTER"); metas.setCurrentPage(Integer.parseInt(params[0])); File file = UtilFile.getFile("system/plugin/filter", NameConverter.encode(filter)); if (file.exists() && file.length() > 0) { String text = new String(RWData.getInstance().load(file), Application.CHARSET); int start = 0; while (start < text.length()) { char c = text.charAt(start); if (Character.isLetterOrDigit(c)) break; start++; } int end = text.length() - 1; while (end > 0) { char c = text.charAt(end); if (Character.isLetterOrDigit(c)) break; end--; } StringBuilder builder = new StringBuilder("\""); for (int i = start; i <= end; i++) { char c = text.charAt(i); if (c == ',') { builder.append("\" AND \""); } else if (c == '\n') { builder.append("\" OR \""); } else if (Character.isLetterOrDigit(c)) { builder.append(c); } else if (Character.isSpaceChar(c) || Character.isWhitespace(c)) { builder.append(' '); } } builder.append("\""); // System.out.println(" thay co filter "+ builder); ArticleSearchQuery query = new ArticleSearchQuery(); query.setPattern(builder.toString()); if (Application.LICENSE != Install.PERSONAL) { query.setHighlightStart("no"); ArticleIndexStorage.getInstance().search(metas, query); } } metas.setTitle(filter); metas.setUrl("?text=" + pattern.substring(idx + 1)); return write(request, response, context, metas, params); }
From source file:ml.shifu.shifu.util.ExprAnalyzer.java
private void removeNonValueChar(char[] processed) { for (int i = 0; i < processed.length; i++) { if (!Character.isLetterOrDigit(processed[i]) && processed[i] != '.' && processed[i] != '_') { processed[i] = ' '; }/*ww w . j a v a 2s .c om*/ } }
From source file:com.yahoo.semsearch.fastlinking.utils.Normalize.java
License:asdf
/** * Removes non digit or letter characters from an input string * This method accumulates chracters in a string buffer for efficiency * * @param args string to normalize/* w w w.j av a2 s. co m*/ * @return processed string */ public static String normalizeFast(String args) { final StringBuilder t = new StringBuilder(); final int length = args.length(); boolean inSpace = false; for (int i = 0; i < length; i++) { char charAt = args.charAt(i); if (Character.isLetterOrDigit(charAt)) { if (inSpace) t.append(' '); t.append(Character.toLowerCase(charAt)); inSpace = false; } else if (t.length() > 0) inSpace = true; } return t.toString(); }