List of usage examples for java.lang CharSequence length
int length();
From source file:com.hj.blog.common.utils.StringUtils.java
static boolean isEmpty(final CharSequence cs) { return cs == null || cs.length() == 0; }
From source file:Main.java
/** * <p>Returns a new {@code CharSequence} that is a subsequence of this * sequence starting with the {@code char} value at the specified index.</p> * <p>/*ww w . j a v a2s . c om*/ * <p>This provides the {@code CharSequence} equivalent to {@link String#substring(int)}. * The length (in {@code char}) of the returned sequence is {@code length() - start}, * so if {@code start == end} then an empty sequence is returned.</p> * * @param cs the specified subsequence, null returns null * @param start the start index, inclusive, valid * @return a new subsequence, may be null * @throws IndexOutOfBoundsException if {@code start} is negative or if * {@code start} is greater than {@code length()} */ public static CharSequence subSequence(final CharSequence cs, final int start) { return cs == null ? null : cs.subSequence(start, cs.length()); }
From source file:Main.java
public static final CharSequence padFront(final CharSequence pText, final char pPadChar, final int pLength) { final int padCount = pLength - pText.length(); if (padCount <= 0) { return pText; } else {/*from w w w . j a va2 s . c o m*/ final StringBuilder sb = new StringBuilder(); for (int i = padCount - 1; i >= 0; i--) { sb.append(pPadChar); } sb.append(pText); return sb.toString(); } }
From source file:Main.java
public static void show(Context context, CharSequence text) { if (!TextUtils.isEmpty(text)) { if (text.length() < 10) { Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); } else {// ww w . j av a 2 s. c o m Toast.makeText(context, text, Toast.LENGTH_LONG).show(); } } }
From source file:Main.java
/** * Formats by adding forward slash every 2 numbers (IE like a credit card expiration date) * @param s Charsequence being altered./*from ww w . j av a 2 s. c om*/ * @return Return an altered String with hyphens in it */ public static String formatNumbersAsCreditCardExpiration(CharSequence s) { int groupDigits = 0; String tmp = ""; for (int i = 0; i < s.length(); ++i) { tmp += s.charAt(i); ++groupDigits; if (groupDigits == 2) { tmp += "/"; groupDigits = 0; } } if (tmp.length() > 5) { tmp = tmp.substring(0, tmp.length() - 1); //Get rid of last digit } return tmp; }
From source file:Strings.java
/** * Returns {@code true} if the specified character sequence is a * valid sequence of UTF-16 {@code char} values. A sequence is * legal if each high surrogate {@code char} value is followed by * a low surrogate value (as defined by {@link * Character#isHighSurrogate(char)} and {@link * Character#isLowSurrogate(char)})./*from www.j a va2 s.c o m*/ * * <p>This method does <b>not</b> check to see if the sequence of * code points defined by the UTF-16 consists only of code points * defined in the latest Unicode standard. The method only tests * the validity of the UTF-16 encoding sequence. * * @param cs Character sequence to test. * @return {@code true} if the sequence of characters is * legal in UTF-16. */ public static boolean isLegalUtf16(CharSequence cs) { for (int i = 0; i < cs.length(); ++i) { char high = cs.charAt(i); if (Character.isLowSurrogate(high)) return false; if (!Character.isHighSurrogate(high)) continue; ++i; if (i >= cs.length()) return false; char low = cs.charAt(i); if (!Character.isLowSurrogate(low)) return false; int codePoint = Character.toCodePoint(high, low); if (!Character.isValidCodePoint(codePoint)) return false; } return true; }
From source file:Main.java
/** * The pattern matching does not work./*from www . ja va 2 s.c o m*/ * * @param sequence the character sequence * @return sanitized string */ public static String sanitizeXml10(CharSequence sequence) { if (sequence == null) { return null; } if (sequence.length() == 0) { return ""; } return invalidXml10.matcher(sequence).replaceAll("\uFFFD"); }
From source file:Main.java
/** * This method determines if the direction of a substring is right-to-left. * If the string is empty that determination is based on the default system language * Locale.getDefault().// w w w. ja v a2 s . com * The method can handle invalid substring definitions (start > end etc.), in which case the * method returns False. * * @return True if the text direction is right-to-left, false otherwise. */ public static boolean isRTL(CharSequence s, int start, int end) { if (s == null || s.length() == 0) { // empty string --> determine the direction from the default language return isRTL(Locale.getDefault()); } if (start == end) { // if no character is selected we need to expand the selection start = Math.max(0, --start); if (start == end) { end = Math.min(s.length(), ++end); } } try { Bidi bidi = new Bidi(s.subSequence(start, end).toString(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); return !bidi.baseIsLeftToRight(); } catch (IndexOutOfBoundsException e) { return false; } }
From source file:Main.java
/** * Finds the length of the largest prefix for two character sequences. * * @param a character sequence/*from ww w . j a v a 2 s . com*/ * @param b character sequence * @return the length of largest prefix of <code>a</code> and <code>b</code> * @throws IllegalArgumentException if either <code>a</code> or <code>b</code> * is <code>null</code> */ public static int largestPrefixLength(CharSequence a, CharSequence b) { int len = 0; for (int i = 0; i < Math.min(a.length(), b.length()); ++i) { if (a.charAt(i) != b.charAt(i)) break; ++len; } return len; }
From source file:Main.java
/** * Returns true if the parameter is null or of zero length *//*w ww . j a va 2 s . c o m*/ public static boolean isEmpty(final CharSequence s) { if (s == null) { return true; } return s.length() == 0; }