Changeset 130242 in webkit
- Timestamp:
- Oct 2, 2012, 6:17:15 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r130241 r130242 1 2012-10-02 Kent Tamura <tkent@chromium.org> 2 3 [Chromium-Win] Implement LocaleWin::dateFormat 4 https://bugs.webkit.org/show_bug.cgi?id=98117 5 6 Reviewed by Kentaro Hara. 7 8 http://trac.webkit.org/changeset/130127 introduced 9 Localizer::dateFormat, and this is its implementation for LocaleICU 10 classs. The code is going to be used when 11 ENABLE_INPUT_MULTIPLE_FIELDS_UI is enabled. 12 13 Tests: Added a new test to WebKit/chromium/tests/LocaleWinTest.cpp. 14 15 * platform/text/LocaleWin.cpp: 16 (WebCore::parseDateFormat): 17 Fix a continuous apostrophes parsing bug; "abc''''def" produced "abc'''def" 18 (WebCore::appendAsLDMLLiteral): 19 A helper function to make a literal string for LDML. 20 (WebCore::convertWindowsDateFormatToLDML): 21 Creates an LDML format from a parsed date format tokens. 22 (WebCore::LocaleWin::dateFormat): 23 Implemented. This uses convertWindowsDateFormatToLDML. 24 (WebCore::LocaleWin::dateFormat): 25 Added for testing. The source windows format is specified as a function 26 argument. 27 * platform/text/LocaleWin.h: 28 (LocaleWin): Declare m_dateFormat and dateFormat(). 29 1 30 2012-10-02 Ian Vollick <vollick@chromium.org> 2 31 -
trunk/Source/WebCore/platform/text/LocaleWin.cpp
r130127 r130242 241 241 StringBuilder literalBuffer; 242 242 bool inQuote = false; 243 bool lastQuoteCanBeLiteral = false; 243 244 for (unsigned i = 0; i < format.length(); ++i) { 244 245 UChar ch = format[i]; … … 247 248 inQuote = false; 248 249 ASSERT(i); 249 if ( format[i - 1] == '\'')250 if (lastQuoteCanBeLiteral && format[i - 1] == '\'') { 250 251 literalBuffer.append('\''); 252 lastQuoteCanBeLiteral = false; 253 } else 254 lastQuoteCanBeLiteral = true; 251 255 } else 252 256 literalBuffer.append(ch); … … 256 260 if (ch == '\'') { 257 261 inQuote = true; 258 if ( i > 0 && format[i - 1] == '\'')262 if (lastQuoteCanBeLiteral && i > 0 && format[i - 1] == '\'') { 259 263 literalBuffer.append(ch); 264 lastQuoteCanBeLiteral = false; 265 } else 266 lastQuoteCanBeLiteral = true; 260 267 } else if (isYearSymbol(ch)) { 261 268 commitLiteralToken(literalBuffer, tokens); … … 678 685 679 686 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 687 static void appendAsLDMLLiteral(const String& literal, StringBuilder& buffer) 688 { 689 if (literal.length() <= 0) 690 return; 691 692 if (literal.find('\'') == notFound) { 693 buffer.append("'"); 694 buffer.append(literal); 695 buffer.append("'"); 696 return; 697 } 698 699 for (unsigned i = 0; i < literal.length(); ++i) { 700 if (literal[i] == '\'') 701 buffer.append("''"); 702 else { 703 String escaped = literal.substring(i); 704 escaped.replace(ASCIILiteral("'"), ASCIILiteral("''")); 705 buffer.append("'"); 706 buffer.append(escaped); 707 buffer.append("'"); 708 return; 709 } 710 } 711 } 712 713 static String convertWindowsDateFormatToLDML(const Vector<DateFormatToken>& tokens) 714 { 715 StringBuilder buffer; 716 for (unsigned i = 0; i < tokens.size(); ++i) { 717 switch (tokens[i].type) { 718 case DateFormatToken::Literal: 719 appendAsLDMLLiteral(tokens[i].data, buffer); 720 break; 721 722 case DateFormatToken::Day2: 723 buffer.append(static_cast<char>(DateTimeFormat::FieldTypeDayOfMonth)); 724 // Fallthrough. 725 case DateFormatToken::Day1: 726 buffer.append(static_cast<char>(DateTimeFormat::FieldTypeDayOfMonth)); 727 break; 728 729 case DateFormatToken::Month4: 730 buffer.append(static_cast<char>(DateTimeFormat::FieldTypeMonth)); 731 // Fallthrough. 732 case DateFormatToken::Month3: 733 buffer.append(static_cast<char>(DateTimeFormat::FieldTypeMonth)); 734 // Fallthrough. 735 case DateFormatToken::Month2: 736 buffer.append(static_cast<char>(DateTimeFormat::FieldTypeMonth)); 737 // Fallthrough. 738 case DateFormatToken::Month1: 739 buffer.append(static_cast<char>(DateTimeFormat::FieldTypeMonth)); 740 break; 741 742 case DateFormatToken::Year4: 743 buffer.append(static_cast<char>(DateTimeFormat::FieldTypeYear)); 744 buffer.append(static_cast<char>(DateTimeFormat::FieldTypeYear)); 745 // Fallthrough. 746 case DateFormatToken::Year2: 747 buffer.append(static_cast<char>(DateTimeFormat::FieldTypeYear)); 748 // Fallthrough. 749 case DateFormatToken::Year1: 750 buffer.append(static_cast<char>(DateTimeFormat::FieldTypeYear)); 751 break; 752 } 753 } 754 return buffer.toString(); 755 } 756 680 757 static DateTimeFormat::FieldType mapCharacterToDateTimeFieldType(UChar ch) 681 758 { … … 732 809 String LocaleWin::dateFormat() 733 810 { 734 // FIXME: We should have real implementation of LocaleWin::dateFormat(). 735 return emptyString(); 811 if (!m_dateFormat.isEmpty()) 812 return m_dateFormat; 813 ensureShortDateTokens(); 814 m_dateFormat = convertWindowsDateFormatToLDML(m_shortDateTokens); 815 return m_dateFormat; 816 } 817 818 String LocaleWin::dateFormat(const String& windowsFormat) 819 { 820 return convertWindowsDateFormatToLDML(parseDateFormat(windowsFormat)); 736 821 } 737 822 -
trunk/Source/WebCore/platform/text/LocaleWin.h
r130127 r130242 68 68 String formatDate(const String& format, int baseYear, int year, int month, int day); 69 69 static String dateFormatText(const String& format, const String& yearText, const String& monthText, const String& dayText); 70 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 71 static String dateFormat(const String&); 72 #endif 70 73 71 74 private: … … 95 98 Vector<String> m_shortMonthLabels; 96 99 Vector<String> m_monthLabels; 100 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 101 String m_dateFormat; 102 #endif 97 103 #if ENABLE(CALENDAR_PICKER) 98 104 Vector<String> m_weekDayShortLabels; -
trunk/Source/WebKit/chromium/ChangeLog
r130237 r130242 1 2012-10-02 Kent Tamura <tkent@chromium.org> 2 3 [Chromium-Win] Implement LocaleWin::dateFormat 4 https://bugs.webkit.org/show_bug.cgi?id=98117 5 6 Reviewed by Kentaro Hara. 7 8 * tests/LocaleWinTest.cpp: 9 (TEST_F): Add tests for LocaleWin::dateFormat. 10 1 11 == Rolled over to ChangeLog-2012-10-02 == -
trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp
r129912 r130242 326 326 327 327 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 328 TEST_F(LocaleWinTest, dateFormat) 329 { 330 EXPECT_STREQ("y'-'M'-'d", LocaleWin::dateFormat("y-M-d").utf8().data()); 331 EXPECT_STREQ("''yy'-'''MM'''-'dd", LocaleWin::dateFormat("''yy-''MM''-dd").utf8().data()); 332 EXPECT_STREQ("yyyy'-''''-'MMM'''''-'dd", LocaleWin::dateFormat("yyyy-''''-MMM''''-dd").utf8().data()); 333 EXPECT_STREQ("yyyy'-'''''MMMM'-'dd", LocaleWin::dateFormat("yyyy-''''MMMM-dd").utf8().data()); 334 } 335 328 336 TEST_F(LocaleWinTest, timeFormat) 329 337 {
Note:
See TracChangeset
for help on using the changeset viewer.