const UChar *pattern;
int32_t patLen = 0;
int32_t sub0Pos, sub1Pos;
+
+ UChar formatOpenParen = 0x0028; // (
+ UChar formatReplaceOpenParen = 0x005B; // [
+ UChar formatCloseParen = 0x0029; // )
+ UChar formatReplaceCloseParen = 0x005D; // ]
UBool haveLang = TRUE; /* assume true, set false if we find we don't have
a lang component in the locale */
patLen=defaultPatLen;
sub0Pos=defaultSub0Pos;
sub1Pos=defaultSub1Pos;
+ // use default formatOpenParen etc. set above
} else { /* non-default pattern */
UChar *p0=u_strstr(pattern, sub0);
UChar *p1=u_strstr(pattern, sub1);
int32_t t=sub0Pos; sub0Pos=sub1Pos; sub1Pos=t;
langi=1;
}
+ if (u_strchr(pattern, 0xFF08) != NULL) {
+ formatOpenParen = 0xFF08; // fullwidth (
+ formatReplaceOpenParen = 0xFF3B; // fullwidth [
+ formatCloseParen = 0xFF09; // fullwidth )
+ formatReplaceCloseParen = 0xFF3D; // fullwidth ]
+ }
}
/* We loop here because there is one case in which after the first pass we could need to
if (len>0) {
/* we addeed a component, so add separator and write it if there's room. */
if(len+sepLen<=cap) {
- p+=len;
+ const UChar * plimit = p + len;
+ for (; p < plimit; p++) {
+ if (*p == formatOpenParen) {
+ *p = formatReplaceOpenParen;
+ } else if (*p == formatCloseParen) {
+ *p = formatReplaceCloseParen;
+ }
+ }
for(int32_t i=0;i<sepLen;++i) {
*p++=separator[i];
}
MessageFormat *format;
MessageFormat *keyTypeFormat;
UDisplayContext capitalizationContext;
+ UnicodeString formatOpenParen;
+ UnicodeString formatReplaceOpenParen;
+ UnicodeString formatCloseParen;
+ UnicodeString formatReplaceCloseParen;
// Constants for capitalization context usage types.
enum CapContextUsage {
pattern = UnicodeString("{0} ({1})", -1, US_INV);
}
format = new MessageFormat(pattern, status);
+ if (pattern.indexOf((UChar)0xFF08) >= 0) {
+ formatOpenParen.setTo(0xFF08); // fullwidth (
+ formatReplaceOpenParen.setTo(0xFF3B); // fullwidth [
+ formatCloseParen.setTo(0xFF09); // fullwidth )
+ formatReplaceCloseParen.setTo(0xFF3D); // fullwidth ]
+ } else {
+ formatOpenParen.setTo(0x0028); // (
+ formatReplaceOpenParen.setTo(0x005B); // [
+ formatCloseParen.setTo(0x0029); // )
+ formatReplaceCloseParen.setTo(0x005D); // ]
+ }
UnicodeString ktPattern;
langData.get("localeDisplayPattern", "keyTypePattern", ktPattern);
if (hasVariant) {
appendWithSep(resultRemainder, variantDisplayName(variant, temp));
}
+ resultRemainder.findAndReplace(formatOpenParen, formatReplaceOpenParen);
+ resultRemainder.findAndReplace(formatCloseParen, formatReplaceCloseParen);
e = locale.createKeywords(status);
if (e && U_SUCCESS(status)) {
while ((key = e->next((int32_t *)0, status)) != NULL) {
locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status);
keyDisplayName(key, temp);
+ temp.findAndReplace(formatOpenParen, formatReplaceOpenParen);
+ temp.findAndReplace(formatCloseParen, formatReplaceCloseParen);
keyValueDisplayName(key, value, temp2);
+ temp2.findAndReplace(formatOpenParen, formatReplaceOpenParen);
+ temp2.findAndReplace(formatCloseParen, formatReplaceCloseParen);
if (temp2 != UnicodeString(value, -1, US_INV)) {
appendWithSep(resultRemainder, temp2);
} else if (temp != UnicodeString(key, -1, US_INV)) {
#include "unicode/ustring.h"
#include "unicode/utypes.h"
#include "unicode/ulocdata.h"
+#include "unicode/uldnames.h"
#include "unicode/parseerr.h" /* may not be included with some uconfig switches */
#include "udbgutil.h"
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
static void TestNonexistentLanguageExemplars(void);
static void TestLocDataErrorCodeChaining(void);
static void TestLanguageExemplarsFallbacks(void);
+static void TestDisplayNameBrackets(void);
static void TestUnicodeDefines(void);
TESTCASE(TestTrailingNull);
TESTCASE(TestUnicodeDefines);
TESTCASE(TestEnglishExemplarCharacters);
+ TESTCASE(TestDisplayNameBrackets);
}
cleanUpDataTable();
}
+/*------------------------------
+ * TestDisplayNameBrackets
+ */
+
+typedef struct {
+ const char * displayLocale;
+ const char * namedRegion;
+ const char * namedLocale;
+ const char * regionName;
+ const char * localeName;
+} DisplayNameBracketsItem;
+
+static const DisplayNameBracketsItem displayNameBracketsItems[] = {
+ { "en", "CC", "en_CC", "Cocos (Keeling) Islands", "English (Cocos [Keeling] Islands)" },
+ { "en", "MM", "my_MM", "Myanmar (Burma)", "Burmese (Myanmar [Burma])" },
+ { "en", "MM", "my_Mymr_MM", "Myanmar (Burma)", "Burmese (Myanmar, Myanmar [Burma])" },
+ { "zh", "CC", "en_CC", "\\u79D1\\u79D1\\u65AF\\uFF08\\u57FA\\u6797\\uFF09\\u7FA4\\u5C9B", "\\u82F1\\u6587\\uFF08\\u79D1\\u79D1\\u65AF\\uFF3B\\u57FA\\u6797\\uFF3D\\u7FA4\\u5C9B\\uFF09" },
+ { "zh", "CG", "fr_CG", "\\u521A\\u679C\\uFF08\\u5E03\\uFF09", "\\u6CD5\\u6587\\uFF08\\u521A\\u679C\\uFF3B\\u5E03\\uFF3D\\uFF09" },
+ { NULL, NULL, NULL, NULL, NULL }
+};
+
+enum { kDisplayNameBracketsMax = 128 };
+
+static void TestDisplayNameBrackets()
+{
+ const DisplayNameBracketsItem * itemPtr = displayNameBracketsItems;
+ for (; itemPtr->displayLocale != NULL; itemPtr++) {
+ ULocaleDisplayNames * uldn;
+ UErrorCode status;
+ UChar expectRegionName[kDisplayNameBracketsMax];
+ UChar expectLocaleName[kDisplayNameBracketsMax];
+ UChar getName[kDisplayNameBracketsMax];
+ int32_t ulen;
+
+ (void) u_unescape(itemPtr->regionName, expectRegionName, kDisplayNameBracketsMax);
+ (void) u_unescape(itemPtr->localeName, expectLocaleName, kDisplayNameBracketsMax);
+
+ status = U_ZERO_ERROR;
+ ulen = uloc_getDisplayCountry(itemPtr->namedLocale, itemPtr->displayLocale, getName, kDisplayNameBracketsMax, &status);
+ if ( U_FAILURE(status) || u_strcmp(getName, expectRegionName) != 0 ) {
+ log_err("uloc_getDisplayCountry for displayLocale %s and namedLocale %s returns unexpected name or status %s\n", itemPtr->displayLocale, itemPtr->namedLocale, myErrorName(status));
+ }
+
+ status = U_ZERO_ERROR;
+ ulen = uloc_getDisplayName(itemPtr->namedLocale, itemPtr->displayLocale, getName, kDisplayNameBracketsMax, &status);
+ if ( U_FAILURE(status) || u_strcmp(getName, expectLocaleName) != 0 ) {
+ log_err("uloc_getDisplayName for displayLocale %s and namedLocale %s returns unexpected name or status %s\n", itemPtr->displayLocale, itemPtr->namedLocale, myErrorName(status));
+ }
+
+ status = U_ZERO_ERROR;
+ uldn = uldn_open(itemPtr->displayLocale, ULDN_STANDARD_NAMES, &status);
+ if (U_SUCCESS(status)) {
+ status = U_ZERO_ERROR;
+ ulen = uldn_regionDisplayName(uldn, itemPtr->namedRegion, getName, kDisplayNameBracketsMax, &status);
+ if ( U_FAILURE(status) || u_strcmp(getName, expectRegionName) != 0 ) {
+ log_err("uldn_regionDisplayName for displayLocale %s and namedRegion %s returns unexpected name or status %s\n", itemPtr->displayLocale, itemPtr->namedRegion, myErrorName(status));
+ }
+
+ status = U_ZERO_ERROR;
+ ulen = uldn_localeDisplayName(uldn, itemPtr->namedLocale, getName, kDisplayNameBracketsMax, &status);
+ if ( U_FAILURE(status) || u_strcmp(getName, expectLocaleName) != 0 ) {
+ log_err("uldn_localeDisplayName for displayLocale %s and namedLocale %s returns unexpected name or status %s\n", itemPtr->displayLocale, itemPtr->namedLocale, myErrorName(status));
+ }
+
+ uldn_close(uldn);
+ } else {
+ log_data_err("uldn_open fails for displayLocale %s, status=%s\n", itemPtr->displayLocale, u_errorName(status));
+ }
+ }
+}
+
+/*------------------------------
+ * TestISOFunctions
+ */
+
#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
/* test for uloc_getISOLanguages, uloc_getISOCountries */
static void TestISOFunctions()