List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:Main.java
/** * Remove all duplicate whitespace characters and line terminators are replaced with a single space. * * @param s a not null String/*from ww w . j a v a 2 s .c om*/ * @return a string with unique whitespace. * @since 1.5.7 */ public static String removeDuplicateWhitespace(String s) { StringBuilder result = new StringBuilder(); int length = s.length(); boolean isPreviousWhiteSpace = false; for (int i = 0; i < length; i++) { char c = s.charAt(i); boolean thisCharWhiteSpace = Character.isWhitespace(c); if (!(isPreviousWhiteSpace && thisCharWhiteSpace)) { result.append(c); } isPreviousWhiteSpace = thisCharWhiteSpace; } return result.toString(); }
From source file:Main.java
public static boolean containsOnlyWhiteSpaces(final Collection<String> values) { if (values == null) { return true; }//from w w w . j av a 2 s . c o m for (final String str : values) { if (TextUtils.isEmpty(str)) { continue; } final int length = str.length(); for (int i = 0; i < length; i = str.offsetByCodePoints(i, 1)) { if (!Character.isWhitespace(str.codePointAt(i))) { return false; } } } return true; }
From source file:Main.java
/** * @since 4.4/*from w w w . j a v a 2s. com*/ */ public static boolean containsBlanks(final CharSequence s) { if (s == null) { return false; } for (int i = 0; i < s.length(); i++) { if (Character.isWhitespace(s.charAt(i))) { return true; } } return false; }
From source file:Main.java
public static byte[] fromHex(String s) { if (s != null) { try {/*from www . j a v a2s .co m*/ StringBuilder sb = new StringBuilder(s.length()); for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if (!Character.isWhitespace(ch)) { sb.append(ch); } } s = sb.toString(); int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { int hi = (Character.digit(s.charAt(i), 16) << 4); int low = Character.digit(s.charAt(i + 1), 16); if (hi >= 256 || low < 0 || low >= 16) { return null; } data[i / 2] = (byte) (hi | low); } return data; } catch (Exception ignored) { } } return null; }
From source file:codes.thischwa.c5c.util.StringUtils.java
public static final boolean isNullOrEmptyOrBlank(final String str) { if (_isNullOrEmpty(str)) return true; for (int i = 0; i < str.length(); i++) { if (!Character.isWhitespace(str.charAt(i))) return false; }/*from w ww . j a v a 2s .c o m*/ return true; }
From source file:Main.java
public static boolean isEmptyOrWhitespaceOnly(String str) { if (TextUtils.isEmpty(str)) { return true; }//from w w w . j a v a2 s . c o m for (int i = 0; i < str.length(); i++) { if (!Character.isWhitespace(str.charAt(i))) { return false; } } return true; }
From source file:Main.java
/** * Returns true if the parameter is null or contains only whitespace *///from ww w . j ava2 s . c o m public static boolean isBlank(final CharSequence s) { if (s == null) { return true; } for (int i = 0; i < s.length(); i++) { if (!Character.isWhitespace(s.charAt(i))) { return false; } } return true; }
From source file:Main.java
/** * <p>/*from w ww. j a v a2 s . c o m*/ * Strip any of a supplied String from the end of a String. * </p> * <p/> * <p> * If the strip String is <code>null</code>, whitespace is stripped. * </p> * * @param str the String to remove characters from * @param strip the String to remove * @return the stripped String */ public static String stripEnd(String str, String strip) { if (str == null) { return null; } int end = str.length(); if (strip == null) { while ((end != 0) && Character.isWhitespace(str.charAt(end - 1))) { end--; } } else { while ((end != 0) && (strip.indexOf(str.charAt(end - 1)) != -1)) { end--; } } return str.substring(0, end); }
From source file:com.google.flightmap.parsing.util.StringUtils.java
/** * Returns mixed-case version of {@code text}. * <p>//from ww w . j a v a2s. c o m * The first letter of each word is capitalized, the rest are lower case. * Words are delimited by spaces and special characters (except single-quote). * "REID-HILLVIEW" becomes "Reid-Hillview". * * @return mixed-case version of {@code text} with each word capitalized. */ public static String capitalize(final String text) { final StringBuilder sb = new StringBuilder(WordUtils.capitalize(text.toLowerCase())); boolean makeNextLetterUpper = false; for (int i = 0; i < sb.length(); ++i) { final char cur = sb.charAt(i); if (Character.isWhitespace(cur)) { continue; // Skip whitespace } else if (Character.isLetterOrDigit(cur)) { if (makeNextLetterUpper) { sb.setCharAt(i, Character.toUpperCase(cur)); makeNextLetterUpper = false; } else { continue; // Skip character if no change is neded } } else { // Not whitespace, letter or digit: we assume punctuation. makeNextLetterUpper = cur != '\''; // Ignore single quote (John'S, Susie'S, ...) } } return sb.toString(); }
From source file:Main.java
/** * <p>//from w w w . j av a 2 s. c o m * Strip any of a supplied String from the start of a String. * </p> * <p/> * <p> * If the strip String is <code>null</code>, whitespace is stripped. * </p> * * @param str the String to remove characters from * @param strip the String to remove * @return the stripped String */ public static String stripStart(String str, String strip) { if (str == null) { return null; } int start = 0; int sz = str.length(); if (strip == null) { while ((start != sz) && Character.isWhitespace(str.charAt(start))) { start++; } } else { while ((start != sz) && (strip.indexOf(str.charAt(start)) != -1)) { start++; } } return str.substring(start); }