List of usage examples for java.lang CharSequence charAt
char charAt(int index);
From source file:Main.java
private static int skipQuotedText(CharSequence s, int i, int len) { if (i + 1 < len && s.charAt(i + 1) == QUOTE) { return 2; }//from w w w. j a v a2 s .c o m int count = 1; // skip leading quote i++; while (i < len) { char c = s.charAt(i); if (c == QUOTE) { count++; // QUOTEQUOTE -> QUOTE if (i + 1 < len && s.charAt(i + 1) == QUOTE) { i++; } else { break; } } else { i++; count++; } } return count; }
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;/* ww w. j a v a 2 s. co m*/ } else { len++; } } return Math.round(len); }
From source file:Main.java
/** * Checks whether the character present at the index of the CharSequence is a flagged character. * @param text - input text.// ww w .j a v a 2 s. com * @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; }
From source file:Main.java
public static CharSequence getTrimmedString(CharSequence src) { if (src == null || src.length() == 0) { return src; }/*from w w w.j a v a2s . co m*/ while (src.length() > 0 && (src.charAt(0) == '\n' || src.charAt(0) == ' ')) { src = src.subSequence(1, src.length()); } while (src.length() > 0 && (src.charAt(src.length() - 1) == '\n' || src.charAt(src.length() - 1) == ' ')) { src = src.subSequence(0, src.length() - 1); } return src; }
From source file:Main.java
public 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"; }/* w w w . j a v a2 s. co m*/ } return null; }
From source file:Main.java
private static void withinStyle(StringBuilder out, CharSequence text, int start, int end) { for (int i = start; i < end; i++) { char c = text.charAt(i); if (c == '<') { out.append("<"); } else if (c == '>') { out.append(">"); } else if (c == '&') { out.append("&"); } else if (c >= 0xD800 && c <= 0xDFFF) { if (c < 0xDC00 && i + 1 < end) { char d = text.charAt(i + 1); if (d >= 0xDC00 && d <= 0xDFFF) { i++;/*from w ww .j ava2 s . co m*/ int codePoint = 0x010000 | (int) c - 0xD800 << 10 | (int) d - 0xDC00; out.append("&#").append(codePoint).append(";"); } } } else if (c > 0x7E || c < ' ') { out.append("&#").append((int) c).append(";"); } else if (c == ' ') { while (i + 1 < end && text.charAt(i + 1) == ' ') { out.append(" "); i++; } out.append(' '); } else { out.append(c); } } }
From source file:Main.java
/** * we can't store a password as a string, since in Java * strings are immutable, and thus we can't null out and * guarantee the password doesn't hang around after GC; * CharSequence doesn't have this problem, and that's what * an EditText returns; So, we go from CharSequence to * an array of bytes; We want a byte array anyway, for crypto. * *//*from www . j a v a 2s .c o m*/ public static char[] fromCharSeqToChars(CharSequence seq) { char[] ret = new char[seq.length()]; int i; for (i = 0; i < seq.length(); i++) { ret[i] = seq.charAt(i); } return ret; }
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.// w w w .j a va2 s . c o m * @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:Main.java
public static boolean isValidT9Key(@NonNull CharSequence key) { final int LEN = key.length(); for (int i = 0; i < LEN; i++) { if (!isValidT9Key(key.charAt(i))) { return false; }/*from ww w. ja va 2 s . c o m*/ } return true; }
From source file:Main.java
public static String sanitizeToLineFeed(CharSequence string) { StringBuilder sb = new StringBuilder(); for (int i = 0, len = string.length(); i < len; i++) { char c = string.charAt(i); boolean legal = c == '\u0009' || c == '\n' || (c >= '\u0020' && c <= '\uD7FF') || (c >= '\uE000' && c <= '\uFFFD'); if (legal) { sb.append(c);//w ww . j a va 2 s.com } } return sb.toString(); }