Changeset 121321 in webkit
- Timestamp:
- Jun 26, 2012, 11:03:35 PM (14 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
platform/text/LocaleICU.cpp (modified) (7 diffs)
-
platform/text/LocaleICU.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r121320 r121321 1 2012-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 1 28 2012-06-26 Luke Macpherson <macpherson@chromium.org> 2 29 -
trunk/Source/WebCore/platform/text/LocaleICU.cpp
r116908 r121321 273 273 if (m_didCreateShortDateFormat) 274 274 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); 278 276 m_didCreateShortDateFormat = true; 279 277 return m_shortDateFormat; 278 } 279 280 UDateFormat* 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); 280 285 } 281 286 … … 314 319 315 320 #if ENABLE(CALENDAR_PICKER) 321 static 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 316 338 static inline bool isICUYearSymbol(UChar letter) 317 339 { … … 331 353 // Specification of the input: 332 354 // http://icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details 333 static String localizeFormat(const Vector<UChar>& buffer)355 static String localizeFormat(const String& buffer) 334 356 { 335 357 StringBuilder builder; 336 358 UChar lastChar = 0; 337 359 bool inQuote = false; 338 for (unsigned i = 0; i < buffer. size(); ++i) {360 for (unsigned i = 0; i < buffer.length(); ++i) { 339 361 if (inQuote) { 340 362 if (buffer[i] == '\'') { … … 375 397 if (!initializeShortDateFormat()) 376 398 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)); 387 400 } 388 401 … … 393 406 } 394 407 395 PassOwnPtr<Vector<String> > LocaleICU::createLabelVector( UDateFormatSymbolType type, int32_t startIndex, int32_t size)396 { 397 if (! m_shortDateFormat)408 PassOwnPtr<Vector<String> > LocaleICU::createLabelVector(const UDateFormat* dateFormat, UDateFormatSymbolType type, int32_t startIndex, int32_t size) 409 { 410 if (!dateFormat) 398 411 return PassOwnPtr<Vector<String> >(); 399 if (udat_countSymbols( m_shortDateFormat, type) != startIndex + size)412 if (udat_countSymbols(dateFormat, type) != startIndex + size) 400 413 return PassOwnPtr<Vector<String> >(); 401 414 … … 404 417 for (int32_t i = 0; i < size; ++i) { 405 418 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); 407 420 if (status != U_BUFFER_OVERFLOW_ERROR) 408 421 return PassOwnPtr<Vector<String> >(); 409 422 Vector<UChar> buffer(length); 410 423 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); 412 425 if (U_FAILURE(status)) 413 426 return PassOwnPtr<Vector<String> >(); … … 453 466 m_firstDayOfWeek = ucal_getAttribute(udat_getCalendar(m_shortDateFormat), UCAL_FIRST_DAY_OF_WEEK) - UCAL_SUNDAY; 454 467 455 m_monthLabels = createLabelVector( UDAT_MONTHS, UCAL_JANUARY, 12);468 m_monthLabels = createLabelVector(m_shortDateFormat, UDAT_MONTHS, UCAL_JANUARY, 12); 456 469 if (!m_monthLabels) 457 470 m_monthLabels = createFallbackMonthLabels(); 458 471 459 m_weekDayShortLabels = createLabelVector( UDAT_SHORT_WEEKDAYS, UCAL_SUNDAY, 7);472 m_weekDayShortLabels = createLabelVector(m_shortDateFormat, UDAT_SHORT_WEEKDAYS, UCAL_SUNDAY, 7); 460 473 if (!m_weekDayShortLabels) 461 474 m_weekDayShortLabels = createFallbackWeekDayShortLabels(); -
trunk/Source/WebCore/platform/text/LocaleICU.h
r116243 r121321 76 76 77 77 bool initializeShortDateFormat(); 78 UDateFormat* openDateFormat(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle) const; 78 79 79 80 #if ENABLE(CALENDAR_PICKER) 80 81 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); 82 83 void initializeCalendar(); 83 84 #endif
Note:
See TracChangeset
for help on using the changeset viewer.