List of usage examples for java.lang CharSequence length
int length();
From source file:Main.java
/** * <p>Checks if a CharSequence is whitespace, empty ("") or null.</p> * <p>/*from ww w . j a v a 2 s .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
/** * @return true if substring started at 'start' is a XML entity reference. *//*from ww w. jav a 2 s . co m*/ public static boolean isXmlEntityRef(CharSequence str, int start) { int len = str.length(); if (start >= len || str.charAt(start) != '&') return false; if (++start >= len) return false; if (str.charAt(start) == '#') return isXmlCharRefPart(str, start + 1); int i = start; if (!isNameStart(str.charAt(i))) return false; for (++i; i < len; ++i) { if (!isName(str.charAt(i))) break; } return (i > start && i < len && str.charAt(i) == ';'); }
From source file:Main.java
/** * Tells whether has a flag in the same line as mentioned by fromIndex character. * @param sequence - text// w w w . java2 s . com * @param flag - expected flag. * @param fromIndex - index representing the line. * @return */ public static boolean hasFlagSameLine(CharSequence sequence, char flag, int fromIndex) { for (int i = fromIndex; i < sequence.length(); i++) { char c = sequence.charAt(i); if (c == NEW_LINE) { return false; } if (c == flag) { return i != fromIndex; } } return false; }
From source file:Main.java
public static void escape(StringBuilder sb, CharSequence string) { for (int i = 0; i < string.length(); i++) { char c = string.charAt(i); switch (c) { case '&': sb.append("&"); break; case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '"': sb.append("""); break; default:/*from ww w .j ava 2s .c o m*/ sb.append(c); } } }
From source file:Main.java
/** * Formats by adding a hyphen for every 4 numbers (IE like a credit card) * @param s Charsequence being altered.// ww w . ja va 2s .c o m * @return Return an altered String with hyphens in it */ public static String formatNumbersAsCreditCard(CharSequence s) { int groupDigits = 0; String tmp = ""; for (int i = 0; i < s.length(); ++i) { tmp += s.charAt(i); ++groupDigits; if (groupDigits == 4) { if (groupDigits == 16) { } else { tmp += "-"; } groupDigits = 0; } } if (tmp.length() == 20) { tmp = tmp.substring(0, tmp.length() - 1); //Get rid of last digit } return tmp; }
From source file:com.laxser.blitz.util.BlitzStringUtil.java
public static boolean startsWith(CharSequence input, String prefix) { if (input.length() < prefix.length()) { return false; }//from w ww .j a v a2 s .co m if (input.getClass() == String.class) { return ((String) input).startsWith(prefix); } int len = prefix.length(); for (int i = 0; i < len; i++) { char pi = input.charAt(i); char ci = prefix.charAt(i); if (pi != ci) { return false; } } return true; }
From source file:Main.java
/** * NOTE: No well-formness check for the referenced char. * * @param start Index to char after "&#". *//*from w w w. ja v a 2 s . com*/ public static boolean isXmlCharRefPart(CharSequence str, int start) { int len = str.length(); if (start >= len) return false; char c; if (str.charAt(start) == 'x') { // &#xhex; ++start; int i = start; for (; i < len; ++i) { c = str.charAt(i); if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) continue; break; } return (i > start && i < len && str.charAt(i) == ';'); } // &#dec; int i = start; for (; i < len; ++i) { c = str.charAt(i); if (c < '0' || c > '9') break; } return (i > start && i < len && str.charAt(i) == ';'); }
From source file:Main.java
/** * Check if wepKey is a valid hexadecimal string. * @param wepKey the input to be checked * @return true if the input string is indeed hex or empty. False if the input string is non-hex * or null./*from w ww .j a va 2s . co m*/ */ static boolean isHexWepKey(CharSequence wepKey) { if (wepKey == null) { return false; } int length = wepKey.length(); // WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?) return (length == 10 || length == 26 || length == 58) && HEX_DIGITS.matcher(wepKey).matches(); }
From source file:Main.java
public static CharSequence sanitizeXml10(CharSequence sequence) { if (sequence == null) { return null; }// ww w . j ava2 s .c om if (sequence.length() == 0) { return sequence; } return invalidXml10.matcher(sequence).replaceAll("\uFFFD"); }
From source file:Main.java
/** * <p>Checks if a CharSequence is empty ("") or null.</p> * * <pre>/*from w ww . j av a 2 s. c o m*/ * StringUtils.isEmpty(null) = true * StringUtils.isEmpty("") = true * StringUtils.isEmpty(" ") = false * StringUtils.isEmpty("bob") = false * StringUtils.isEmpty(" bob ") = false * </pre> * * <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(CharSequence cs) { return cs == null || cs.length() == 0; }