1 package com.android.contacts.datepicker;
2 
3 public class ICU {
4 
5     /**
6      * This method is directly copied from {@link libcore.icu.ICU}. The method is simple enough
7      * that it probably won't change.
8      */
getDateFormatOrder(String pattern)9     public static char[] getDateFormatOrder(String pattern) {
10         char[] result = new char[3];
11         int resultIndex = 0;
12         boolean sawDay = false;
13         boolean sawMonth = false;
14         boolean sawYear = false;
15 
16         for (int i = 0; i < pattern.length(); ++i) {
17             char ch = pattern.charAt(i);
18             if (ch == 'd' || ch == 'L' || ch == 'M' || ch == 'y') {
19                 if (ch == 'd' && !sawDay) {
20                     result[resultIndex++] = 'd';
21                     sawDay = true;
22                 } else if ((ch == 'L' || ch == 'M') && !sawMonth) {
23                     result[resultIndex++] = 'M';
24                     sawMonth = true;
25                 } else if ((ch == 'y') && !sawYear) {
26                     result[resultIndex++] = 'y';
27                     sawYear = true;
28                 }
29             } else if (ch == 'G') {
30                 // Ignore the era specifier, if present.
31             } else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
32                 throw new IllegalArgumentException("Bad pattern character '"
33                         + ch + "' in " + pattern);
34             } else if (ch == '\'') {
35                 if (i < pattern.length() - 1 && pattern.charAt(i + 1) == '\'') {
36                     ++i;
37                 } else {
38                     i = pattern.indexOf('\'', i + 1);
39                     if (i == -1) {
40                         throw new IllegalArgumentException("Bad quoting in " + pattern);
41                     }
42                     ++i;
43                 }
44             } else {
45                 // Ignore spaces and punctuation.
46             }
47         }
48         return result;
49     }
50 
51 }
52