diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp index 62c7d22131e..5ebb8d5b171 100644 --- a/icu4c/source/i18n/smpdtfmt.cpp +++ b/icu4c/source/i18n/smpdtfmt.cpp @@ -2230,7 +2230,7 @@ UBool SimpleDateFormat::matchLiterals(const UnicodeString &pattern, if (t >= text.length() || literal.charAt(p) != text.charAt(t)) { // Ran out of text, or found a non-matching character: // OK in lenient mode, an error in strict mode. - if (partialMatchLenient) { + if (whitespaceLenient) { if (t == textOffset && text.charAt(t) == 0x2e && isAfterNonNumericField(pattern, patternOffset)) { // Lenient mode and the literal input text begins with a "." and @@ -2238,9 +2238,16 @@ UBool SimpleDateFormat::matchLiterals(const UnicodeString &pattern, ++t; continue; // Do not update p. } + // if it is actual whitespace and we're whitespace lenient it's OK + UChar wsc = text.charAt(t); + if(PatternProps::isWhiteSpace(wsc)) + break; + } + // or if we're partial match lenient it's OK + if(partialMatchLenient) { break; } - + return FALSE; } ++p; diff --git a/icu4c/source/test/intltest/dtfmttst.cpp b/icu4c/source/test/intltest/dtfmttst.cpp index 9c9cd5bc859..f6dae50268c 100644 --- a/icu4c/source/test/intltest/dtfmttst.cpp +++ b/icu4c/source/test/intltest/dtfmttst.cpp @@ -4212,9 +4212,9 @@ void DateFormatTest::TestDateFormatLeniency() { //locale leniency parse String pattern expected result { "en", true, UnicodeString("2008-07 02"), UnicodeString("yyyy-LLLL dd"), UnicodeString("2008-July 02") }, { "en", false, UnicodeString("2008-07 02"), UnicodeString("yyyy-LLLL dd"), UnicodeString("") }, - { "en", true, UnicodeString("2008-Jan 02"), UnicodeString("yyyy-LLL. dd"), UnicodeString("2008-Jan 02") }, + { "en", true, UnicodeString("2008-Jan 02"), UnicodeString("yyyy-LLL. dd"), UnicodeString("2008-Jan. 02") }, { "en", false, UnicodeString("2008-Jan 02"), UnicodeString("yyyy-LLL. dd"), UnicodeString("") }, - { "en", true, UnicodeString("2008-Jan--02"), UnicodeString("yyyy-MMM' -- 'dd"), UnicodeString("2008-Jan 02") }, + { "en", true, UnicodeString("2008-Jan--02"), UnicodeString("yyyy-MMM' -- 'dd"), UnicodeString("2008-Jan -- 02") }, { "en", false, UnicodeString("2008-Jan--02"), UnicodeString("yyyy-MMM' -- 'dd"), UnicodeString("") }, // terminator { NULL, true, UnicodeString(""), UnicodeString(""), UnicodeString("") } @@ -4240,17 +4240,39 @@ void DateFormatTest::TestDateFormatLeniency() { } sdmft->setLenient(itemPtr->leniency); sdmft->setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, itemPtr->leniency, status). + setBooleanAttribute(UDAT_PARSE_PARTIAL_MATCH, itemPtr->leniency, status). setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, itemPtr->leniency, status); - UDate d = sdmft->parse(itemPtr->parseString, pos); - (void)d; + UDate d = sdmft->parse(itemPtr->parseString, pos); - // TODO: Ticket 10625. Nothing here is checking the expected result when the parse succeeds. - - if ((pos.getErrorIndex() > -1) && (itemPtr->expectedResult.length() != 0)) { - errln("error: unexpected error - " + itemPtr->parseString + - " - error index " + pos.getErrorIndex() + - " - leniency " + itemPtr->leniency); + if(itemPtr->expectedResult.length() == 0) { + if(pos.getErrorIndex() != -1) { + continue; + } else { + errln("error: unexpected parse success - " + itemPtr->parseString + + " - pattern " + itemPtr->pattern + + " - error index " + pos.getErrorIndex() + + " - leniency " + itemPtr->leniency); + continue; + } } + if(pos.getErrorIndex() != -1) { + errln("error: parse error for string - " + itemPtr->parseString + + " - pattern " + itemPtr->pattern + + " - idx " + pos.getIndex() + + " - error index "+pos.getErrorIndex() + + " - leniency " + itemPtr->leniency); + continue; + } + + UnicodeString formatResult(""); + sdmft->format(d, formatResult); + if(formatResult.compare(itemPtr->expectedResult) != 0) { + errln("error: unexpected format result. pattern["+itemPtr->pattern+"] expected[" + itemPtr->expectedResult + "] but result was[" + formatResult + "]"); + continue; + } else { + logln("formatted results match! - " + formatResult); + } + } }