List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:io.fabric8.kubernetes.client.dsl.base.OperationSupport.java
protected static <T> T unmarshal(InputStream is) throws KubernetesClientException { try (BufferedInputStream bis = new BufferedInputStream(is)) { bis.mark(-1);/*from w w w . j a v a 2 s . c o m*/ int intch; do { intch = bis.read(); } while (intch > -1 && Character.isWhitespace(intch)); bis.reset(); ObjectMapper mapper = JSON_MAPPER; if (intch != '{') { mapper = YAML_MAPPER; } return mapper.readerFor(KubernetesResource.class).readValue(bis); } catch (IOException e) { throw KubernetesClientException.launderThrowable(e); } }
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; }/*from w w w. jav a 2 s . co m*/ } } return true; }
From source file:HexFormat.java
/** * Parse a hexadecimal number, skipping leading whitespace. Does not throw * an exception; if no object can be parsed, index is unchanged! Hexadecimal * numbers may be indicated with a leading character designation of '0x'. * /*from w ww. ja va 2 s. c om*/ * @param source * the string to parse * @param status * the string index to start at * @return The hexadecimal number as a Long object. * * @since 1.0 */ public Object parseObject(String source, ParsePosition status) { int start = status.getIndex(); boolean success = false; StringBuffer buffer = new StringBuffer(); char c, c2; long result; StringCharacterIterator iter = new StringCharacterIterator(source, start); for (c = iter.current(); c != CharacterIterator.DONE; c = iter.next()) { if (Character.isWhitespace(c)) { // skip whitespace continue; } break; } if (c == CharacterIterator.DONE) { return (null); } if (c == '0') { c2 = iter.next(); if (c2 == CharacterIterator.DONE) { return (null); } if (c2 == 'x') { // has a leading '0x' designation, so skip over it } else { // replace the two characters iter.previous(); iter.previous(); } } else { // skip back one character iter.previous(); } // gather valid hex digits for (c = iter.next(); c != CharacterIterator.DONE; c = iter.next()) { if (hexDigits.indexOf(c) != -1) { success = true; buffer.append(c); } else { break; } } if (!success) { // no valid hex digits return (null); } // convert hex to long if (buffer.length() > 16) { // larger than a long, error // with a buffer full of nibbles, the maximum nibbles in a // 64 bit number is 16 nibbles return (null); } // parse number try { result = Long.parseLong(buffer.toString(), 16); } catch (NumberFormatException e) { // unable to parse number return (null); } status.setIndex(iter.getIndex()); return (new Long(result)); }
From source file:com.liferay.cucumber.util.StringUtil.java
public static String trimTrailing(String s) { if (s == null) { return null; }/* w w w. ja va 2s .c o m*/ if (s.length() == 0) { return s; } int len = s.length(); int x = 0; for (int i = len - 1; i >= 0; i--) { char c = s.charAt(i); if (!Character.isWhitespace(c)) { x = i + 1; break; } } if (x == 0) { return StringPool.BLANK; } else if (x == len) { return s; } else { return s.substring(0, x); } }
From source file:com.gargoylesoftware.htmlunit.CodeStyleTest.java
/** * Verifies that no XML files have trailing whitespace. *///from www . ja v a 2 s .co m private void trailingWhitespace(final List<String> lines, final String relativePath) { for (int i = 0; i < lines.size(); i++) { final String line = lines.get(i); if (!line.isEmpty()) { final char last = line.charAt(line.length() - 1); if (Character.isWhitespace(last)) { addFailure("Trailing whitespace in " + relativePath + ", line: " + (i + 1)); } } } }
From source file:com.itude.mobile.android.util.StringUtil.java
/** * Capitalizes every word in str //w ww .j a va 2s . c o m * * @param str {@link String} * @return Capitalizes {@link String} */ public static String capitalize(String str) { if (str == null || str.length() == 0) return str; boolean capitalizeNext = true; StringBuilder result = new StringBuilder(); for (int i = 0; i < str.length(); ++i) { char ch = str.charAt(i); if (capitalizeNext) result.append(Character.toUpperCase(ch)); else result.append(ch); capitalizeNext = Character.isWhitespace(ch); } return result.toString(); }
From source file:jos.parser.Parser.java
private String makeParameters(final String sig) { int colon = sig.indexOf(':'); if (colon == -1) { return ""; }/* w ww .ja v a2 s . c o m*/ final StringBuilder sb = new StringBuilder(); StringBuilder tsb = new StringBuilder(); State state = State.SKIP_TO_TYPE; for (int i = 0; i < sig.length(); i++) { char c = sig.charAt(i); switch (state) { case SKIP_TO_TYPE: if (Character.isWhitespace(c)) { continue; } if (c == '(') { tsb = new StringBuilder(); state = State.END_OF_TYPE; } break; case END_OF_TYPE: if (c == ')') { state = State.SKIP_TO_PARAMETER; sb.append(remapType(tsb.toString())); sb.append(' '); } else { if (c != '*') { tsb.append(c); } } break; case SKIP_TO_PARAMETER: if (!Character.isWhitespace(c)) { state = State.PARAMETER; sb.append(c); } break; case PARAMETER: if (Character.isWhitespace(c)) { state = State.SKIP_TO_TYPE; sb.append(", "); } else { if (c != ';') { sb.append(c); } } break; } } log(" -> %s", sb.toString()); return sb.toString(); }
From source file:com.vsct.dt.hesperides.templating.models.Property.java
/** * Skip white space./*from w w w . j a v a2s . co m*/ * * @param str string * @param len len string * @param start position to start * * @return position of first non space char. */ private static int skipWhitespace(final String str, final int len, final int start) { int index; // After annotation, we have whitespace. boolean skipFirstWhitespace = true; for (index = start; index < len && skipFirstWhitespace; index++) { // Search blank char skipFirstWhitespace = Character.isWhitespace(str.charAt(index)); } // Must decrement to have right position return --index; }
From source file:Unsigned.java
/** * Parse a binary number into a Number object. If up to 8 bits are parsed, * returns a Byte. If more than 8 and up to 16 bits are parsed, return a * Short. If more than 16 and up to 32 bits are parsed, return an Integer. * If more than 32 and up to 64 bits are parsed, return a Long. * // w ww.j av a 2s . co m * @param text * a binary number * @param parsePosition * position to start parsing from * @return return an integer form of Number object if parse is successful; * <CODE>null</CODE> otherwise * * @since 1.0 */ public Number parse(String text, ParsePosition parsePosition) { boolean skipWhitespace = true; int startIndex, bits; // remove whitespace StringCharacterIterator iter = new StringCharacterIterator(text, parsePosition.getIndex()); for (char c = iter.current(); c != CharacterIterator.DONE; c = iter.next()) { if (skipWhitespace && Character.isWhitespace(c)) { // skip whitespace continue; } } parsePosition.setIndex(iter.getIndex()); startIndex = parsePosition.getIndex(); Number result = (Number) parseObject(text, parsePosition); if (result == null) { return (result); } bits = parsePosition.getIndex() - startIndex; if (bits <= 8) { result = new Byte(result.byteValue()); } else if (bits <= 16) { result = new Short(result.shortValue()); } else if (bits <= 32) { result = new Integer(result.intValue()); } else if (bits <= 64) { result = new Long(result.longValue()); } return (result); }
From source file:importer.filters.PlayFilter.java
/** * Get the first word of a string/*from w w w . jav a 2 s . co m*/ * @param text the text to get the first word of * @param stripPunctuation strip punctuation * @return the first word */ String firstWord(String text, boolean stripPunctuation) { String word1 = text.trim(); int pos = 0; for (int i = 0; i < word1.length(); i++) { char token = word1.charAt(i); if (token == speakerEnd) { pos = i + 1; break; } else if (Character.isWhitespace(token)) { pos = i; break; } } if (pos > 0) word1 = word1.substring(0, pos); if (stripPunctuation) return strip(word1); else return word1; }