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