From: Yoshito Umaoka Date: Thu, 26 Oct 2017 22:13:13 +0000 (+0000) Subject: ICU-13446 Fixed Chakma date format fractional seconds parsing problem. Removed logKno... X-Git-Tag: release-61-rc~194 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4b67416113ef638f39b7070dc7e0e5ac3b1774d3;p=icu ICU-13446 Fixed Chakma date format fractional seconds parsing problem. Removed logKnownIssue from TestTimeZoneFormat. X-SVN-Rev: 40647 --- diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp index c4d325cc485..27fbbd8f7a9 100644 --- a/icu4c/source/i18n/smpdtfmt.cpp +++ b/icu4c/source/i18n/smpdtfmt.cpp @@ -3202,7 +3202,7 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC case UDAT_FRACTIONAL_SECOND_FIELD: // Fractional seconds left-justify - i = pos.getIndex() - start; + i = countDigits(text, start, pos.getIndex()); if (i < 3) { while (i < 3) { value *= 10; @@ -3728,6 +3728,19 @@ void SimpleDateFormat::parseInt(const UnicodeString& text, } } +int32_t SimpleDateFormat::countDigits(const UnicodeString& text, int32_t start, int32_t end) const { + int32_t numDigits = 0; + int32_t idx = start; + while (idx < end) { + UChar32 cp = text.char32At(idx); + if (u_isdigit(cp)) { + numDigits++; + } + idx += U16_LENGTH(cp); + } + return numDigits; +} + //---------------------------------------------------------------------- void SimpleDateFormat::translatePattern(const UnicodeString& originalPattern, diff --git a/icu4c/source/i18n/unicode/smpdtfmt.h b/icu4c/source/i18n/unicode/smpdtfmt.h index 4733e759aa7..9801b29bdb7 100644 --- a/icu4c/source/i18n/unicode/smpdtfmt.h +++ b/icu4c/source/i18n/unicode/smpdtfmt.h @@ -1433,6 +1433,16 @@ private: int32_t checkIntSuffix(const UnicodeString& text, int32_t start, int32_t patLoc, UBool isNegative) const; + /** + * Counts number of digit code points in the specified text. + * + * @param text input text + * @param start start index, inclusive + * @param end end index, exclusive + * @return number of digits found in the text in the specified range. + */ + int32_t countDigits(const UnicodeString& text, int32_t start, int32_t end) const; + /** * Translate a pattern, mapping each character in the from string to the * corresponding character in the to string. Return an error if the original diff --git a/icu4c/source/test/intltest/tzfmttst.cpp b/icu4c/source/test/intltest/tzfmttst.cpp index 05c4778a9d6..46a640ae688 100644 --- a/icu4c/source/test/intltest/tzfmttst.cpp +++ b/icu4c/source/test/intltest/tzfmttst.cpp @@ -567,11 +567,6 @@ void TimeZoneFormatTest::RunTimeRoundTripTests(int32_t threadNumber) { logln(" Thread %d, Locale %s, Pattern %s", threadNumber, gLocaleData->locales[locidx].getName(), CStr(pattern)()); - if (uprv_strcmp(gLocaleData->locales[locidx].getLanguage(), "ccp") == 0 - && logKnownIssue("13446", "Chakma time zone parsing")) { - continue; - } - SimpleDateFormat *sdf = new SimpleDateFormat(pattern, gLocaleData->locales[locidx], status); if (U_FAILURE(status)) { errcheckln(status, (UnicodeString) "new SimpleDateFormat failed for pattern " +