You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
137 lines
3.4 KiB
Java
137 lines
3.4 KiB
Java
package android.text;
|
|
|
|
import java.util.Locale;
|
|
import java.util.regex.Pattern;
|
|
|
|
public class TextUtils {
|
|
public static int getLayoutDirectionFromLocale(Locale locale) {
|
|
return 0 /*LTR*/; // FIXME
|
|
}
|
|
|
|
// 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.length() == 0;
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
}
|
|
|
|
/**
|
|
* Returns the original text if it fits in the specified width
|
|
* given the properties of the specified Paint,
|
|
* or, if it does not fit, a truncated
|
|
* copy with ellipsis character added at the specified edge or center.
|
|
*/
|
|
public static CharSequence ellipsize(CharSequence text, TextPaint p, float avail, TruncateAt where) {
|
|
return text;
|
|
}
|
|
|
|
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 {
|
|
for (int i = start; i < end; i++)
|
|
dest[destoff++] = s.charAt(i);
|
|
}
|
|
}
|
|
|
|
public static int getCapsMode(CharSequence cs, int off, int reqModes) {
|
|
return 0;
|
|
}
|
|
}
|