Changeset 130242 in webkit


Ignore:
Timestamp:
Oct 2, 2012 6:17:15 PM (12 years ago)
Author:
tkent@chromium.org
Message:

[Chromium-Win] Implement LocaleWin::dateFormat
https://bugs.webkit.org/show_bug.cgi?id=98117

Reviewed by Kentaro Hara.

Source/WebCore:

http://trac.webkit.org/changeset/130127 introduced
Localizer::dateFormat, and this is its implementation for LocaleICU
classs. The code is going to be used when
ENABLE_INPUT_MULTIPLE_FIELDS_UI is enabled.

Tests: Added a new test to WebKit/chromium/tests/LocaleWinTest.cpp.

  • platform/text/LocaleWin.cpp:

(WebCore::parseDateFormat):
Fix a continuous apostrophes parsing bug; "abc'def" produced "abcdef"
(WebCore::appendAsLDMLLiteral):
A helper function to make a literal string for LDML.
(WebCore::convertWindowsDateFormatToLDML):
Creates an LDML format from a parsed date format tokens.
(WebCore::LocaleWin::dateFormat):
Implemented. This uses convertWindowsDateFormatToLDML.
(WebCore::LocaleWin::dateFormat):
Added for testing. The source windows format is specified as a function
argument.

  • platform/text/LocaleWin.h:

(LocaleWin): Declare m_dateFormat and dateFormat().

Source/WebKit/chromium:

  • tests/LocaleWinTest.cpp:

(TEST_F): Add tests for LocaleWin::dateFormat.

Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r130241 r130242  
     12012-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
    1302012-10-02  Ian Vollick  <vollick@chromium.org>
    231
  • trunk/Source/WebCore/platform/text/LocaleWin.cpp

    r130127 r130242  
    241241    StringBuilder literalBuffer;
    242242    bool inQuote = false;
     243    bool lastQuoteCanBeLiteral = false;
    243244    for (unsigned i = 0; i < format.length(); ++i) {
    244245        UChar ch = format[i];
     
    247248                inQuote = false;
    248249                ASSERT(i);
    249                 if (format[i - 1] == '\'')
     250                if (lastQuoteCanBeLiteral && format[i - 1] == '\'') {
    250251                    literalBuffer.append('\'');
     252                    lastQuoteCanBeLiteral = false;
     253                } else
     254                    lastQuoteCanBeLiteral = true;
    251255            } else
    252256                literalBuffer.append(ch);
     
    256260        if (ch == '\'') {
    257261            inQuote = true;
    258             if (i > 0 && format[i - 1] == '\'')
     262            if (lastQuoteCanBeLiteral && i > 0 && format[i - 1] == '\'') {
    259263                literalBuffer.append(ch);
     264                lastQuoteCanBeLiteral = false;
     265            } else
     266                lastQuoteCanBeLiteral = true;
    260267        } else if (isYearSymbol(ch)) {
    261268            commitLiteralToken(literalBuffer, tokens);
     
    678685
    679686#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
     687static 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
     713static 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
    680757static DateTimeFormat::FieldType mapCharacterToDateTimeFieldType(UChar ch)
    681758{
     
    732809String LocaleWin::dateFormat()
    733810{
    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
     818String LocaleWin::dateFormat(const String& windowsFormat)
     819{
     820    return convertWindowsDateFormatToLDML(parseDateFormat(windowsFormat));
    736821}
    737822
  • trunk/Source/WebCore/platform/text/LocaleWin.h

    r130127 r130242  
    6868    String formatDate(const String& format, int baseYear, int year, int month, int day);
    6969    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
    7073
    7174private:
     
    9598    Vector<String> m_shortMonthLabels;
    9699    Vector<String> m_monthLabels;
     100#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
     101    String m_dateFormat;
     102#endif
    97103#if ENABLE(CALENDAR_PICKER)
    98104    Vector<String> m_weekDayShortLabels;
  • trunk/Source/WebKit/chromium/ChangeLog

    r130237 r130242  
     12012-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
    111== Rolled over to ChangeLog-2012-10-02 ==
  • trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp

    r129912 r130242  
    326326
    327327#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
     328TEST_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
    328336TEST_F(LocaleWinTest, timeFormat)
    329337{
Note: See TracChangeset for help on using the changeset viewer.