summaryrefslogtreecommitdiff
path: root/core/src/test/java/android/text/TextUtils.java
blob: 709cb9e93e5c76cb9b61847c2dd4dab64d37cdea (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
package android.text;

/**
 * A slim-down version of standard {@link android.text.TextUtils} to be used in unit tests.
 */
public class TextUtils {

    /**
     * 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
     */
    @SuppressWarnings("unused")
    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;
    }

    /**
     * Returns <code>true</code> if the string is <code>null</code> or has zero length.
     *
     * @param str The string to be examined, can be <code>null</code>.
     * @return <code>true</code> if the string is <code>null</code> or has zero length.
     */
    public static boolean isEmpty(CharSequence str) {
        return str == null || str.length() == 0;
    }
}