ICU-12701 additional porting issues.

X-SVN-Rev: 39323
This commit is contained in:
Steven R. Loomis 2016-09-21 23:52:53 +00:00
parent da8e954004
commit f0156c183b
8 changed files with 32 additions and 38 deletions

View File

@ -1267,11 +1267,11 @@ DateIntervalFormat::splitPatternInto2Part(const UnicodeString& intervalPattern)
}
count = 0;
}
if (ch == '\'') {
if (ch == 0x0027 /*'*/) {
// Consecutive single quotes are a single quote literal,
// either outside of quotes or between quotes
if ((i+1) < intervalPattern.length() &&
intervalPattern.charAt(i+1) == '\'') {
intervalPattern.charAt(i+1) == 0x0027 /*'*/) {
++i;
} else {
inQuote = ! inQuote;
@ -1471,10 +1471,10 @@ DateIntervalFormat::adjustFieldWidth(const UnicodeString& inputSkeleton,
}
count = 0;
}
if (ch == '\'') {
if (ch == 0x0027 /*'*/) {
// Consecutive single quotes are a single quote literal,
// either outside of quotes or between quotes
if ((i+1) < adjustedPtn.length() && adjustedPtn.charAt(i+1) == '\'') {
if ((i+1) < adjustedPtn.length() && adjustedPtn.charAt(i+1) == 0x0027 /* ' */) {
++i;
} else {
inQuote = ! inQuote;

View File

@ -2020,7 +2020,7 @@ FormatParser::getCanonicalIndex(const UnicodeString& s, UBool strict) {
}
int32_t i = 0;
int32_t bestRow = -1;
while (dtTypes[i].patternChar != '\0') {
while (dtTypes[i].patternChar != 0x0000) {
if ( dtTypes[i].patternChar != ch ) {
++i;
continue;

View File

@ -1641,7 +1641,7 @@ static void TestOverrideNumberFormat(void) {
overrideFmt = NULL; // no longer valid
assertSuccess("udat_setNumberFormatForField()", &status);
getter_result = udat_getNumberFormatForField(fmt, 'd');
getter_result = udat_getNumberFormatForField(fmt, 0x0064 /*'d'*/);
if(getter_result == NULL) {
log_err("FAIL: udat_getNumberFormatForField did not return a valid pointer\n");
}

View File

@ -4727,7 +4727,7 @@ void DateFormatTest::TestNumberFormatOverride() {
fmt->adoptNumberFormat(fields, check_nf, status);
assertSuccess("adoptNumberFormat check_nf", status);
const NumberFormat* get_nf = fmt->getNumberFormatForField('M');
const NumberFormat* get_nf = fmt->getNumberFormatForField((UChar)0x004D /*'M'*/);
if (get_nf != check_nf) errln("FAIL: getter and setter do not work");
}
NumberFormat* check_nf = NumberFormat::createInstance(Locale("en_US"), status);

View File

@ -966,7 +966,8 @@ void DateIntervalFormatTest::testFormat() {
"de", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "EEEEdMMM", "Mittwoch, 10. Jan.",
/* Following is an important test, because the 'h' in 'Uhr' is interpreted as a pattern
if not escaped properly. */
"de", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "h", "10 Uhr vorm. \\u2013 2 Uhr nachm.",
"de", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "H", "10\\u201314 Uhr",
@ -1051,17 +1052,12 @@ void DateIntervalFormatTest::expect(const char** data, int32_t data_length) {
const char* pattern = data[0];
i++;
#ifdef DTIFMTTS_DEBUG
char result[1000];
char mesg[1000];
sprintf(mesg, "locale: %s\n", locName);
PRINTMESG(mesg);
#endif
while (i<data_length) {
const char* locName = data[i++];
Locale loc(locName);
SimpleDateFormat ref(pattern, loc, ec);
logln( "case %d, locale: %s\n", (i-1)/5, locName);
if (U_FAILURE(ec)) {
dataerrln("contruct SimpleDateFormat in expect failed: %s", u_errorName(ec));
return;
@ -1069,39 +1065,25 @@ void DateIntervalFormatTest::expect(const char** data, int32_t data_length) {
// 'f'
const char* datestr = data[i++];
const char* datestr_2 = data[i++];
#ifdef DTIFMTTS_DEBUG
sprintf(mesg, "original date: %s - %s\n", datestr, datestr_2);
PRINTMESG(mesg)
#endif
logln("original date: %s - %s\n", datestr, datestr_2);
UDate date = ref.parse(ctou(datestr), ec);
if (!assertSuccess("parse 1st data in expect", ec)) return;
UDate date_2 = ref.parse(ctou(datestr_2), ec);
if (!assertSuccess("parse 2nd data in expect", ec)) return;
DateInterval dtitv(date, date_2);
const UnicodeString& oneSkeleton = data[i++];
const UnicodeString& oneSkeleton(ctou(data[i++]));
DateIntervalFormat* dtitvfmt = DateIntervalFormat::createInstance(oneSkeleton, loc, ec);
if (!assertSuccess("createInstance(skeleton) in expect", ec)) return;
FieldPosition pos(FieldPosition::DONT_CARE);
dtitvfmt->format(&dtitv, str.remove(), pos, ec);
if (!assertSuccess("format in expect", ec)) return;
assertEquals((UnicodeString)"\"" + locName + "\\" + oneSkeleton + "\\" + datestr + "\\" + datestr_2 + "\"", ctou(data[i++]), str);
assertEquals((UnicodeString)"\"" + locName + "\\" + oneSkeleton + "\\" + ctou(datestr) + "\\" + ctou(datestr_2) + "\"", ctou(data[i++]), str);
#ifdef DTIFMTTS_DEBUG
str.extract(0, str.length(), result, "UTF-8");
sprintf(mesg, "interval date: %s\n", result);
std::cout << "//";
PRINTMESG(mesg)
std::cout << "\"" << locName << "\", "
<< "\"" << datestr << "\", "
<< "\"" << datestr_2 << "\", ";
printUnicodeString(oneSkeleton);
printUnicodeString(str);
std::cout << "\n\n";
#endif
logln("interval date:" + str + "\"" + locName + "\", "
+ "\"" + datestr + "\", "
+ "\"" + datestr_2 + "\", " + oneSkeleton);
delete dtitvfmt;
}
}

View File

@ -1707,12 +1707,14 @@ void MeasureFormatTest::TestGram() {
}
void MeasureFormatTest::TestCurrencies() {
UChar USD[] = {'U', 'S', 'D', 0};
UChar USD[4];
u_uastrcpy(USD, "USD");
UErrorCode status = U_ZERO_ERROR;
CurrencyAmount USD_1(1.0, USD, status);
assertEquals("Currency Code", USD, USD_1.getISOCurrency());
CurrencyAmount USD_2(2.0, USD, status);
CurrencyAmount USD_NEG_1(-1.0, USD, status);
if (!assertSuccess("Error creating measures", status)) {
if (!assertSuccess("Error creating currencies", status)) {
return;
}
Locale en("en");
@ -2081,7 +2083,7 @@ void MeasureFormatTest::verifyFormatWithPrefix(
if (!assertSuccess("Error formatting", status)) {
return;
}
assertEquals(description, UnicodeString(expected).unescape(), result);
assertEquals(description, ctou(expected), result);
}
void MeasureFormatTest::verifyFormat(

View File

@ -172,6 +172,7 @@ void StringTest::runIndexedTest(int32_t index, UBool exec, const char *&name, ch
TESTCASE_AUTO(TestStringByteSink);
TESTCASE_AUTO(TestCharString);
TESTCASE_AUTO(TestCStr);
TESTCASE_AUTO(Testctou);
TESTCASE_AUTO_END;
}
@ -545,3 +546,11 @@ StringTest::TestCStr() {
errln("%s:%d CStr(s)() failed. Expected \"%s\", got \"%s\"", __FILE__, __LINE__, cs, CStr(us)());
}
}
void
StringTest::Testctou() {
const char *cs = "Fa\\u0127mu";
UnicodeString u = ctou(cs);
assertEquals("Testing unescape@0", (int32_t)0x0046, u.charAt(0));
assertEquals("Testing unescape@2", (int32_t)295, u.charAt(2));
}

View File

@ -48,6 +48,7 @@ private:
void TestSTLCompatibility();
void TestCharString();
void TestCStr();
void Testctou();
};
#endif