Title: [121321] trunk/Source/WebCore
Revision
121321
Author
yo...@chromium.org
Date
2012-06-26 23:03:35 -0700 (Tue, 26 Jun 2012)

Log Message

[Platform] Change implementation of LocaleICU class to support more UDateFormat.
https://bugs.webkit.org/show_bug.cgi?id=89967

Reviewed by Kent Tamura.

This patch changes internal functions of LocaleICU class to process
multiple ICU date time format handles in addition to short date time
format handle.

This patch is a part of implementing input type time. I'll add time
format related ICU date time format handles.

No new tests. This patch doesn't change behavior.

* platform/text/LocaleICU.cpp:
(WebCore::LocaleICU::initializeShortDateFormat): Changed to use openDateFormat().
(WebCore::LocaleICU::openDateFormat): Added for common usage of udt_open().
(WebCore::getDateFormatPattern): Added for common usage of udt_toPattern().
(WebCore::localizeFormat): Changed to take String parameter.
(WebCore::LocaleICU::initializeLocalizedDateFormatText): Changed to use getDateFormatPattern.
(WebCore::LocaleICU::createLabelVector): Changed to take UDateFormat parameter.
(WebCore::LocaleICU::initializeCalendar): Changed for helper functions.
* platform/text/LocaleICU.h:
(LocaleICU):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (121320 => 121321)


--- trunk/Source/WebCore/ChangeLog	2012-06-27 05:40:18 UTC (rev 121320)
+++ trunk/Source/WebCore/ChangeLog	2012-06-27 06:03:35 UTC (rev 121321)
@@ -1,3 +1,30 @@
+2012-06-26  Yoshifumi Inoue  <yo...@chromium.org>
+
+        [Platform] Change implementation of LocaleICU class to support more UDateFormat.
+        https://bugs.webkit.org/show_bug.cgi?id=89967
+
+        Reviewed by Kent Tamura.
+
+        This patch changes internal functions of LocaleICU class to process
+        multiple ICU date time format handles in addition to short date time
+        format handle.
+
+        This patch is a part of implementing input type time. I'll add time
+        format related ICU date time format handles.
+
+        No new tests. This patch doesn't change behavior.
+
+        * platform/text/LocaleICU.cpp:
+        (WebCore::LocaleICU::initializeShortDateFormat): Changed to use openDateFormat().
+        (WebCore::LocaleICU::openDateFormat): Added for common usage of udt_open().
+        (WebCore::getDateFormatPattern): Added for common usage of udt_toPattern().
+        (WebCore::localizeFormat): Changed to take String parameter.
+        (WebCore::LocaleICU::initializeLocalizedDateFormatText): Changed to use getDateFormatPattern.
+        (WebCore::LocaleICU::createLabelVector): Changed to take UDateFormat parameter.
+        (WebCore::LocaleICU::initializeCalendar): Changed for helper functions.
+        * platform/text/LocaleICU.h:
+        (LocaleICU):
+
 2012-06-26  Luke Macpherson  <macpher...@chromium.org>
 
         Return correct value for css variables enabled runtime flag.

Modified: trunk/Source/WebCore/platform/text/LocaleICU.cpp (121320 => 121321)


--- trunk/Source/WebCore/platform/text/LocaleICU.cpp	2012-06-27 05:40:18 UTC (rev 121320)
+++ trunk/Source/WebCore/platform/text/LocaleICU.cpp	2012-06-27 06:03:35 UTC (rev 121321)
@@ -272,13 +272,18 @@
 {
     if (m_didCreateShortDateFormat)
         return m_shortDateFormat;
-    const UChar gmtTimezone[3] = {'G', 'M', 'T'};
-    UErrorCode status = U_ZERO_ERROR;
-    m_shortDateFormat = udat_open(UDAT_NONE, UDAT_SHORT, m_locale.data(), gmtTimezone, WTF_ARRAY_LENGTH(gmtTimezone), 0, -1, &status);
+    m_shortDateFormat = openDateFormat(UDAT_NONE, UDAT_SHORT);
     m_didCreateShortDateFormat = true;
     return m_shortDateFormat;
 }
 
+UDateFormat* LocaleICU::openDateFormat(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle) const
+{
+    const UChar gmtTimezone[3] = {'G', 'M', 'T'};
+    UErrorCode status = U_ZERO_ERROR;
+    return udat_open(timeStyle, dateStyle, m_locale.data(), gmtTimezone, WTF_ARRAY_LENGTH(gmtTimezone), 0, -1, &status);
+}
+
 double LocaleICU::parseLocalizedDate(const String& input)
 {
     if (!initializeShortDateFormat())
@@ -313,6 +318,23 @@
 }
 
 #if ENABLE(CALENDAR_PICKER)
+static String getDateFormatPattern(const UDateFormat* dateFormat)
+{
+    if (!dateFormat)
+        return emptyString();
+
+    UErrorCode status = U_ZERO_ERROR;
+    int32_t length = udat_toPattern(dateFormat, TRUE, 0, 0, &status);
+    if (status != U_BUFFER_OVERFLOW_ERROR || !length)
+        return emptyString();
+    Vector<UChar> buffer(length);
+    status = U_ZERO_ERROR;
+    udat_toPattern(dateFormat, TRUE, buffer.data(), length, &status);
+    if (U_FAILURE(status))
+        return emptyString();
+    return String::adopt(buffer);
+}
+
 static inline bool isICUYearSymbol(UChar letter)
 {
     return letter == 'y' || letter == 'Y';
@@ -330,12 +352,12 @@
 
 // Specification of the input:
 // http://icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details
-static String localizeFormat(const Vector<UChar>& buffer)
+static String localizeFormat(const String& buffer)
 {
     StringBuilder builder;
     UChar lastChar = 0;
     bool inQuote = false;
-    for (unsigned i = 0; i < buffer.size(); ++i) {
+    for (unsigned i = 0; i < buffer.length(); ++i) {
         if (inQuote) {
             if (buffer[i] == '\'') {
                 inQuote = false;
@@ -374,16 +396,7 @@
     m_localizedDateFormatText = emptyString();
     if (!initializeShortDateFormat())
         return;
-    UErrorCode status = U_ZERO_ERROR;
-    int32_t length = udat_toPattern(m_shortDateFormat, TRUE, 0, 0, &status);
-    if (status != U_BUFFER_OVERFLOW_ERROR)
-        return;
-    Vector<UChar> buffer(length);
-    status = U_ZERO_ERROR;
-    udat_toPattern(m_shortDateFormat, TRUE, buffer.data(), length, &status);
-    if (U_FAILURE(status))
-        return;
-    m_localizedDateFormatText = localizeFormat(buffer);
+    m_localizedDateFormatText = localizeFormat(getDateFormatPattern(m_shortDateFormat));
 }
 
 String LocaleICU::localizedDateFormatText()
@@ -392,23 +405,23 @@
     return m_localizedDateFormatText;
 }
 
-PassOwnPtr<Vector<String> > LocaleICU::createLabelVector(UDateFormatSymbolType type, int32_t startIndex, int32_t size)
+PassOwnPtr<Vector<String> > LocaleICU::createLabelVector(const UDateFormat* dateFormat, UDateFormatSymbolType type, int32_t startIndex, int32_t size)
 {
-    if (!m_shortDateFormat)
+    if (!dateFormat)
         return PassOwnPtr<Vector<String> >();
-    if (udat_countSymbols(m_shortDateFormat, type) != startIndex + size)
+    if (udat_countSymbols(dateFormat, type) != startIndex + size)
         return PassOwnPtr<Vector<String> >();
 
     OwnPtr<Vector<String> > labels = adoptPtr(new Vector<String>());
     labels->reserveCapacity(size);
     for (int32_t i = 0; i < size; ++i) {
         UErrorCode status = U_ZERO_ERROR;
-        int32_t length = udat_getSymbols(m_shortDateFormat, type, startIndex + i, 0, 0, &status);
+        int32_t length = udat_getSymbols(dateFormat, type, startIndex + i, 0, 0, &status);
         if (status != U_BUFFER_OVERFLOW_ERROR)
             return PassOwnPtr<Vector<String> >();
         Vector<UChar> buffer(length);
         status = U_ZERO_ERROR;
-        udat_getSymbols(m_shortDateFormat, type, startIndex + i, buffer.data(), length, &status);
+        udat_getSymbols(dateFormat, type, startIndex + i, buffer.data(), length, &status);
         if (U_FAILURE(status))
             return PassOwnPtr<Vector<String> >();
         labels->append(String::adopt(buffer));
@@ -452,11 +465,11 @@
     }
     m_firstDayOfWeek = ucal_getAttribute(udat_getCalendar(m_shortDateFormat), UCAL_FIRST_DAY_OF_WEEK) - UCAL_SUNDAY;
 
-    m_monthLabels = createLabelVector(UDAT_MONTHS, UCAL_JANUARY, 12);
+    m_monthLabels = createLabelVector(m_shortDateFormat, UDAT_MONTHS, UCAL_JANUARY, 12);
     if (!m_monthLabels)
         m_monthLabels = createFallbackMonthLabels();
 
-    m_weekDayShortLabels = createLabelVector(UDAT_SHORT_WEEKDAYS, UCAL_SUNDAY, 7);
+    m_weekDayShortLabels = createLabelVector(m_shortDateFormat, UDAT_SHORT_WEEKDAYS, UCAL_SUNDAY, 7);
     if (!m_weekDayShortLabels)
         m_weekDayShortLabels = createFallbackWeekDayShortLabels();
 }

Modified: trunk/Source/WebCore/platform/text/LocaleICU.h (121320 => 121321)


--- trunk/Source/WebCore/platform/text/LocaleICU.h	2012-06-27 05:40:18 UTC (rev 121320)
+++ trunk/Source/WebCore/platform/text/LocaleICU.h	2012-06-27 06:03:35 UTC (rev 121321)
@@ -75,10 +75,11 @@
     unsigned matchedDecimalSymbolIndex(const String& input, unsigned& position);
 
     bool initializeShortDateFormat();
+    UDateFormat* openDateFormat(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle) const;
 
 #if ENABLE(CALENDAR_PICKER)
     void initializeLocalizedDateFormatText();
-    PassOwnPtr<Vector<String> > createLabelVector(UDateFormatSymbolType, int32_t startIndex, int32_t size);
+    PassOwnPtr<Vector<String> > createLabelVector(const UDateFormat*, UDateFormatSymbolType, int32_t startIndex, int32_t size);
     void initializeCalendar();
 #endif
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to