Title: [133751] trunk/Source/WebCore
Revision
133751
Author
[email protected]
Date
2012-11-07 06:18:43 -0800 (Wed, 07 Nov 2012)

Log Message

Unreviewed, rolling out r133712.
http://trac.webkit.org/changeset/133712
https://bugs.webkit.org/show_bug.cgi?id=101461

Broke fast/forms/time* tests on chromium-win. (Requested by
mkwst on #webkit).

Patch by Sheriff Bot <[email protected]> on 2012-11-07

* platform/text/win/LocaleWin.cpp:
(WebCore::DateFormatToken::DateFormatToken):
(DateFormatToken):
(WebCore):
(WebCore::isEraSymbol):
(WebCore::isYearSymbol):
(WebCore::isMonthSymbol):
(WebCore::isDaySymbol):
(WebCore::commitLiteralToken):
(WebCore::parseDateFormat):
(WebCore::LocaleWin::ensureShortDateTokens):
(WebCore::convertWindowsDateFormatToLDML):
(WebCore::mapCharacterToDateTimeFieldType):
(WebCore::convertWindowsTimeFormatToLDML):
(WebCore::LocaleWin::dateFormat):
(WebCore::LocaleWin::monthFormat):
(WebCore::LocaleWin::timeFormat):
(WebCore::LocaleWin::shortTimeFormat):
* platform/text/win/LocaleWin.h:
(LocaleWin):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (133750 => 133751)


--- trunk/Source/WebCore/ChangeLog	2012-11-07 14:14:49 UTC (rev 133750)
+++ trunk/Source/WebCore/ChangeLog	2012-11-07 14:18:43 UTC (rev 133751)
@@ -1,3 +1,33 @@
+2012-11-07  Sheriff Bot  <[email protected]>
+
+        Unreviewed, rolling out r133712.
+        http://trac.webkit.org/changeset/133712
+        https://bugs.webkit.org/show_bug.cgi?id=101461
+
+        Broke fast/forms/time* tests on chromium-win. (Requested by
+        mkwst on #webkit).
+
+        * platform/text/win/LocaleWin.cpp:
+        (WebCore::DateFormatToken::DateFormatToken):
+        (DateFormatToken):
+        (WebCore):
+        (WebCore::isEraSymbol):
+        (WebCore::isYearSymbol):
+        (WebCore::isMonthSymbol):
+        (WebCore::isDaySymbol):
+        (WebCore::commitLiteralToken):
+        (WebCore::parseDateFormat):
+        (WebCore::LocaleWin::ensureShortDateTokens):
+        (WebCore::convertWindowsDateFormatToLDML):
+        (WebCore::mapCharacterToDateTimeFieldType):
+        (WebCore::convertWindowsTimeFormatToLDML):
+        (WebCore::LocaleWin::dateFormat):
+        (WebCore::LocaleWin::monthFormat):
+        (WebCore::LocaleWin::timeFormat):
+        (WebCore::LocaleWin::shortTimeFormat):
+        * platform/text/win/LocaleWin.h:
+        (LocaleWin):
+
 2012-11-07  Vsevolod Vlasov  <[email protected]>
 
         Web Inspector: [Regression] Editing formatted source should not be allowed.

Modified: trunk/Source/WebCore/platform/text/win/LocaleWin.cpp (133750 => 133751)


--- trunk/Source/WebCore/platform/text/win/LocaleWin.cpp	2012-11-07 14:14:49 UTC (rev 133750)
+++ trunk/Source/WebCore/platform/text/win/LocaleWin.cpp	2012-11-07 14:18:43 UTC (rev 133751)
@@ -160,6 +160,42 @@
 
 // -------------------------------- Tokenized date format
 
+struct DateFormatToken {
+    enum Type {
+        Literal,
+        Day1,
+        Day2,
+        Month1,
+        Month2,
+        Month3,
+        Month4,
+        Year1,
+        Year2,
+        Year4,
+    };
+    Type type;
+    String data; // This is valid only if type==Literal.
+
+    DateFormatToken(Type type)
+        : type(type)
+    { }
+
+    DateFormatToken(const String& data)
+        : type(Literal)
+        , data(data)
+    { }
+
+    DateFormatToken(const DateFormatToken& token)
+        : type(token.type)
+        , data(token.data)
+    { }
+};
+
+static inline bool isEraSymbol(UChar letter) { return letter == 'g'; }
+static inline bool isYearSymbol(UChar letter) { return letter == 'y'; }
+static inline bool isMonthSymbol(UChar letter) { return letter == 'M'; }
+static inline bool isDaySymbol(UChar letter) { return letter == 'd'; }
+
 static unsigned countContinuousLetters(const String& format, unsigned index)
 {
     unsigned count = 1;
@@ -172,34 +208,18 @@
     return count;
 }
 
-static void commitLiteralToken(StringBuilder& literalBuffer, StringBuilder& converted)
+static void commitLiteralToken(StringBuilder& literalBuffer, Vector<DateFormatToken>& tokens)
 {
     if (literalBuffer.length() <= 0)
         return;
-    DateTimeFormat::quoteAndAppendLiteral(literalBuffer.toString(), converted);
+    tokens.append(DateFormatToken(literalBuffer.toString()));
     literalBuffer.clear();
 }
 
-// This function converts Windows date/time pattern format [1][2] into LDML date
-// format pattern [3].
-//
-// i.e.
-//   We set h, H, m, s, d, dd, M, or y as is. They have same meaning in both of
-//   Windows and LDML.
-//   We need to convert the following patterns:
-//     t -> a
-//     tt -> a
-//     ddd -> EEE
-//     dddd -> EEEE
-//     g -> G
-//     gg -> ignore
-//
-// [1] http://msdn.microsoft.com/en-us/library/dd317787(v=vs.85).aspx
-// [2] http://msdn.microsoft.com/en-us/library/dd318148(v=vs.85).aspx
-// [3] LDML http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
-static String convertWindowsDateTimeFormat(const String& format)
+// See http://msdn.microsoft.com/en-us/library/dd317787(v=vs.85).aspx
+static Vector<DateFormatToken> parseDateFormat(const String format)
 {
-    StringBuilder converted;
+    Vector<DateFormatToken> tokens;
     StringBuilder literalBuffer;
     bool inQuote = false;
     bool lastQuoteCanBeLiteral = false;
@@ -226,38 +246,53 @@
                 lastQuoteCanBeLiteral = false;
             } else
                 lastQuoteCanBeLiteral = true;
-        } else if (isASCIIAlpha(ch)) {
-            commitLiteralToken(literalBuffer, converted);
-            unsigned symbolStart = i;
+        } else if (isYearSymbol(ch)) {
+            commitLiteralToken(literalBuffer, tokens);
             unsigned count = countContinuousLetters(format, i);
             i += count - 1;
-            if (ch == 'h' || ch == 'H' || ch == 'm' || ch == 's' || ch == 'M' || ch == 'y')
-                converted.append(format, symbolStart, count);
-            else if (ch == 'd') {
-                if (count <= 2)
-                    converted.append(format, symbolStart, count);
-                else if (count == 3)
-                    converted.append("EEE");
-                else
-                    converted.append("EEEE");
-            } else if (ch == 'g') {
-                if (count == 1)
-                    converted.append('G');
-                else {
-                    // gg means imperial era in Windows.
-                    // Just ignore it.
-                }
-            } else if (ch == 't')
-                converted.append('a');
+            if (count == 1)
+                tokens.append(DateFormatToken(DateFormatToken::Year1));
+            else if (count == 2)
+                tokens.append(DateFormatToken(DateFormatToken::Year2));
             else
-                literalBuffer.append(format, symbolStart, count);
+                tokens.append(DateFormatToken(DateFormatToken::Year4));
+        } else if (isMonthSymbol(ch)) {
+            commitLiteralToken(literalBuffer, tokens);
+            unsigned count = countContinuousLetters(format, i);
+            i += count - 1;
+            if (count == 1)
+                tokens.append(DateFormatToken(DateFormatToken::Month1));
+            else if (count == 2)
+                tokens.append(DateFormatToken(DateFormatToken::Month2));
+            else if (count == 3)
+                tokens.append(DateFormatToken(DateFormatToken::Month3));
+            else
+                tokens.append(DateFormatToken(DateFormatToken::Month4));
+        } else if (isDaySymbol(ch)) {
+            commitLiteralToken(literalBuffer, tokens);
+            unsigned count = countContinuousLetters(format, i);
+            i += count - 1;
+            if (count == 1)
+                tokens.append(DateFormatToken(DateFormatToken::Day1));
+            else
+                tokens.append(DateFormatToken(DateFormatToken::Day2));
+        } else if (isEraSymbol(ch)) {
+            // Just ignore era.
+            // HTML5 date supports only A.D.
         } else
             literalBuffer.append(ch);
     }
-    commitLiteralToken(literalBuffer, converted);
-    return converted.toString();
+    commitLiteralToken(literalBuffer, tokens);
+    return tokens;
 }
 
+void LocaleWin::ensureShortDateTokens()
+{
+    if (!m_shortDateTokens.isEmpty())
+        return;
+    m_shortDateTokens = parseDateFormat(getLocaleInfoString(LOCALE_SSHORTDATE));
+}
+
 void LocaleWin::ensureMonthLabels()
 {
     if (!m_monthLabels.isEmpty())
@@ -345,29 +380,128 @@
 #endif
 
 #if ENABLE(DATE_AND_TIME_INPUT_TYPES)
+static String convertWindowsDateFormatToLDML(const Vector<DateFormatToken>& tokens)
+{
+    StringBuilder buffer;
+    for (unsigned i = 0; i < tokens.size(); ++i) {
+        switch (tokens[i].type) {
+        case DateFormatToken::Literal:
+            DateTimeFormat::quoteAndAppendLiteral(tokens[i].data, buffer);
+            break;
+
+        case DateFormatToken::Day2:
+            buffer.append(static_cast<char>(DateTimeFormat::FieldTypeDayOfMonth));
+            // Fallthrough.
+        case DateFormatToken::Day1:
+            buffer.append(static_cast<char>(DateTimeFormat::FieldTypeDayOfMonth));
+            break;
+
+        case DateFormatToken::Month4:
+            buffer.append(static_cast<char>(DateTimeFormat::FieldTypeMonth));
+            // Fallthrough.
+        case DateFormatToken::Month3:
+            buffer.append(static_cast<char>(DateTimeFormat::FieldTypeMonth));
+            // Fallthrough.
+        case DateFormatToken::Month2:
+            buffer.append(static_cast<char>(DateTimeFormat::FieldTypeMonth));
+            // Fallthrough.
+        case DateFormatToken::Month1:
+            buffer.append(static_cast<char>(DateTimeFormat::FieldTypeMonth));
+            break;
+
+        case DateFormatToken::Year4:
+            buffer.append(static_cast<char>(DateTimeFormat::FieldTypeYear));
+            buffer.append(static_cast<char>(DateTimeFormat::FieldTypeYear));
+            // Fallthrough.
+        case DateFormatToken::Year2:
+            buffer.append(static_cast<char>(DateTimeFormat::FieldTypeYear));
+            // Fallthrough.
+        case DateFormatToken::Year1:
+            buffer.append(static_cast<char>(DateTimeFormat::FieldTypeYear));
+            break;
+        }
+    }
+    return buffer.toString();
+}
+
+static DateTimeFormat::FieldType mapCharacterToDateTimeFieldType(UChar ch)
+{
+    switch (ch) {
+    case 'h':
+        return DateTimeFormat::FieldTypeHour12;
+
+    case 'H':
+        return DateTimeFormat::FieldTypeHour23;
+
+    case 'm':
+        return DateTimeFormat::FieldTypeMinute;
+
+    case 's':
+        return DateTimeFormat::FieldTypeSecond;
+
+    case 't':
+        return DateTimeFormat::FieldTypePeriod;
+
+    default:
+        return DateTimeFormat::FieldTypeLiteral;
+    }
+}
+
+// This class used for converting Windows time pattern format[1] into LDML[2]
+// time format string.
+// [1] http://msdn.microsoft.com/en-us/library/windows/desktop/dd318148(v=vs.85).aspx
+// [2] LDML http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
+static String convertWindowsTimeFormatToLDML(const String& windowsTimeFormat)
+{
+    StringBuilder builder;
+    int counter = 0;
+    DateTimeFormat::FieldType lastFieldType = DateTimeFormat::FieldTypeLiteral;
+    for (unsigned index = 0; index < windowsTimeFormat.length(); ++index) {
+        UChar const ch = windowsTimeFormat[index];
+        DateTimeFormat::FieldType fieldType = mapCharacterToDateTimeFieldType(ch);
+        if (fieldType == DateTimeFormat::FieldTypeLiteral)
+            builder.append(ch);
+        else if (fieldType == lastFieldType) {
+            ++counter;
+            if (counter == 2 && lastFieldType != DateTimeFormat::FieldTypePeriod)
+                builder.append(static_cast<UChar>(lastFieldType));
+        } else {
+            if (lastFieldType != DateTimeFormat::FieldTypeLiteral)
+                builder.append(static_cast<UChar>(lastFieldType));
+            builder.append(static_cast<UChar>(fieldType));
+            counter = 1;
+        }
+        lastFieldType = fieldType;
+    }
+    return builder.toString();
+}
+
 String LocaleWin::dateFormat()
 {
-    if (m_dateFormat.isNull())
-        m_dateFormat = convertWindowsDateTimeFormat(getLocaleInfoString(LOCALE_SSHORTDATE));
+    if (!m_dateFormat.isNull())
+        return m_dateFormat;
+    ensureShortDateTokens();
+    m_dateFormat = convertWindowsDateFormatToLDML(m_shortDateTokens);
     return m_dateFormat;
 }
 
 String LocaleWin::dateFormat(const String& windowsFormat)
 {
-    return convertWindowsDateTimeFormat(windowsFormat);
+    return convertWindowsDateFormatToLDML(parseDateFormat(windowsFormat));
 }
 
 String LocaleWin::monthFormat()
 {
-    if (m_monthFormat.isNull())
-        m_monthFormat = convertWindowsDateTimeFormat(getLocaleInfoString(LOCALE_SYEARMONTH));
+    if (!m_monthFormat.isNull())
+        return m_monthFormat;
+    m_monthFormat = convertWindowsDateFormatToLDML(parseDateFormat(getLocaleInfoString(LOCALE_SYEARMONTH)));
     return m_monthFormat;
 }
 
 String LocaleWin::timeFormat()
 {
     if (m_timeFormatWithSeconds.isNull())
-        m_timeFormatWithSeconds = convertWindowsDateTimeFormat(getLocaleInfoString(LOCALE_STIMEFORMAT));
+        m_timeFormatWithSeconds = convertWindowsTimeFormatToLDML(getLocaleInfoString(LOCALE_STIMEFORMAT));
     return m_timeFormatWithSeconds;
 }
 
@@ -386,7 +520,7 @@
         if (pos != notFound)
             format.remove(pos, builder.length());
     }
-    m_timeFormatWithoutSeconds = convertWindowsDateTimeFormat(format);
+    m_timeFormatWithoutSeconds = convertWindowsTimeFormatToLDML(format);
     return m_timeFormatWithoutSeconds;
 }
 

Modified: trunk/Source/WebCore/platform/text/win/LocaleWin.h (133750 => 133751)


--- trunk/Source/WebCore/platform/text/win/LocaleWin.h	2012-11-07 14:14:49 UTC (rev 133750)
+++ trunk/Source/WebCore/platform/text/win/LocaleWin.h	2012-11-07 14:18:43 UTC (rev 133751)
@@ -71,6 +71,7 @@
     void getLocaleInfo(LCTYPE, DWORD&);
     void ensureShortMonthLabels();
     void ensureMonthLabels();
+    void ensureShortDateTokens();
 #if ENABLE(CALENDAR_PICKER)
     void ensureWeekDayShortLabels();
 #endif
@@ -78,6 +79,7 @@
     virtual void initializeLocaleData() OVERRIDE;
 
     LCID m_lcid;
+    Vector<DateFormatToken> m_shortDateTokens;
 #if ENABLE(DATE_AND_TIME_INPUT_TYPES)
     Vector<String> m_shortMonthLabels;
     Vector<String> m_monthLabels;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to