Files
android_translation_layer/src/api-impl/android/text/TextUtils.java

100 lines
2.4 KiB
Java
Raw Normal View History

package android.text;
import java.util.regex.Pattern;
public class TextUtils {
// unchanged from android source
/* split */
private static String[] EMPTY_STRING_ARRAY = new String[] {};
public static String[] split(String text, String expression) {
if (text.length() == 0) {
return EMPTY_STRING_ARRAY;
} else {
return text.split(expression, -1);
}
}
public static String[] split(String text, Pattern pattern) {
if (text.length() == 0) {
return EMPTY_STRING_ARRAY;
} else {
return pattern.split(text, -1);
}
}
/* join */
public static String join(CharSequence delimiter, Object[] tokens) {
StringBuilder sb = new StringBuilder();
boolean firstTime = true;
for (Object token : tokens) {
if (firstTime) {
firstTime = false;
} else {
sb.append(delimiter);
}
sb.append(token);
}
return sb.toString();
}
public static String join(CharSequence delimiter, Iterable tokens) {
StringBuilder sb = new StringBuilder();
boolean firstTime = true;
for (Object token : tokens) {
if (firstTime) {
firstTime = false;
} else {
sb.append(delimiter);
}
sb.append(token);
}
return sb.toString();
}
// end of unchanged from android source
public static CharSequence join(Iterable<CharSequence> list) {
final CharSequence delimiter = ","; // ????
return join(delimiter, list);
}
public static boolean isEmpty(CharSequence str) {
return str == null || str.equals("");
}
/**
* Returns true if a and b are equal, including if they are both null.
* <p><i>Note: In platform versions 1.1 and earlier, this method only worked well if
* both the arguments were instances of String.</i></p>
* @param a first CharSequence to check
* @param b second CharSequence to check
* @return true if a and b are equal
*/
public static boolean equals(CharSequence a, CharSequence b) {
if (a == b) return true;
int length;
if (a != null && b != null && (length = a.length()) == b.length()) {
if (a instanceof String && b instanceof String) {
return a.equals(b);
} else {
for (int i = 0; i < length; i++) {
if (a.charAt(i) != b.charAt(i)) return false;
}
return true;
}
}
return false;
}
public enum TruncateAt {
START,
MIDDLE,
END,
MARQUEE,
END_SMALL
}
}