From f0156c183b034bb6bb041930c3dbaacce2cd919d Mon Sep 17 00:00:00 2001
From: "Steven R. Loomis" <srl@icu-project.org>
Date: Wed, 21 Sep 2016 23:52:53 +0000
Subject: [PATCH] ICU-12701 additional porting issues.

X-SVN-Rev: 39323
---
 icu4c/source/i18n/dtitvfmt.cpp             |  8 ++---
 icu4c/source/i18n/dtptngen.cpp             |  2 +-
 icu4c/source/test/cintltst/cdattst.c       |  2 +-
 icu4c/source/test/intltest/dtfmttst.cpp    |  2 +-
 icu4c/source/test/intltest/dtifmtts.cpp    | 38 ++++++----------------
 icu4c/source/test/intltest/measfmttest.cpp |  8 +++--
 icu4c/source/test/intltest/strtest.cpp     |  9 +++++
 icu4c/source/test/intltest/strtest.h       |  1 +
 8 files changed, 32 insertions(+), 38 deletions(-)

diff --git a/icu4c/source/i18n/dtitvfmt.cpp b/icu4c/source/i18n/dtitvfmt.cpp
index 15c80e6d926..48068d3cc2d 100644
--- a/icu4c/source/i18n/dtitvfmt.cpp
+++ b/icu4c/source/i18n/dtitvfmt.cpp
@@ -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;
diff --git a/icu4c/source/i18n/dtptngen.cpp b/icu4c/source/i18n/dtptngen.cpp
index c5fead15f1e..f57f08fe1f5 100644
--- a/icu4c/source/i18n/dtptngen.cpp
+++ b/icu4c/source/i18n/dtptngen.cpp
@@ -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;
diff --git a/icu4c/source/test/cintltst/cdattst.c b/icu4c/source/test/cintltst/cdattst.c
index 3faa32ce4ed..c1137aa1c0a 100644
--- a/icu4c/source/test/cintltst/cdattst.c
+++ b/icu4c/source/test/cintltst/cdattst.c
@@ -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");
         }
diff --git a/icu4c/source/test/intltest/dtfmttst.cpp b/icu4c/source/test/intltest/dtfmttst.cpp
index f0e00d6c783..0bba757a253 100644
--- a/icu4c/source/test/intltest/dtfmttst.cpp
+++ b/icu4c/source/test/intltest/dtfmttst.cpp
@@ -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);
diff --git a/icu4c/source/test/intltest/dtifmtts.cpp b/icu4c/source/test/intltest/dtifmtts.cpp
index 30c2cff9718..095eb3f60bd 100644
--- a/icu4c/source/test/intltest/dtifmtts.cpp
+++ b/icu4c/source/test/intltest/dtifmtts.cpp
@@ -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;
     }
 }
diff --git a/icu4c/source/test/intltest/measfmttest.cpp b/icu4c/source/test/intltest/measfmttest.cpp
index 08ad11c7d32..510146b0146 100644
--- a/icu4c/source/test/intltest/measfmttest.cpp
+++ b/icu4c/source/test/intltest/measfmttest.cpp
@@ -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(
diff --git a/icu4c/source/test/intltest/strtest.cpp b/icu4c/source/test/intltest/strtest.cpp
index 1512c2b51cc..f621631c5a9 100644
--- a/icu4c/source/test/intltest/strtest.cpp
+++ b/icu4c/source/test/intltest/strtest.cpp
@@ -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));
+}
diff --git a/icu4c/source/test/intltest/strtest.h b/icu4c/source/test/intltest/strtest.h
index bcfd38acf38..d72834e17e9 100644
--- a/icu4c/source/test/intltest/strtest.h
+++ b/icu4c/source/test/intltest/strtest.h
@@ -48,6 +48,7 @@ private:
     void TestSTLCompatibility();
     void TestCharString();
     void TestCStr();
+    void Testctou();
 };
 
 #endif
-- 
2.40.0