From: Mark Davis Date: Mon, 15 Jul 2013 13:40:57 +0000 (+0000) Subject: ICU-10187 Fix test (regions that leaked () in CLDR). X-Git-Tag: milestone-59-0-1~2765 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7d4180dc4d2b6bc348b1b160c211d838308e1379;p=icu ICU-10187 Fix test (regions that leaked () in CLDR). X-SVN-Rev: 33923 --- diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/LocaleDisplayNamesImpl.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/LocaleDisplayNamesImpl.java index 24dfb174155..546a38f2bce 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/LocaleDisplayNamesImpl.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/LocaleDisplayNamesImpl.java @@ -337,23 +337,27 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames { } if (resultName == null) { - resultName = localeIdName(lang); + resultName = localeIdName(lang) + .replace(formatOpenParen, formatReplaceOpenParen) + .replace(formatCloseParen, formatReplaceCloseParen); } StringBuilder buf = new StringBuilder(); if (hasScript) { // first element, don't need appendWithSep - buf.append(scriptDisplayNameInContext(script)); + buf.append(scriptDisplayNameInContext(script) + .replace(formatOpenParen, formatReplaceOpenParen) + .replace(formatCloseParen, formatReplaceCloseParen)); } if (hasCountry) { - String regionDisplayName = regionDisplayName(country); - regionDisplayName = regionDisplayName + appendWithSep(regionDisplayName(country) .replace(formatOpenParen, formatReplaceOpenParen) - .replace(formatCloseParen, formatReplaceCloseParen); - appendWithSep(regionDisplayName, buf); + .replace(formatCloseParen, formatReplaceCloseParen), buf); } if (hasVariant) { - appendWithSep(variantDisplayName(variant), buf); + appendWithSep(variantDisplayName(variant) + .replace(formatOpenParen, formatReplaceOpenParen) + .replace(formatCloseParen, formatReplaceCloseParen), buf); } Iterator keys = locale.getKeywords(); @@ -361,8 +365,12 @@ public class LocaleDisplayNamesImpl extends LocaleDisplayNames { while (keys.hasNext()) { String key = keys.next(); String value = locale.getKeywordValue(key); - String keyDisplayName = keyDisplayName(key); - String valueDisplayName = keyValueDisplayName(key, value); + String keyDisplayName = keyDisplayName(key) + .replace(formatOpenParen, formatReplaceOpenParen) + .replace(formatCloseParen, formatReplaceCloseParen); + String valueDisplayName = keyValueDisplayName(key, value) + .replace(formatOpenParen, formatReplaceOpenParen) + .replace(formatCloseParen, formatReplaceCloseParen); if (!valueDisplayName.equals(value)) { appendWithSep(valueDisplayName, buf); } else if (!key.equals(keyDisplayName)) { diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java index ac89234de43..83f74a3fe44 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java @@ -1084,27 +1084,31 @@ public class ULocaleTest extends TestFmwk { } private boolean checkName(String name, String language, String script, String country, String variant, ULocale dl) { - if (language.length() > 0 && name.indexOf(language) == -1) { - errln("loc: " + dl + " name '" + name + "' does not contain language '" + language + "'"); + if (!checkInclusion(dl, name, language, "language")) { return false; } - if (script.length() > 0 && name.indexOf(script) == -1) { - errln("loc: " + dl + " name '" + name + "' does not contain script '" + script + "'"); + if (!checkInclusion(dl, name, script, "script")) { return false; } - if (country.length() > 0 && name.indexOf(country) == -1) { - String country2 = country.replace('(', '[').replace(')',']').replace('(', '[').replace(')',']'); + if (!checkInclusion(dl, name, country, "country")) { + return false; + } + if (!checkInclusion(dl, name, variant, "variant")) { + return false; + } + return true; + } + + private boolean checkInclusion(ULocale dl, String name, String substring, String substringName) { + if (substring.length() > 0 && name.indexOf(substring) == -1) { + String country2 = substring.replace('(', '[').replace(')',']').replace('(', '[').replace(')',']'); if (name.indexOf(country2) == -1) { - errln("loc: " + dl + " name '" + name + "' does not contain country '" + country + "'"); + errln("loc: " + dl + " name '" + name + "' does not contain " + + substringName + + " '" + substring + "'"); return false; -// } else { -// System.out.println("loc: " + dl + " name '" + name + "' does not contain country '" + country + "'"); } } - if (variant.length() > 0 && name.indexOf(variant) == -1) { - errln("loc: " + dl + " name '" + name + "' does not contain variant '" + variant + "'"); - return false; - } return true; } @@ -1125,7 +1129,6 @@ public class ULocaleTest extends TestFmwk { script = ULocale.getDisplayScriptInContext(localeID, testLocale); country = ULocale.getDisplayCountry(localeID, testLocale); variant = ULocale.getDisplayVariant(localeID, testLocale); - if (!checkName(name, language, script, country, variant, new ULocale(testLocale))) { break; }