List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:Main.java
/** * Trim off trailing blanks but not leading blanks * * @param str/*from w w w . ja va2 s .c o m*/ * * @return The input with trailing blanks stipped off */ public static String trimTrailing(String str) { if (str == null) return null; int len = str.length(); for (; len > 0; len--) { if (!Character.isWhitespace(str.charAt(len - 1))) break; } return str.substring(0, len); }
From source file:Main.java
/** * Determine whether a parameter name ends at the current position, * that is, whether the given character qualifies as a separator. *//*w ww .j a va 2s . co m*/ private static boolean isParameterSeparator(char c) { if (Character.isWhitespace(c)) { return true; } for (char separator : PARAMETER_SEPARATORS) { if (c == separator) { return true; } } return false; }
From source file:Main.java
public static char skipWhitespace(Reader reader) throws IOException { if (DEBUG)/*from w ww .j av a 2 s . c om*/ System.out.println("XMLParserUtilities.skipWhitespace( " + reader + ")"); char c = (char) reader.read(); while (Character.isWhitespace(c)) { c = (char) reader.read(); } return c; }
From source file:Main.java
/** * Check whether the given CharSequence contains any whitespace characters. * @param str the CharSequence to check (may be {@code null}) * @return {@code true} if the CharSequence is not empty and * contains at least 1 whitespace character * @see Character#isWhitespace// w w w . j a va 2s.c o m */ public static boolean containsWhitespace(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:StringUtil.java
/** * Helper function for null, empty, and whitespace string testing. * * @return true if s == null or s.equals("") or s contains only whitespace * characters./*from w w w . j a va 2 s . c o m*/ */ public static boolean isEmptyOrWhitespace(String s) { s = makeSafe(s); for (int i = 0, n = s.length(); i < n; i++) { if (!Character.isWhitespace(s.charAt(i))) { return false; } } return true; }
From source file:Main.java
public static String getLeadingWhitespace(String str) { if (str == null) { return ""; //$NON-NLS-1$ }// ww w . j av a 2s .c o m int sz = str.length(); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < sz; i++) { if ((Character.isWhitespace(str.charAt(i)))) { buffer.append(str.charAt(i)); } else { break; } } return buffer.toString(); }
From source file:Main.java
public static boolean isNumber(String s) { boolean pointcanappear = true; boolean signcanappear = true; boolean res = true; int i = 0;//from ww w . j a va2 s . c o m if (s.length() == 0) res = false; while (i < s.length() && res) { char c = s.charAt(i); boolean ok = false; if (Character.isWhitespace(c)) ok = true; else if (Character.isDigit(c)) { if (signcanappear) signcanappear = false; ok = true; } else if (c == '-' && signcanappear) { signcanappear = false; ok = true; } else if ((c == '.' || c == ',') && pointcanappear) { pointcanappear = false; ok = true; } if (ok) i++; else res = false; } return res; }
From source file:Main.java
private static String startXMLFor(String elementName, String argStr) { int tokenIndex = argStr.toLowerCase().indexOf(elementName.toLowerCase()); if (tokenIndex < 1) return null; int startIndex = tokenIndex; while (startIndex >= 0 && argStr.charAt(startIndex) != '<' && (Character.isWhitespace(argStr.charAt(startIndex)) || startIndex == tokenIndex)) { --startIndex;//from w w w. j av a 2s . com } // while if (startIndex < 0 || argStr.charAt(startIndex) != '<') return null; if (startIndex == 0) return argStr; return argStr.substring(startIndex); }
From source file:io.micrometer.core.instrument.util.StringUtils.java
/** * Check if the String is null or has only whitespaces. * * Modified from {@link org.apache.commons.lang.StringUtils#isBlank(String)}. * * @param string String to check//from w ww . j a v a 2s. co m * @return {@code true} if the String is null or has only whitespaces */ public static boolean isBlank(@Nullable String string) { if (isEmpty(string)) { return true; } for (int i = 0; i < string.length(); i++) { if (!Character.isWhitespace(string.charAt(i))) { return false; } } return true; }
From source file:Main.java
/** * <p>/*from w w w . ja va 2s . c om*/ * Deletes all whitespaces from a String. * </p> * <p/> * <p> * Whitespace is defined by {@link Character#isWhitespace(char)}. * </p> * * @param str String target to delete whitespace from * @return the String without whitespaces * @throws NullPointerException */ public static String deleteWhitespace(String str) { StringBuilder buffer = new StringBuilder(); int sz = str.length(); for (int i = 0; i < sz; i++) { if (!Character.isWhitespace(str.charAt(i))) { buffer.append(str.charAt(i)); } } return buffer.toString(); }