2022-10-02 23:06:56 +02:00
|
|
|
package android.text;
|
|
|
|
|
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
public class TextUtils {
|
|
|
|
|
// unchanged from android source
|
|
|
|
|
|
|
|
|
|
/* split */
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
private static String[] EMPTY_STRING_ARRAY = new String[] {};
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public static String[] split(String text, String expression) {
|
|
|
|
|
if (text.length() == 0) {
|
|
|
|
|
return EMPTY_STRING_ARRAY;
|
|
|
|
|
} else {
|
|
|
|
|
return text.split(expression, -1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public static String[] split(String text, Pattern pattern) {
|
|
|
|
|
if (text.length() == 0) {
|
|
|
|
|
return EMPTY_STRING_ARRAY;
|
|
|
|
|
} else {
|
|
|
|
|
return pattern.split(text, -1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-02 23:06:56 +02:00
|
|
|
|
|
|
|
|
/* join */
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
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();
|
|
|
|
|
}
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
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();
|
|
|
|
|
}
|
2022-10-02 23:06:56 +02:00
|
|
|
// end of unchanged from android source
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public static CharSequence join(Iterable<CharSequence> list) {
|
|
|
|
|
final CharSequence delimiter = ","; // ????
|
|
|
|
|
return join(delimiter, list);
|
|
|
|
|
}
|
2022-11-24 16:05:38 +01:00
|
|
|
|
|
|
|
|
public static boolean isEmpty(CharSequence str) {
|
2023-07-14 17:56:31 +02:00
|
|
|
return str == null || str.equals("");
|
2022-11-24 16:05:38 +01:00
|
|
|
}
|
2023-07-14 17:56:31 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
2023-08-17 10:46:24 +02:00
|
|
|
|
|
|
|
|
public enum TruncateAt {
|
|
|
|
|
START,
|
|
|
|
|
MIDDLE,
|
|
|
|
|
END,
|
|
|
|
|
MARQUEE,
|
|
|
|
|
END_SMALL
|
|
|
|
|
}
|
2023-08-22 14:41:01 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
2023-09-12 23:18:47 +02:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|