List of usage examples for java.lang CharSequence length
int length();
From source file:Main.java
/** * <p>Checks if a CharSequence is empty ("") or null.</p> * <p>/*from ww w . ja va 2 s .co m*/ * <pre> * StringUtils.isEmpty(null) = true * StringUtils.isEmpty("") = true * StringUtils.isEmpty(" ") = false * StringUtils.isEmpty("bob") = false * StringUtils.isEmpty(" bob ") = false * </pre> * <p> * <p>NOTE: This method changed in Lang version 2.0. * It no longer trims the CharSequence. * That functionality is available in isBlank().</p> * * @param cs the CharSequence to check, may be null * @return {@code true} if the CharSequence is empty or null * @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence) */ public static boolean isEmpty(final CharSequence cs) { return cs == null || cs.length() == 0; }
From source file:Main.java
private static String guessAppropriateEncoding(CharSequence contents) { // Very crude at the moment for (int i = 0; i < contents.length(); i++) { if (contents.charAt(i) > 0xFF) { return "UTF-8"; }/*from w w w. j a va 2 s . c om*/ } return null; }
From source file:Main.java
public static boolean validUTF16String(CharSequence s) { final int size = s.length(); for (int i = 0; i < size; i++) { char ch = s.charAt(i); if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) { if (i < size - 1) { i++;// ww w. j ava 2s.com char nextCH = s.charAt(i); if (nextCH >= UNI_SUR_LOW_START && nextCH <= UNI_SUR_LOW_END) { // Valid surrogate pair } else // Unmatched high surrogate return false; } else // Unmatched high surrogate return false; } else if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) // Unmatched low surrogate return false; } return true; }
From source file:Main.java
public static long calculateWeiboLength(CharSequence c) { double len = 0; for (int i = 0; i < c.length(); i++) { int temp = (int) c.charAt(i); if (temp > 0 && temp < 127) { len += 0.5;/*from w ww.j a v a2 s. c om*/ } else { len++; } } return Math.round(len); }
From source file:Main.java
/** * is null or its length is 0// www . j ava2 s . com * * <pre> * isEmpty(null) = true; * isEmpty("") = true; * isEmpty(" ") = false; * </pre> * * @param str * @return if string is null or its size is 0, return true, else return false. */ public static boolean isEmpty(CharSequence str) { return (str == null || str.length() == 0); }
From source file:Main.java
/** * get length of CharSequence/* ww w .java2s.co m*/ * * <pre> * length(null) = 0; * length(\"\") = 0; * length(\"abc\") = 3; * </pre> * * @param str * @return if str is null or empty, return 0, else return {@link CharSequence#length()}. */ public static int length(CharSequence str) { return str == null ? 0 : str.length(); }
From source file:Main.java
/** * <p>Checks if a CharSequence is whitespace, empty ("") or null.</p> * * <pre>/*from ww w. j a va2 s. co m*/ * 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 2.0 * @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence) */ public static boolean isBlank(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
public static CharSequence trimTrailingWhitespace(CharSequence source) { if (source == null) return ""; int i = source.length(); // loop back to the first non-whitespace character while (--i >= 0 && Character.isWhitespace(source.charAt(i))) { }/*from ww w . j a va 2s . c o m*/ return source.subSequence(0, i + 1); }
From source file:Main.java
public static int length(CharSequence str) { if (str == null) { return 0; } else {// w w w . j a va 2 s. c o m return str.length(); } }
From source file:Main.java
/** * Checks whether the character present at the index of the CharSequence is a flagged character. * @param text - input text.// www. j a v a2s . c om * @param index - index to check. * @return true if the character is flagged, false otherwise. */ public static boolean isFlagged(CharSequence text, int index) { if (index > INVALID_INDEX && index < text.length()) { char c = text.charAt(index); return c == SPACE || c == NEW_LINE || c == BOLD_FLAG || c == ITALIC_FLAG || c == STRIKE_FLAG; } return true; }