List of usage examples for java.lang Character isLetterOrDigit
public static boolean isLetterOrDigit(int codePoint)
From source file:net.lightbody.bmp.proxy.jetty.http.ajp.AJP13Packet.java
public String toString(int max) { StringBuffer b = new StringBuffer(); StringBuffer a = new StringBuffer(); b.append(_bytes);/*from ww w. ja v a 2 s. c o m*/ b.append('/'); b.append(_buf.length); b.append('['); b.append(_pos); b.append("]: "); switch (_buf[__HDR_SIZE]) { case __FORWARD_REQUEST: b.append("FORWARD_REQUEST{:"); break; case __SHUTDOWN: b.append("SHUTDOWN :"); break; case __SEND_BODY_CHUNK: b.append("SEND_BODY_CHUNK :"); break; case __SEND_HEADERS: b.append("SEND_HEADERS ( :"); break; case __END_RESPONSE: b.append("END_RESPONSE )}:"); break; case __GET_BODY_CHUNK: b.append("GET_BODY_CHUNK :"); break; } if (max == 0) return b.toString(); b.append("\n"); for (int i = 0; i < _bytes; i++) { int d = _buf[i] & 0xFF; if (d < 16) b.append('0'); b.append(Integer.toString(d, 16)); char c = (char) d; if (Character.isLetterOrDigit(c)) a.append(c); else a.append('.'); if (i % 32 == 31 || i == (_bytes - 1)) { b.append(" : "); b.append(a.toString()); a.setLength(0); b.append("\n"); if (max > 0 && (i + 1) >= max) break; } else b.append(","); } return b.toString(); }
From source file:pyromaniac.IO.MMFastaImporter.java
/** * _read qualities.// w ww. ja va2s . c om * * @param pyrotagBlock the pyrotag block * @param pos the pos * @return the array list * @throws SeqFormattingException the seq formatting exception */ public ArrayList<Integer> _readQualities(char[] pyrotagBlock, MutableInteger pos) throws SeqFormattingException { ArrayList<Integer> qualities = new ArrayList<Integer>(); String currInt = ""; char curr; int index = pos.value(); try { while (index < pyrotagBlock.length) { curr = pyrotagBlock[index]; if (Character.isLetterOrDigit(curr) || Character.isWhitespace(curr)) { if (Character.isLetter(curr)) { throw new SeqFormattingException("Non-numeric quality score encountered: " + curr, this.qualFile); } else if (Character.isWhitespace(curr) && currInt.length() > 0) { qualities.add(Integer.parseInt(currInt)); currInt = ""; } else if (Character.isDigit(curr)) { currInt = currInt + curr; } } else if (currInt.length() > 0) { qualities.add(Integer.parseInt(currInt)); currInt = ""; } index++; } if (currInt.length() > 0) { qualities.add(Integer.parseInt(currInt)); } return qualities; } catch (NumberFormatException nfe) { throw new SeqFormattingException("Quality score: " + currInt + " is not an integer ", this.qualFile); } }
From source file:com.netspective.sparx.util.xml.XmlSource.java
/** * Given a text string, return a string that would be suitable for an XML element name. For example, * when given Person_Address it would return person-address. The rule is to basically take every letter * or digit and return it in lowercase and every non-letter or non-digit as a dash. *//*from w w w .j av a2s . co m*/ public static String xmlTextToNodeName(String xml) { if (xml == null || xml.length() == 0) return xml; StringBuffer constant = new StringBuffer(); for (int i = 0; i < xml.length(); i++) { char ch = xml.charAt(i); constant.append(Character.isLetterOrDigit(ch) ? Character.toLowerCase(ch) : '-'); } return constant.toString(); }
From source file:org.marketcetera.util.misc.RandomStringsTest.java
@Test public void genStrId() { String sFirst = RandomStrings.genStrId(); boolean foundDifferent = false; for (int i = 0; i < STR_ITERATION_COUNT; i++) { String s = RandomStrings.genStrId(); int[] ucps = StringUtils.toUCPArray(s); assertTrue("Length is " + ucps.length, ((ucps.length >= 2) && (ucps.length <= RandomStrings.DEFAULT_LEN_STR_ID))); assertTrue("Value was " + Integer.toHexString(ucps[0]), Character.isLetter(ucps[0])); assertTrue("Value was " + Integer.toHexString(ucps[1]), Character.isDigit(ucps[1])); for (int j = 2; j < ucps.length; j++) { assertTrue("Value was " + Integer.toHexString(ucps[j]), Character.isLetterOrDigit(ucps[j])); }/*from ww w. j a v a 2s . c o m*/ if (!s.equals(sFirst)) { foundDifferent = true; } } assertTrue(foundDifferent); }
From source file:jos.parser.Parser.java
private String makeSelector(final String sig) { final StringBuilder sb = new StringBuilder(); for (int i = 0; i < sig.length(); i++) { char c = sig.charAt(i); if (c == ' ') { continue; }/* w w w . j a v a 2 s. c o m*/ if (c == ';') { break; } else if (c == ':') { sb.append(c); i++; for (; i < sig.length(); i++) { c = sig.charAt(i); if (c == ')') { for (++i; i < sig.length() && Character.isWhitespace(sig.charAt(i)); i++) { ; } for (++i; i < sig.length(); i++) { if (!Character.isLetterOrDigit(sig.charAt(i))) { break; } } break; } } } else { sb.append(c); } } return sb.toString(); }
From source file:org.plasma.text.lang3gl.java.DefaultFactory.java
protected String toConstantName(String name) { name = name.trim();/*from w ww . j av a2s. c o m*/ StringBuilder buf = new StringBuilder(); char[] array = name.toCharArray(); for (int i = 0; i < array.length; i++) { String lit = reservedJavaCharToLiteralMap.get(Character.valueOf(array[i])); if (lit != null) { buf.append(lit.toUpperCase()); continue; } if (i > 0) { if (Character.isLetter(array[i]) && Character.isUpperCase(array[i])) { if (!Character.isUpperCase(array[i - 1])) buf.append("_"); } } if (Character.isLetterOrDigit(array[i])) { buf.append(Character.toUpperCase(array[i])); } else buf.append("_"); } return buf.toString(); }
From source file:gov.nih.nci.caIMAGE.util.SafeHTMLUtil.java
public static boolean isLetterOrDigit(String input) { for (int i = 0; i < input.length(); i++) { if (!Character.isLetterOrDigit(input.charAt(i))) return false; }/* w w w. j av a 2 s . co m*/ return true; }
From source file:util.misc.TextLineBreakerStringWidth.java
/** * Finds the best position to break the word in order to fit into a maximum * width./*from www .j a v a 2 s . co m*/ * * @param word The word to break * @param maxWidth The maximum width of the word * @param mustBreak this word must break, even if no hyphenation is found * @return The position where to break the word */ private int findBreakPos(final String word, int maxWidth, boolean mustBreak) { // Reserve some space for the minus maxWidth -= mMinusWidth; // Binary search for the last fitting character int left = 0; int right = word.length() - 1; while (left < right) { int middle = (left + right + 1) / 2; // +1 to enforce taking the ceiling // Check whether this substring fits String subWord = word.substring(0, middle); int subWordWidth = getStringWidth(subWord); if (subWordWidth < maxWidth) { // It fits -> go on with the right side left = middle; } else { // It fits not -> go on with the left side right = middle - 1; } } int lastFittingPos = left; // Try to find a char that is no letter or digit // E.g. if the word is "Stadt-Land-Fluss" we try to break it in // "Stadt-" and "Land-Fluss" rather than "Stadt-La" and "nd-Fluss" for (int i = lastFittingPos - 1; i >= (lastFittingPos / 2); i--) { char ch = word.charAt(i); if (!Character.isLetterOrDigit(ch)) { // This char is no letter or digit -> break here return i + 1; } } if (useHyphenator) { int endCharacters; if (Character.isLetter(word.charAt(word.length() - 1))) { endCharacters = 2; } else { endCharacters = 3; // some words end in punctuation, so make sure at least 2 letters stay together } int startCharacters = 2; if (word.length() >= startCharacters + endCharacters) { final String hyphenated = hyphenator.hyphenate(word, endCharacters, startCharacters); if (hyphenated != null && hyphenated.length() > word.length()) { int characters = 0; int lastHyphen = 0; for (int i = 0; i < hyphenated.length(); i++) { if (hyphenated.charAt(i) != '\u00AD') { if (++characters > lastFittingPos) { return lastHyphen; } } else { lastHyphen = characters; } } } } } // We did not find a better break char -> break at the last fitting char if (mustBreak) { return lastFittingPos; } return 0; }
From source file:com.silverpeas.util.StringUtil.java
private static boolean checkEncoding(String value) { if (value != null) { char[] chars = value.toCharArray(); for (char currentChar : chars) { if (!Character.isLetterOrDigit(currentChar) && !Character.isWhitespace(currentChar) && !ArrayUtil.contains(PUNCTUATION, currentChar)) { return false; }/* w ww . jav a2 s.co m*/ } } return true; }
From source file:org.kuali.kfs.sys.batch.service.impl.BatchInputFileServiceImpl.java
/** * For this implementation, a file user identifier must consist of letters and digits * * @see org.kuali.kfs.sys.batch.service.BatchInputFileService#isFileUserIdentifierProperlyFormatted(java.lang.String) */// w ww .j ava 2s . c om @Override public boolean isFileUserIdentifierProperlyFormatted(String fileUserIdentifier) { if (ObjectUtils.isNull(fileUserIdentifier)) { return false; } for (int i = 0; i < fileUserIdentifier.length(); i++) { char c = fileUserIdentifier.charAt(i); if (!(Character.isLetterOrDigit(c))) { return false; } } return true; }