List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:Main.java
/** * <p>/* w w w. j a v a 2 s .co m*/ * Capitalise all the words in a String. * </p> * <p/> * <p> * Uses {@link Character#isWhitespace(char)} as a separator between words. * </p> * <p/> * <p> * <code>null</code> will return <code>null</code>. * </p> * * @param str the String to capitalise * @return capitalised String */ public static String capitaliseAllWords(String str) { if (str == null) { return null; } int sz = str.length(); StringBuilder buffer = new StringBuilder(sz); boolean space = true; for (int i = 0; i < sz; i++) { char ch = str.charAt(i); if (Character.isWhitespace(ch)) { buffer.append(ch); space = true; } else if (space) { buffer.append(Character.toTitleCase(ch)); space = false; } else { buffer.append(ch); } } return buffer.toString(); }
From source file:Main.java
/** * <p>//w w w . ja v a 2s .c om * Uncapitalise all the words in a string. * </p> * <p/> * <p> * Uses {@link Character#isWhitespace(char)} as a separator between words. * </p> * <p/> * <p> * <code>null</code> will return <code>null</code>. * </p> * * @param str the string to uncapitalise * @return uncapitalised string */ public static String uncapitaliseAllWords(String str) { if (str == null) { return null; } int sz = str.length(); StringBuilder buffer = new StringBuilder(sz); boolean space = true; for (int i = 0; i < sz; i++) { char ch = str.charAt(i); if (Character.isWhitespace(ch)) { buffer.append(ch); space = true; } else if (space) { buffer.append(Character.toLowerCase(ch)); space = false; } else { buffer.append(ch); } } return buffer.toString(); }
From source file:Main.java
/** * <p>//ww w .ja v a 2 s. com * Checks if a String is whitespace, empty ("") or null. * </p> * <p/> * * <pre> * StringUtils.isBlank(null) = true * StringUtils.isBlank("") = true * StringUtils.isBlank(" ") = true * StringUtils.isBlank("bob") = false * StringUtils.isBlank(" bob ") = false * </pre> * * @param str the String to check, may be null * @return <code>true</code> if the String is null, empty or whitespace * @since 1.5.2 */ public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(str.charAt(i))) { return false; } } return true; }
From source file:com.twosigma.beaker.shared.module.util.ControlCharacterUtils.java
public static boolean containsControlCharacters(final String value) { if (StringUtils.isNotEmpty(value)) { for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); if (!Character.isWhitespace(c) && Character.isISOControl(c)) { return true; }/*from w ww.j a v a2 s . c o m*/ } } return false; }
From source file:Main.java
/** * collapse multi-whitespace into one whitespace in the original text. * Support unicode white space with isWhitespace and isSpaceChar method in * {@link #Character}/*from w ww . j av a 2 s .com*/ * * @param oriText * @return */ public static String collapseWhiteSpace(StringBuffer oriText) { if (oriText == null) { return null; } int oriLen = oriText.length(); StringBuffer newText = new StringBuffer(oriLen); int wsCount = 0; char lastWs = ' '; for (int i = 0; i <= oriLen; i++) { if (i == oriLen) { if (wsCount == 1) { newText.append(lastWs); } if (wsCount > 1) { newText.append(' '); } wsCount = 0; break; } char c = oriText.charAt(i); if (Character.isWhitespace(c) || Character.isSpaceChar(c)) { wsCount++; lastWs = c; } else { if (wsCount == 1) { newText.append(lastWs); } if (wsCount > 1) { newText.append(' '); } wsCount = 0; newText.append(c); } } String relt = newText.toString(); return relt; }
From source file:Main.java
/** * <p>Checks if a CharSequence is whitespace, empty ("") or null.</p> * <p>//ww w .j av a 2s . c o m * <pre> * StringUtils.isBlank(null) = true * StringUtils.isBlank("") = true * StringUtils.isBlank(" ") = true * StringUtils.isBlank("bob") = false * StringUtils.isBlank(" bob ") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if the CharSequence is null, empty or whitespace * @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence) */ public static boolean isBlank(final CharSequence cs) { int strLen; if (cs == null || (strLen = cs.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if (Character.isWhitespace(cs.charAt(i)) == false) { return false; } } return true; }
From source file:Main.java
/** * Check whether the given CharSequence has actual text. * More specifically, returns {@code true} if the string not {@code null}, * its length is greater than 0, and it contains at least one non-whitespace character. * <p><pre class="code">/*from w ww .j a va2 s . com*/ * StringUtils.hasText(null) = false * StringUtils.hasText("") = false * StringUtils.hasText(" ") = false * StringUtils.hasText("12345") = true * StringUtils.hasText(" 12345 ") = true * </pre> * @param str the CharSequence to check (may be {@code null}) * @return {@code true} if the CharSequence is not {@code null}, * its length is greater than 0, and it does not contain whitespace only * @see Character#isWhitespace */ public static boolean hasText(CharSequence str) { if (!hasLength(str)) { return false; } int strLen = str.length(); for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(str.charAt(i))) { return true; } } return false; }
From source file:com.qwazr.utils.StringUtils.java
public static final String replaceConsecutiveSpaces(String source, String replace) { if (isEmpty(source)) return source; StringBuilder target = new StringBuilder(); int l = source.length(); boolean consecutiveSpace = false; for (int i = 0; i < l; i++) { char c = source.charAt(i); if (Character.isWhitespace(c)) { if (!consecutiveSpace) { if (replace != null) target.append(replace); consecutiveSpace = true; }/* w w w .j a v a2 s .com*/ } else { target.append(c); if (consecutiveSpace) consecutiveSpace = false; } } return target.toString(); }
From source file:StandardUtilities.java
/** * @param str A java string/*ww w. j a v a 2 s . c o m*/ * @return the leading whitespace of that string, for indenting subsequent lines. * @since jEdit 4.3pre10 */ public static String getIndentString(String str) { StringBuilder indentString = new StringBuilder(); int idx = 0; char ch = str.charAt(idx); while (idx < str.length() && Character.isWhitespace(ch)) { indentString.append(ch); idx++; ch = str.charAt(idx); } return indentString.toString(); }
From source file:Main.java
/** * Returns a new string with all the whitespace removed * //from w w w . ja va 2 s . c o m * @param s the source string * @return the string without whitespace or null */ public static String removeWhiteSpace(String s) { String retn = null; if (s != null) { int len = s.length(); StringBuffer sbuf = new StringBuffer(len); for (int i = 0; i < len; i++) { char c = s.charAt(i); if (!Character.isWhitespace(c)) sbuf.append(c); } retn = sbuf.toString(); } return retn; }