List of usage examples for java.lang CharSequence charAt
char charAt(int index);
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; }//from w w w.ja va 2 s . c o m } return null; }
From source file:com.hj.blog.common.utils.StringUtils.java
static boolean isNumeric(final CharSequence cs) { if (isEmpty(cs)) { return false; }/*from w w w.j a v a 2 s . c om*/ final int sz = cs.length(); for (int i = 0; i < sz; i++) { if (Character.isDigit(cs.charAt(i)) == false) { return false; } } return true; }
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 v a 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:Main.java
public static CharSequence toLowerCase(CharSequence character) { if (character == null || character.equals("")) { return character; }//from w ww .j ava 2s. c o m StringBuffer buffer = new StringBuffer(); for (int i = 0; i < character.length(); i++) { buffer.append(Character.toLowerCase(character.charAt(i))); } return buffer.toString(); }
From source file:Main.java
/** * Check whether the given CharSequence has actual text. * More specifically, returns {@code true} if the string not {@code null}, * its length is greater than 0, and it contains at least one non-whitespace character. * <p><pre class="code">//from w w w . j a v a2s .c om * StringUtils.hasText(null) = false * StringUtils.hasText("") = false * StringUtils.hasText(" ") = false * StringUtils.hasText("12345") = true * StringUtils.hasText(" 12345 ") = true * </pre> * @param str the CharSequence to check (may be {@code null}) * @return {@code true} if the CharSequence is not {@code null}, * its length is greater than 0, and it does not contain whitespace only * @see Character#isWhitespace */ public static boolean hasText(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: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>./*from w ww. j av a2 s .com*/ * * <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
static boolean prefixes(CharSequence sequence, String prefix) { boolean prefixes = false; if (sequence.length() > prefix.length()) { int count = prefix.length(); prefixes = true;/*from w ww .ja v a 2 s .com*/ for (int i = 0; i < count; i++) { if (sequence.charAt(i) != prefix.charAt(i)) { prefixes = false; break; } } } return prefixes; }
From source file:Main.java
public static String escapeXml(CharSequence str) { if (str == null) { return null; }// w ww . java 2 s .c om StringBuilder res = null; int strLength = str.length(); for (int i = 0; i < strLength; i++) { char c = str.charAt(i); String repl = encodeXMLChar(c); if (repl == null) { if (res != null) { res.append(c); } } else { if (res == null) { res = new StringBuilder(str.length() + 5); for (int k = 0; k < i; k++) { res.append(str.charAt(k)); } } res.append(repl); } } return res == null ? str.toString() : res.toString(); }
From source file:TextUtils.java
/** * See {@link String#compareTo(String)}// w ww . j a va 2 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:Strings.java
/** * Return <code>true</code> if the two character sequences have * the same length and the same characters. Recall that equality * is not refined in the specification of {@link CharSequence}, but * rather inherited from {@link Object#equals(Object)}. * * The related method {@link #hashCode(CharSequence)} returns * hash codes consistent with this notion of equality. * * @param cs1 First character sequence./* w w w .j a v a 2s.c o m*/ * @param cs2 Second character sequence. * @return <code>true</code> if the character sequences yield * the same strings. */ public static boolean equalCharSequence(CharSequence cs1, CharSequence cs2) { if (cs1 == cs2) return true; int len = cs1.length(); if (len != cs2.length()) return false; for (int i = 0; i < len; ++i) if (cs1.charAt(i) != cs2.charAt(i)) return false; return true; }