blob: abf5491fd3e2ad624312e921e01b247919cda7bb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package com.xtremelabs.robolectric.shadows;
import android.text.TextUtils;
import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;
import com.xtremelabs.robolectric.util.Join;
import java.util.Collection;
@SuppressWarnings({"UnusedDeclaration"})
@Implements(TextUtils.class)
public class ShadowTextUtils {
@Implementation
public static CharSequence expandTemplate(CharSequence template,
CharSequence... values) {
String s = template.toString();
for (int i = 0, valuesLength = values.length; i < valuesLength; i++) {
CharSequence value = values[i];
s = s.replace("^" + (i + 1), value);
}
return s;
}
@Implementation
public static boolean isEmpty(CharSequence s) {
return (s == null || s.length() == 0);
}
@Implementation
public static int getTrimmedLength(CharSequence s) {
int len = s.length();
int start = 0;
while (start < len && s.charAt(start) <= ' ') {
start++;
}
int end = len;
while (end > start && s.charAt(end - 1) <= ' ') {
end--;
}
return end - start;
}
@Implementation
public static String join(CharSequence delimiter, Iterable tokens) {
return Join.join((String) delimiter, (Collection) tokens);
}
@Implementation
public static String join(CharSequence delimiter, Object[] tokens) {
return Join.join((String) delimiter, tokens);
}
@Implementation
public static boolean isDigitsOnly(CharSequence str) {
final int len = str.length();
for (int i = 0; i < len; i++) {
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
return true;
}
@Implementation
public static String[] split(String text, String expression) {
if(text.length() == 0) {
return new String[]{};
}
return text.split(expression);
}
}
|