Print this page
rev 5696 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o packaging changes. by Naoto Sato and Masayoshi Okutsu)
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/classes/sun/util/locale/LocaleUtils.java
+++ new/src/share/classes/sun/util/locale/LocaleUtils.java
1 1 /*
2 2 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 /*
27 27 *******************************************************************************
28 28 * Copyright (C) 2009, International Business Machines Corporation and *
29 29 * others. All Rights Reserved. *
30 30 *******************************************************************************
31 31 */
32 32 package sun.util.locale;
33 33
34 34 import java.util.List;
35 35 import java.util.Map;
36 36 import java.util.Set;
37 37
38 38 /**
39 39 * Collection of static utility methods for Locale support. The
40 40 * methods which manipulate characters or strings support ASCII only.
41 41 */
42 42 public final class LocaleUtils {
43 43
44 44 private LocaleUtils() {
45 45 }
46 46
47 47 /**
48 48 * Compares two ASCII Strings s1 and s2, ignoring case.
49 49 */
50 50 public static boolean caseIgnoreMatch(String s1, String s2) {
51 51 if (s1 == s2) {
52 52 return true;
53 53 }
54 54
55 55 int len = s1.length();
56 56 if (len != s2.length()) {
57 57 return false;
58 58 }
59 59
60 60 for (int i = 0; i < len; i++) {
61 61 char c1 = s1.charAt(i);
62 62 char c2 = s2.charAt(i);
63 63 if (c1 != c2 && toLower(c1) != toLower(c2)) {
64 64 return false;
65 65 }
66 66 }
67 67 return true;
68 68 }
69 69
70 70 static int caseIgnoreCompare(String s1, String s2) {
71 71 if (s1 == s2) {
72 72 return 0;
73 73 }
74 74 return toLowerString(s1).compareTo(toLowerString(s2));
75 75 }
76 76
77 77 static char toUpper(char c) {
78 78 return isLower(c) ? (char)(c - 0x20) : c;
79 79 }
80 80
81 81 static char toLower(char c) {
82 82 return isUpper(c) ? (char)(c + 0x20) : c;
83 83 }
84 84
85 85 /**
86 86 * Converts the given ASCII String to lower-case.
87 87 */
88 88 public static String toLowerString(String s) {
89 89 int len = s.length();
90 90 int idx = 0;
91 91 for (; idx < len; idx++) {
92 92 if (isUpper(s.charAt(idx))) {
93 93 break;
94 94 }
95 95 }
96 96 if (idx == len) {
97 97 return s;
98 98 }
99 99
100 100 char[] buf = new char[len];
101 101 for (int i = 0; i < len; i++) {
102 102 char c = s.charAt(i);
103 103 buf[i] = (i < idx) ? c : toLower(c);
104 104 }
105 105 return new String(buf);
106 106 }
107 107
108 108 static String toUpperString(String s) {
109 109 int len = s.length();
110 110 int idx = 0;
111 111 for (; idx < len; idx++) {
112 112 if (isLower(s.charAt(idx))) {
113 113 break;
114 114 }
115 115 }
116 116 if (idx == len) {
117 117 return s;
118 118 }
119 119
120 120 char[] buf = new char[len];
121 121 for (int i = 0; i < len; i++) {
122 122 char c = s.charAt(i);
123 123 buf[i] = (i < idx) ? c : toUpper(c);
124 124 }
125 125 return new String(buf);
126 126 }
127 127
128 128 static String toTitleString(String s) {
129 129 int len;
130 130 if ((len = s.length()) == 0) {
131 131 return s;
132 132 }
133 133 int idx = 0;
134 134 if (!isLower(s.charAt(idx))) {
135 135 for (idx = 1; idx < len; idx++) {
136 136 if (isUpper(s.charAt(idx))) {
137 137 break;
138 138 }
139 139 }
140 140 }
141 141 if (idx == len) {
142 142 return s;
143 143 }
144 144
145 145 char[] buf = new char[len];
146 146 for (int i = 0; i < len; i++) {
147 147 char c = s.charAt(i);
148 148 if (i == 0 && idx == 0) {
149 149 buf[i] = toUpper(c);
150 150 } else if (i < idx) {
151 151 buf[i] = c;
152 152 } else {
153 153 buf[i] = toLower(c);
154 154 }
155 155 }
156 156 return new String(buf);
157 157 }
158 158
159 159 private static boolean isUpper(char c) {
160 160 return c >= 'A' && c <= 'Z';
161 161 }
162 162
163 163 private static boolean isLower(char c) {
164 164 return c >= 'a' && c <= 'z';
165 165 }
166 166
167 167 static boolean isAlpha(char c) {
168 168 return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
169 169 }
170 170
171 171 static boolean isAlphaString(String s) {
172 172 int len = s.length();
173 173 for (int i = 0; i < len; i++) {
174 174 if (!isAlpha(s.charAt(i))) {
175 175 return false;
176 176 }
177 177 }
178 178 return true;
179 179 }
180 180
181 181 static boolean isNumeric(char c) {
182 182 return (c >= '0' && c <= '9');
183 183 }
184 184
185 185 static boolean isNumericString(String s) {
186 186 int len = s.length();
187 187 for (int i = 0; i < len; i++) {
188 188 if (!isNumeric(s.charAt(i))) {
↓ open down ↓ |
188 lines elided |
↑ open up ↑ |
189 189 return false;
190 190 }
191 191 }
192 192 return true;
193 193 }
194 194
195 195 static boolean isAlphaNumeric(char c) {
196 196 return isAlpha(c) || isNumeric(c);
197 197 }
198 198
199 - static boolean isAlphaNumericString(String s) {
199 + public static boolean isAlphaNumericString(String s) {
200 200 int len = s.length();
201 201 for (int i = 0; i < len; i++) {
202 202 if (!isAlphaNumeric(s.charAt(i))) {
203 203 return false;
204 204 }
205 205 }
206 206 return true;
207 207 }
208 208
209 209 static boolean isEmpty(String str) {
210 210 return str == null || str.length() == 0;
211 211 }
212 212
213 213 static boolean isEmpty(Set<?> set) {
214 214 return set == null || set.isEmpty();
215 215 }
216 216
217 217 static boolean isEmpty(Map<?, ?> map) {
218 218 return map == null || map.isEmpty();
219 219 }
220 220
221 221 static boolean isEmpty(List<?> list) {
222 222 return list == null || list.isEmpty();
223 223 }
224 224 }
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX