mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-3636 Fix parsing of variant and keyword values as the third and fourth parameter when no country is present.
X-SVN-Rev: 14645
This commit is contained in:
parent
a66aa4cf27
commit
ef91ad8baf
3 changed files with 40 additions and 6 deletions
|
@ -394,7 +394,15 @@ Locale::Locale( const char * newLanguage,
|
|||
|
||||
if ( ksize != 0)
|
||||
{
|
||||
*p++ = '@';
|
||||
if (uprv_strchr(newKeywords, '=')) {
|
||||
*p++ = '@'; /* keyword parsing */
|
||||
}
|
||||
else {
|
||||
*p++ = '_'; /* Variant parsing with a script */
|
||||
if ( vsize == 0) {
|
||||
*p++ = '_'; /* No country found */
|
||||
}
|
||||
}
|
||||
uprv_strcpy(p, newKeywords);
|
||||
p += ksize;
|
||||
}
|
||||
|
@ -550,7 +558,7 @@ Locale& Locale::init(const char* localeID)
|
|||
break; // error: one of the fields is too long
|
||||
}
|
||||
|
||||
variantField = 0;
|
||||
variantField = 2; /* Usually the 2nd one, except when a script is used. */
|
||||
if (fieldLen[0] > 0) {
|
||||
/* We have a language */
|
||||
uprv_memcpy(language, fullName, fieldLen[0]);
|
||||
|
@ -571,7 +579,6 @@ Locale& Locale::init(const char* localeID)
|
|||
/* We have a country and no script */
|
||||
uprv_memcpy(country, field[1], fieldLen[1]);
|
||||
country[fieldLen[1]] = 0;
|
||||
variantField = 2;
|
||||
}
|
||||
if (variantField > 0 && fieldLen[variantField] > 0) {
|
||||
/* We have a variant */
|
||||
|
|
|
@ -226,11 +226,12 @@ void LocaleTest::runIndexedTest( int32_t index, UBool exec, const char* &name, c
|
|||
TESTCASE(25, TestKeywordVariantParsing);
|
||||
TESTCASE(26, TestGetBaseName);
|
||||
TESTCASE(27, TestGetLocale);
|
||||
TESTCASE(28, TestVariantWithOutCountry);
|
||||
|
||||
// keep the last index in sync with the condition in default:
|
||||
|
||||
default:
|
||||
if (index <= 27) { // keep this in sync with the last index!
|
||||
if (index <= 28) { // keep this in sync with the last index!
|
||||
name = "(test omitted by !UCONFIG_NO_FORMATTING)";
|
||||
} else {
|
||||
name = "";
|
||||
|
@ -1732,7 +1733,7 @@ void LocaleTest::_checklocs(const char* label,
|
|||
}
|
||||
}
|
||||
|
||||
void LocaleTest::TestGetLocale() {
|
||||
void LocaleTest::TestGetLocale(void) {
|
||||
UErrorCode ec = U_ZERO_ERROR;
|
||||
const char *req;
|
||||
Locale valid, actual, reqLoc;
|
||||
|
@ -1937,3 +1938,27 @@ void LocaleTest::TestGetLocale() {
|
|||
delete coll;
|
||||
#endif
|
||||
}
|
||||
|
||||
void LocaleTest::TestVariantWithOutCountry(void) {
|
||||
Locale loc("en","","POSIX");
|
||||
if (0 != strcmp(loc.getVariant(), "POSIX")) {
|
||||
errln("FAIL: en__POSIX didn't get parsed correctly");
|
||||
}
|
||||
Locale loc2("en","","FOUR");
|
||||
if (0 != strcmp(loc2.getVariant(), "FOUR")) {
|
||||
errln("FAIL: en__FOUR didn't get parsed correctly");
|
||||
}
|
||||
Locale loc3("en","Latn","","FOUR");
|
||||
if (0 != strcmp(loc3.getVariant(), "FOUR")) {
|
||||
errln("FAIL: en_Latn__FOUR didn't get parsed correctly");
|
||||
}
|
||||
Locale loc4("","Latn","","FOUR");
|
||||
if (0 != strcmp(loc4.getVariant(), "FOUR")) {
|
||||
errln("FAIL: _Latn__FOUR didn't get parsed correctly");
|
||||
}
|
||||
Locale loc5("","Latn","US","FOUR");
|
||||
if (0 != strcmp(loc5.getVariant(), "FOUR")) {
|
||||
errln("FAIL: _Latn_US_FOUR didn't get parsed correctly");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,9 @@ public:
|
|||
|
||||
void TestSetIsBogus(void);
|
||||
|
||||
void TestGetLocale();
|
||||
void TestGetLocale(void);
|
||||
|
||||
void TestVariantWithOutCountry(void);
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
static UDate date(int32_t y, int32_t m, int32_t d, int32_t hr = 0, int32_t min = 0, int32_t sec = 0);
|
||||
|
|
Loading…
Add table
Reference in a new issue