⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 121321 in webkit


Ignore:
Timestamp:
Jun 26, 2012, 11:03:35 PM (14 years ago)
Author:
yosin@chromium.org
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):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r121320 r121321  
     12012-06-26  Yoshifumi Inoue  <yosin@chromium.org>
     2
     3        [Platform] Change implementation of LocaleICU class to support more UDateFormat.
     4        https://bugs.webkit.org/show_bug.cgi?id=89967
     5
     6        Reviewed by Kent Tamura.
     7
     8        This patch changes internal functions of LocaleICU class to process
     9        multiple ICU date time format handles in addition to short date time
     10        format handle.
     11
     12        This patch is a part of implementing input type time. I'll add time
     13        format related ICU date time format handles.
     14
     15        No new tests. This patch doesn't change behavior.
     16
     17        * platform/text/LocaleICU.cpp:
     18        (WebCore::LocaleICU::initializeShortDateFormat): Changed to use openDateFormat().
     19        (WebCore::LocaleICU::openDateFormat): Added for common usage of udt_open().
     20        (WebCore::getDateFormatPattern): Added for common usage of udt_toPattern().
     21        (WebCore::localizeFormat): Changed to take String parameter.
     22        (WebCore::LocaleICU::initializeLocalizedDateFormatText): Changed to use getDateFormatPattern.
     23        (WebCore::LocaleICU::createLabelVector): Changed to take UDateFormat parameter.
     24        (WebCore::LocaleICU::initializeCalendar): Changed for helper functions.
     25        * platform/text/LocaleICU.h:
     26        (LocaleICU):
     27
    1282012-06-26  Luke Macpherson  <macpherson@chromium.org>
    229
  • trunk/Source/WebCore/platform/text/LocaleICU.cpp

    r116908 r121321  
    273273    if (m_didCreateShortDateFormat)
    274274        return m_shortDateFormat;
    275     const UChar gmtTimezone[3] = {'G', 'M', 'T'};
    276     UErrorCode status = U_ZERO_ERROR;
    277     m_shortDateFormat = udat_open(UDAT_NONE, UDAT_SHORT, m_locale.data(), gmtTimezone, WTF_ARRAY_LENGTH(gmtTimezone), 0, -1, &status);
     275    m_shortDateFormat = openDateFormat(UDAT_NONE, UDAT_SHORT);
    278276    m_didCreateShortDateFormat = true;
    279277    return m_shortDateFormat;
     278}
     279
     280UDateFormat* LocaleICU::openDateFormat(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle) const
     281{
     282    const UChar gmtTimezone[3] = {'G', 'M', 'T'};
     283    UErrorCode status = U_ZERO_ERROR;
     284    return udat_open(timeStyle, dateStyle, m_locale.data(), gmtTimezone, WTF_ARRAY_LENGTH(gmtTimezone), 0, -1, &status);
    280285}
    281286
     
    314319
    315320#if ENABLE(CALENDAR_PICKER)
     321static String getDateFormatPattern(const UDateFormat* dateFormat)
     322{
     323    if (!dateFormat)
     324        return emptyString();
     325
     326    UErrorCode status = U_ZERO_ERROR;
     327    int32_t length = udat_toPattern(dateFormat, TRUE, 0, 0, &status);
     328    if (status != U_BUFFER_OVERFLOW_ERROR || !length)
     329        return emptyString();
     330    Vector<UChar> buffer(length);
     331    status = U_ZERO_ERROR;
     332    udat_toPattern(dateFormat, TRUE, buffer.data(), length, &status);
     333    if (U_FAILURE(status))
     334        return emptyString();
     335    return String::adopt(buffer);
     336}
     337
    316338static inline bool isICUYearSymbol(UChar letter)
    317339{
     
    331353// Specification of the input:
    332354// http://icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details
    333 static String localizeFormat(const Vector<UChar>& buffer)
     355static String localizeFormat(const String& buffer)
    334356{
    335357    StringBuilder builder;
    336358    UChar lastChar = 0;
    337359    bool inQuote = false;
    338     for (unsigned i = 0; i < buffer.size(); ++i) {
     360    for (unsigned i = 0; i < buffer.length(); ++i) {
    339361        if (inQuote) {
    340362            if (buffer[i] == '\'') {
     
    375397    if (!initializeShortDateFormat())
    376398        return;
    377     UErrorCode status = U_ZERO_ERROR;
    378     int32_t length = udat_toPattern(m_shortDateFormat, TRUE, 0, 0, &status);
    379     if (status != U_BUFFER_OVERFLOW_ERROR)
    380         return;
    381     Vector<UChar> buffer(length);
    382     status = U_ZERO_ERROR;
    383     udat_toPattern(m_shortDateFormat, TRUE, buffer.data(), length, &status);
    384     if (U_FAILURE(status))
    385         return;
    386     m_localizedDateFormatText = localizeFormat(buffer);
     399    m_localizedDateFormatText = localizeFormat(getDateFormatPattern(m_shortDateFormat));
    387400}
    388401
     
    393406}
    394407
    395 PassOwnPtr<Vector<String> > LocaleICU::createLabelVector(UDateFormatSymbolType type, int32_t startIndex, int32_t size)
    396 {
    397     if (!m_shortDateFormat)
     408PassOwnPtr<Vector<String> > LocaleICU::createLabelVector(const UDateFormat* dateFormat, UDateFormatSymbolType type, int32_t startIndex, int32_t size)
     409{
     410    if (!dateFormat)
    398411        return PassOwnPtr<Vector<String> >();
    399     if (udat_countSymbols(m_shortDateFormat, type) != startIndex + size)
     412    if (udat_countSymbols(dateFormat, type) != startIndex + size)
    400413        return PassOwnPtr<Vector<String> >();
    401414
     
    404417    for (int32_t i = 0; i < size; ++i) {
    405418        UErrorCode status = U_ZERO_ERROR;
    406         int32_t length = udat_getSymbols(m_shortDateFormat, type, startIndex + i, 0, 0, &status);
     419        int32_t length = udat_getSymbols(dateFormat, type, startIndex + i, 0, 0, &status);
    407420        if (status != U_BUFFER_OVERFLOW_ERROR)
    408421            return PassOwnPtr<Vector<String> >();
    409422        Vector<UChar> buffer(length);
    410423        status = U_ZERO_ERROR;
    411         udat_getSymbols(m_shortDateFormat, type, startIndex + i, buffer.data(), length, &status);
     424        udat_getSymbols(dateFormat, type, startIndex + i, buffer.data(), length, &status);
    412425        if (U_FAILURE(status))
    413426            return PassOwnPtr<Vector<String> >();
     
    453466    m_firstDayOfWeek = ucal_getAttribute(udat_getCalendar(m_shortDateFormat), UCAL_FIRST_DAY_OF_WEEK) - UCAL_SUNDAY;
    454467
    455     m_monthLabels = createLabelVector(UDAT_MONTHS, UCAL_JANUARY, 12);
     468    m_monthLabels = createLabelVector(m_shortDateFormat, UDAT_MONTHS, UCAL_JANUARY, 12);
    456469    if (!m_monthLabels)
    457470        m_monthLabels = createFallbackMonthLabels();
    458471
    459     m_weekDayShortLabels = createLabelVector(UDAT_SHORT_WEEKDAYS, UCAL_SUNDAY, 7);
     472    m_weekDayShortLabels = createLabelVector(m_shortDateFormat, UDAT_SHORT_WEEKDAYS, UCAL_SUNDAY, 7);
    460473    if (!m_weekDayShortLabels)
    461474        m_weekDayShortLabels = createFallbackWeekDayShortLabels();
  • trunk/Source/WebCore/platform/text/LocaleICU.h

    r116243 r121321  
    7676
    7777    bool initializeShortDateFormat();
     78    UDateFormat* openDateFormat(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle) const;
    7879
    7980#if ENABLE(CALENDAR_PICKER)
    8081    void initializeLocalizedDateFormatText();
    81     PassOwnPtr<Vector<String> > createLabelVector(UDateFormatSymbolType, int32_t startIndex, int32_t size);
     82    PassOwnPtr<Vector<String> > createLabelVector(const UDateFormat*, UDateFormatSymbolType, int32_t startIndex, int32_t size);
    8283    void initializeCalendar();
    8384#endif
Note: See TracChangeset for help on using the changeset viewer.