List of usage examples for java.lang CharSequence length
int length();
From source file:net.seleucus.wsp.crypto.FwknopSymmetricCrypto.java
protected static boolean equals(CharSequence a, CharSequence b) { if (a.length() != b.length()) return false; boolean result = true; for (int i = 0; i < a.length(); i++) { if (a.charAt(i) != b.charAt(i)) result = false;// w w w . j av a2 s . co m } return result; }
From source file:com.figo.campaignhelper.GenerateActivity.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 HTTP.UTF_8; }/*w w w . ja va2 s . c o m*/ } return null; }
From source file:Strings.java
/** * Appends a whitespace-normalized form of the specified character * sequence into the specified string buffer. Initial and final * whitespaces are not appended, and every other maximal sequence * of contiguous whitespace is replaced with a single whitespace * character. For instance, <code>" a\tb\n"</code> * would append the following characters to <code>"a * b"</code>.//w w w . j a v a 2 s . c o m * * <P>This command is useful for text inputs for web or GUI * applications. * * @param cs Character sequence whose normalization is appended to * the buffer. * @param sb String buffer to which the normalized character * sequence is appended. */ public static void normalizeWhitespace(CharSequence cs, StringBuilder sb) { int i = 0; int length = cs.length(); while (length > 0 && isWhitespace(cs.charAt(length - 1))) --length; while (i < length && isWhitespace(cs.charAt(i))) ++i; boolean inWhiteSpace = false; for (; i < length; ++i) { char nextChar = cs.charAt(i); if (isWhitespace(nextChar)) { if (!inWhiteSpace) { sb.append(' '); inWhiteSpace = true; } } else { inWhiteSpace = false; sb.append(nextChar); } } }
From source file:Main.java
/** * Finds the index of the first word that starts with the given prefix. * <p>//from w w w. j ava 2 s.co m * If not found, returns -1. * * @param text the text in which to search for the prefix * @param prefix the text to find, in upper case letters */ public static int indexOfWordPrefix(CharSequence text, String prefix) { if (prefix == null || text == null) { return -1; } int textLength = text.length(); int prefixLength = prefix.length(); if (prefixLength == 0 || textLength < prefixLength) { return -1; } int i = 0; while (i < textLength) { // Skip non-word characters while (i < textLength && !Character.isLetterOrDigit(text.charAt(i))) { i++; } if (i + prefixLength > textLength) { return -1; } // Compare the prefixes int j; for (j = 0; j < prefixLength; j++) { if (Character.toUpperCase(text.charAt(i + j)) != prefix.charAt(j)) { break; } } if (j == prefixLength) { return i; } // Skip this word while (i < textLength && Character.isLetterOrDigit(text.charAt(i))) { i++; } } return -1; }
From source file:com.googlecode.jcimd.charset.GsmCharsetProvider.java
/** * Returns the number of bytes needed to encode the given character * sequence as GSM 3.38 (7-bit) default alphabet. Returns -1 if the * given sequence contains a character that cannot be encoded. * * @param s the given character sequence * @return the number of bytes needed to encode the given character * sequence as GSM 3.38 (7-bit) default alphabet. Otherwise, -1 is * returned.//from w ww . j a v a2s . c o m */ public static int countGsm7BitCharacterBytes(CharSequence s) { int length = s.length(); int totalBits = 0, bits = 0; for (int i = 0; i < length; i++) { bits = countGsm7BitCharacterBits(s.charAt(i)); if (bits < 0) { return -1; } totalBits += bits; } // Divide bits by 8 rounding up // (bits + 8 - 1) / 8 return (totalBits + 7) / 8; }
From source file:Main.java
public static void setEditCursor(EditText editText) { CharSequence text = editText.getText(); //Debug.asserts(text instanceof Spannable); if (text instanceof Spannable) { Spannable spanText = (Spannable) text; Selection.setSelection(spanText, text.length()); }/*w ww . j a v a2 s . c o m*/ }
From source file:Main.java
public static boolean checkRange(@Nullable final CharSequence text, int start, int end) { if (text == null) return false; if (end < start) { return false; }/*from w ww. jav a 2 s .co m*/ int len = text.length(); if (start > len || end > len) { return false; } if (start < 0 || end < 0) { return false; } return true; }
From source file:TextUtils.java
/** * See {@link String#compareToIgnoreCase(String)} * //from w w w.j av a2 s.c o m * @param s * @param t * @return See {@link String#compareToIgnoreCase(String)} */ public static int compareToIgnoreCase(CharSequence s, CharSequence t) { int i = 0; while (i < s.length() && i < t.length()) { char a = Character.toLowerCase(s.charAt(i)); char b = Character.toLowerCase(t.charAt(i)); int diff = a - b; if (diff != 0) { return diff; } i++; } return s.length() - t.length(); }
From source file:TextUtils.java
/** * See {@link String#compareTo(String)}/*w w w .j ava2 s . co m*/ * * @param s * @param t * @return See {@link String#compareTo(String)} */ public static int compareTo(CharSequence s, CharSequence t) { int i = 0; while (i < s.length() && i < t.length()) { char a = s.charAt(i); char b = t.charAt(i); int diff = a - b; if (diff != 0) { return diff; } i++; } return s.length() - t.length(); }
From source file:com.appglu.impl.util.StringUtils.java
public static boolean hasLength(CharSequence str) { return (str != null && str.length() > 0); }