List of usage examples for java.lang CharSequence getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.laxser.blitz.util.BlitzStringUtil.java
public static boolean startsWith(CharSequence input, String prefix) { if (input.length() < prefix.length()) { return false; }/* w w w. ja va2 s .c o 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:com.jecelyin.editor.v2.core.text.TextUtils.java
public static int lastIndexOf(CharSequence s, char ch, int last) { Class<? extends CharSequence> c = s.getClass(); if (c == String.class) return ((String) s).lastIndexOf(ch, last); return lastIndexOf(s, ch, 0, last); }
From source file:com.jecelyin.editor.v2.core.text.TextUtils.java
public static int indexOf(CharSequence s, char ch, int start) { Class<? extends CharSequence> c = s.getClass(); if (c == String.class) return ((String) s).indexOf(ch, start); return indexOf(s, ch, start, s.length()); }
From source file:com.jecelyin.editor.v2.core.text.TextUtils.java
public static void getChars(CharSequence s, int start, int end, char[] dest, int destoff) { Class<? extends CharSequence> c = s.getClass(); if (c == String.class) ((String) s).getChars(start, end, dest, destoff); else if (c == StringBuffer.class) ((StringBuffer) s).getChars(start, end, dest, destoff); else if (c == StringBuilder.class) ((StringBuilder) s).getChars(start, end, dest, destoff); else if (s instanceof GetChars) ((GetChars) s).getChars(start, end, dest, destoff); else {/* ww w .j ava2 s. com*/ for (int i = start; i < end; i++) dest[destoff++] = s.charAt(i); } }
From source file:com.jecelyin.editor.v2.core.text.TextUtils.java
public static int indexOfNewLineChar(CharSequence s, int start, int end) { Class<? extends CharSequence> c = s.getClass(); if (s instanceof GetChars || c == StringBuffer.class || c == StringBuilder.class || c == String.class) { final int INDEX_INCREMENT = 500; char[] temp = obtain(INDEX_INCREMENT); while (start < end) { int segend = start + INDEX_INCREMENT; if (segend > end) segend = end;/*www.ja v a2s .c o m*/ getChars(s, start, segend, temp, 0); int count = segend - start; for (int i = 0; i < count; i++) { if (temp[i] == '\r' || temp[i] == '\n') { recycle(temp); if (temp[i] == '\r' && i + 1 < count && temp[i + 1] == '\n') { i++; } return i + start; } } start = segend; } recycle(temp); return -1; } for (int i = start; i < end; i++) if (s.charAt(i) == '\r' || s.charAt(i) == '\n') { if (s.charAt(i) == '\r' && i + 1 < end && s.charAt(i + 1) == '\n') { i++; } return i; } return -1; }
From source file:com.jecelyin.editor.v2.core.text.TextUtils.java
public static int indexOf(CharSequence s, char ch, int start, int end) { Class<? extends CharSequence> c = s.getClass(); if (s instanceof GetChars || c == StringBuffer.class || c == StringBuilder.class || c == String.class) { final int INDEX_INCREMENT = 500; char[] temp = obtain(INDEX_INCREMENT); while (start < end) { int segend = start + INDEX_INCREMENT; if (segend > end) segend = end;//from ww w. ja va2 s. c o m getChars(s, start, segend, temp, 0); int count = segend - start; for (int i = 0; i < count; i++) { if (temp[i] == ch) { recycle(temp); return i + start; } } start = segend; } recycle(temp); return -1; } for (int i = start; i < end; i++) if (s.charAt(i) == ch) return i; return -1; }
From source file:com.jecelyin.editor.v2.core.text.TextUtils.java
public static int lastIndexOf(CharSequence s, char ch, int start, int last) { if (last < 0) return -1; if (last >= s.length()) last = s.length() - 1;/* w w w.j a v a 2 s .c o m*/ int end = last + 1; Class<? extends CharSequence> c = s.getClass(); if (s instanceof GetChars || c == StringBuffer.class || c == StringBuilder.class || c == String.class) { final int INDEX_INCREMENT = 500; char[] temp = obtain(INDEX_INCREMENT); while (start < end) { int segstart = end - INDEX_INCREMENT; if (segstart < start) segstart = start; getChars(s, segstart, end, temp, 0); int count = end - segstart; for (int i = count - 1; i >= 0; i--) { if (temp[i] == ch) { recycle(temp); return i + segstart; } } end = segstart; } recycle(temp); return -1; } for (int i = end - 1; i >= start; i--) if (s.charAt(i) == ch) return i; return -1; }