if (_variants.isEmpty()) {
_variants = new ArrayList<String>(3);
}
- _variants.add(s);
+ // Ignore repeated variant
+ s = s.toUpperCase();
+ if (!_variants.contains(s)) {
+ _variants.add(s);
+ }
sts._parseLength = itr.currentEnd();
itr.next();
}
String s = itr.current();
if (isExtensionSingleton(s)) {
int start = itr.currentStart();
- String singleton = s;
+ String singleton = s.toLowerCase();
StringBuilder sb = new StringBuilder(singleton);
itr.next();
if (_extensions.size() == 0) {
_extensions = new ArrayList<String>(4);
}
- _extensions.add(sb.toString());
+ // Ignore the extension if it is already in _extensions.
+ boolean alreadyHas = false;
+ for (String extension : _extensions) {
+ alreadyHas |= extension.charAt(0) == sb.charAt(0);
+ }
+ if (!alreadyHas) {
+ _extensions.add(sb.toString());
+ }
found = true;
} else {
break;
}
}
+ @Test
+ public void TestForLanguageTagBug20148() {
+ ULocale uloc = ULocale.forLanguageTag("de-DE-1901-1901");
+ assertEquals("ULocale.forLanguageTag(\"de-DE-1901-1901\") ",
+ "de_DE_1901", uloc.getName());
+
+ uloc = ULocale.forLanguageTag("de-DE-1aBc-1AbC");
+ assertEquals("ULocale.forLanguageTag(\"de-DE-1aBc-1AbC\") ",
+ "de_DE_1ABC", uloc.getName());
+
+ uloc = ULocale.forLanguageTag("en-a-bbb-a-ccc");
+ assertEquals("ULocale.forLanguageTag(\"en-a-bbb-a-ccc\") ",
+ "en@a=bbb", uloc.getName());
+
+ uloc = ULocale.forLanguageTag("en-A-bbb-a-ccc");
+ assertEquals("ULocale.forLanguageTag(\"en-A-bbb-a-ccc\") ",
+ "en@a=bbb", uloc.getName());
+ }
+
@Test
public void TestForLanguageTagBug13776() {
final Locale backupDefault = Locale.getDefault();