| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011,2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011,2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 void LocaleICU::initializeLocaleData() { | 105 void LocaleICU::initializeLocaleData() { |
| 106 if (m_didCreateDecimalFormat) | 106 if (m_didCreateDecimalFormat) |
| 107 return; | 107 return; |
| 108 m_didCreateDecimalFormat = true; | 108 m_didCreateDecimalFormat = true; |
| 109 UErrorCode status = U_ZERO_ERROR; | 109 UErrorCode status = U_ZERO_ERROR; |
| 110 m_numberFormat = unum_open(UNUM_DECIMAL, 0, 0, m_locale.data(), 0, &status); | 110 m_numberFormat = unum_open(UNUM_DECIMAL, 0, 0, m_locale.data(), 0, &status); |
| 111 if (!U_SUCCESS(status)) | 111 if (!U_SUCCESS(status)) |
| 112 return; | 112 return; |
| 113 | 113 |
| 114 Vector<String, DecimalSymbolsSize> symbols; | 114 Vector<String, DecimalSymbolsSize> symbols; |
| 115 symbols.append(decimalSymbol(UNUM_ZERO_DIGIT_SYMBOL)); | 115 symbols.push_back(decimalSymbol(UNUM_ZERO_DIGIT_SYMBOL)); |
| 116 symbols.append(decimalSymbol(UNUM_ONE_DIGIT_SYMBOL)); | 116 symbols.push_back(decimalSymbol(UNUM_ONE_DIGIT_SYMBOL)); |
| 117 symbols.append(decimalSymbol(UNUM_TWO_DIGIT_SYMBOL)); | 117 symbols.push_back(decimalSymbol(UNUM_TWO_DIGIT_SYMBOL)); |
| 118 symbols.append(decimalSymbol(UNUM_THREE_DIGIT_SYMBOL)); | 118 symbols.push_back(decimalSymbol(UNUM_THREE_DIGIT_SYMBOL)); |
| 119 symbols.append(decimalSymbol(UNUM_FOUR_DIGIT_SYMBOL)); | 119 symbols.push_back(decimalSymbol(UNUM_FOUR_DIGIT_SYMBOL)); |
| 120 symbols.append(decimalSymbol(UNUM_FIVE_DIGIT_SYMBOL)); | 120 symbols.push_back(decimalSymbol(UNUM_FIVE_DIGIT_SYMBOL)); |
| 121 symbols.append(decimalSymbol(UNUM_SIX_DIGIT_SYMBOL)); | 121 symbols.push_back(decimalSymbol(UNUM_SIX_DIGIT_SYMBOL)); |
| 122 symbols.append(decimalSymbol(UNUM_SEVEN_DIGIT_SYMBOL)); | 122 symbols.push_back(decimalSymbol(UNUM_SEVEN_DIGIT_SYMBOL)); |
| 123 symbols.append(decimalSymbol(UNUM_EIGHT_DIGIT_SYMBOL)); | 123 symbols.push_back(decimalSymbol(UNUM_EIGHT_DIGIT_SYMBOL)); |
| 124 symbols.append(decimalSymbol(UNUM_NINE_DIGIT_SYMBOL)); | 124 symbols.push_back(decimalSymbol(UNUM_NINE_DIGIT_SYMBOL)); |
| 125 symbols.append(decimalSymbol(UNUM_DECIMAL_SEPARATOR_SYMBOL)); | 125 symbols.push_back(decimalSymbol(UNUM_DECIMAL_SEPARATOR_SYMBOL)); |
| 126 symbols.append(decimalSymbol(UNUM_GROUPING_SEPARATOR_SYMBOL)); | 126 symbols.push_back(decimalSymbol(UNUM_GROUPING_SEPARATOR_SYMBOL)); |
| 127 ASSERT(symbols.size() == DecimalSymbolsSize); | 127 ASSERT(symbols.size() == DecimalSymbolsSize); |
| 128 setLocaleData(symbols, decimalTextAttribute(UNUM_POSITIVE_PREFIX), | 128 setLocaleData(symbols, decimalTextAttribute(UNUM_POSITIVE_PREFIX), |
| 129 decimalTextAttribute(UNUM_POSITIVE_SUFFIX), | 129 decimalTextAttribute(UNUM_POSITIVE_SUFFIX), |
| 130 decimalTextAttribute(UNUM_NEGATIVE_PREFIX), | 130 decimalTextAttribute(UNUM_NEGATIVE_PREFIX), |
| 131 decimalTextAttribute(UNUM_NEGATIVE_SUFFIX)); | 131 decimalTextAttribute(UNUM_NEGATIVE_SUFFIX)); |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool LocaleICU::initializeShortDateFormat() { | 134 bool LocaleICU::initializeShortDateFormat() { |
| 135 if (m_didCreateShortDateFormat) | 135 if (m_didCreateShortDateFormat) |
| 136 return m_shortDateFormat; | 136 return m_shortDateFormat; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 status = U_ZERO_ERROR; | 210 status = U_ZERO_ERROR; |
| 211 if (isStandAloneMonth) { | 211 if (isStandAloneMonth) { |
| 212 udat_format(dateFormat, kEpoch + i * kMonth, buffer.characters(), length, | 212 udat_format(dateFormat, kEpoch + i * kMonth, buffer.characters(), length, |
| 213 0, &status); | 213 0, &status); |
| 214 } else { | 214 } else { |
| 215 udat_getSymbols(dateFormat, type, startIndex + i, buffer.characters(), | 215 udat_getSymbols(dateFormat, type, startIndex + i, buffer.characters(), |
| 216 length, &status); | 216 length, &status); |
| 217 } | 217 } |
| 218 if (U_FAILURE(status)) | 218 if (U_FAILURE(status)) |
| 219 return std::unique_ptr<Vector<String>>(); | 219 return std::unique_ptr<Vector<String>>(); |
| 220 labels->append(String::adopt(buffer)); | 220 labels->push_back(String::adopt(buffer)); |
| 221 } | 221 } |
| 222 return labels; | 222 return labels; |
| 223 } | 223 } |
| 224 | 224 |
| 225 static std::unique_ptr<Vector<String>> createFallbackWeekDayShortLabels() { | 225 static std::unique_ptr<Vector<String>> createFallbackWeekDayShortLabels() { |
| 226 std::unique_ptr<Vector<String>> labels = WTF::makeUnique<Vector<String>>(); | 226 std::unique_ptr<Vector<String>> labels = WTF::makeUnique<Vector<String>>(); |
| 227 labels->reserveCapacity(7); | 227 labels->reserveCapacity(7); |
| 228 labels->append("Sun"); | 228 labels->push_back("Sun"); |
| 229 labels->append("Mon"); | 229 labels->push_back("Mon"); |
| 230 labels->append("Tue"); | 230 labels->push_back("Tue"); |
| 231 labels->append("Wed"); | 231 labels->push_back("Wed"); |
| 232 labels->append("Thu"); | 232 labels->push_back("Thu"); |
| 233 labels->append("Fri"); | 233 labels->push_back("Fri"); |
| 234 labels->append("Sat"); | 234 labels->push_back("Sat"); |
| 235 return labels; | 235 return labels; |
| 236 } | 236 } |
| 237 | 237 |
| 238 void LocaleICU::initializeCalendar() { | 238 void LocaleICU::initializeCalendar() { |
| 239 if (m_weekDayShortLabels) | 239 if (m_weekDayShortLabels) |
| 240 return; | 240 return; |
| 241 | 241 |
| 242 if (!initializeShortDateFormat()) { | 242 if (!initializeShortDateFormat()) { |
| 243 m_firstDayOfWeek = 0; | 243 m_firstDayOfWeek = 0; |
| 244 m_weekDayShortLabels = createFallbackWeekDayShortLabels(); | 244 m_weekDayShortLabels = createFallbackWeekDayShortLabels(); |
| 245 return; | 245 return; |
| 246 } | 246 } |
| 247 m_firstDayOfWeek = ucal_getAttribute(udat_getCalendar(m_shortDateFormat), | 247 m_firstDayOfWeek = ucal_getAttribute(udat_getCalendar(m_shortDateFormat), |
| 248 UCAL_FIRST_DAY_OF_WEEK) - | 248 UCAL_FIRST_DAY_OF_WEEK) - |
| 249 UCAL_SUNDAY; | 249 UCAL_SUNDAY; |
| 250 | 250 |
| 251 m_weekDayShortLabels = | 251 m_weekDayShortLabels = |
| 252 createLabelVector(m_shortDateFormat, UDAT_SHORT_WEEKDAYS, UCAL_SUNDAY, 7); | 252 createLabelVector(m_shortDateFormat, UDAT_SHORT_WEEKDAYS, UCAL_SUNDAY, 7); |
| 253 if (!m_weekDayShortLabels) | 253 if (!m_weekDayShortLabels) |
| 254 m_weekDayShortLabels = createFallbackWeekDayShortLabels(); | 254 m_weekDayShortLabels = createFallbackWeekDayShortLabels(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 static std::unique_ptr<Vector<String>> createFallbackMonthLabels() { | 257 static std::unique_ptr<Vector<String>> createFallbackMonthLabels() { |
| 258 std::unique_ptr<Vector<String>> labels = WTF::makeUnique<Vector<String>>(); | 258 std::unique_ptr<Vector<String>> labels = WTF::makeUnique<Vector<String>>(); |
| 259 labels->reserveCapacity(WTF_ARRAY_LENGTH(WTF::monthFullName)); | 259 labels->reserveCapacity(WTF_ARRAY_LENGTH(WTF::monthFullName)); |
| 260 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthFullName); ++i) | 260 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthFullName); ++i) |
| 261 labels->append(WTF::monthFullName[i]); | 261 labels->push_back(WTF::monthFullName[i]); |
| 262 return labels; | 262 return labels; |
| 263 } | 263 } |
| 264 | 264 |
| 265 const Vector<String>& LocaleICU::monthLabels() { | 265 const Vector<String>& LocaleICU::monthLabels() { |
| 266 if (m_monthLabels) | 266 if (m_monthLabels) |
| 267 return *m_monthLabels; | 267 return *m_monthLabels; |
| 268 if (initializeShortDateFormat()) { | 268 if (initializeShortDateFormat()) { |
| 269 m_monthLabels = | 269 m_monthLabels = |
| 270 createLabelVector(m_shortDateFormat, UDAT_MONTHS, UCAL_JANUARY, 12); | 270 createLabelVector(m_shortDateFormat, UDAT_MONTHS, UCAL_JANUARY, 12); |
| 271 if (m_monthLabels) | 271 if (m_monthLabels) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 287 | 287 |
| 288 bool LocaleICU::isRTL() { | 288 bool LocaleICU::isRTL() { |
| 289 UErrorCode status = U_ZERO_ERROR; | 289 UErrorCode status = U_ZERO_ERROR; |
| 290 return uloc_getCharacterOrientation(m_locale.data(), &status) == | 290 return uloc_getCharacterOrientation(m_locale.data(), &status) == |
| 291 ULOC_LAYOUT_RTL; | 291 ULOC_LAYOUT_RTL; |
| 292 } | 292 } |
| 293 | 293 |
| 294 static std::unique_ptr<Vector<String>> createFallbackAMPMLabels() { | 294 static std::unique_ptr<Vector<String>> createFallbackAMPMLabels() { |
| 295 std::unique_ptr<Vector<String>> labels = WTF::makeUnique<Vector<String>>(); | 295 std::unique_ptr<Vector<String>> labels = WTF::makeUnique<Vector<String>>(); |
| 296 labels->reserveCapacity(2); | 296 labels->reserveCapacity(2); |
| 297 labels->append("AM"); | 297 labels->push_back("AM"); |
| 298 labels->append("PM"); | 298 labels->push_back("PM"); |
| 299 return labels; | 299 return labels; |
| 300 } | 300 } |
| 301 | 301 |
| 302 void LocaleICU::initializeDateTimeFormat() { | 302 void LocaleICU::initializeDateTimeFormat() { |
| 303 if (m_didCreateTimeFormat) | 303 if (m_didCreateTimeFormat) |
| 304 return; | 304 return; |
| 305 | 305 |
| 306 // We assume ICU medium time pattern and short time pattern are compatible | 306 // We assume ICU medium time pattern and short time pattern are compatible |
| 307 // with LDML, because ICU specific pattern character "V" doesn't appear | 307 // with LDML, because ICU specific pattern character "V" doesn't appear |
| 308 // in both medium and short time pattern. | 308 // in both medium and short time pattern. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 return m_shortMonthLabels; | 407 return m_shortMonthLabels; |
| 408 if (initializeShortDateFormat()) { | 408 if (initializeShortDateFormat()) { |
| 409 if (std::unique_ptr<Vector<String>> labels = createLabelVector( | 409 if (std::unique_ptr<Vector<String>> labels = createLabelVector( |
| 410 m_shortDateFormat, UDAT_SHORT_MONTHS, UCAL_JANUARY, 12)) { | 410 m_shortDateFormat, UDAT_SHORT_MONTHS, UCAL_JANUARY, 12)) { |
| 411 m_shortMonthLabels = *labels; | 411 m_shortMonthLabels = *labels; |
| 412 return m_shortMonthLabels; | 412 return m_shortMonthLabels; |
| 413 } | 413 } |
| 414 } | 414 } |
| 415 m_shortMonthLabels.reserveCapacity(WTF_ARRAY_LENGTH(WTF::monthName)); | 415 m_shortMonthLabels.reserveCapacity(WTF_ARRAY_LENGTH(WTF::monthName)); |
| 416 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthName); ++i) | 416 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthName); ++i) |
| 417 m_shortMonthLabels.append(WTF::monthName[i]); | 417 m_shortMonthLabels.push_back(WTF::monthName[i]); |
| 418 return m_shortMonthLabels; | 418 return m_shortMonthLabels; |
| 419 } | 419 } |
| 420 | 420 |
| 421 const Vector<String>& LocaleICU::standAloneMonthLabels() { | 421 const Vector<String>& LocaleICU::standAloneMonthLabels() { |
| 422 if (!m_standAloneMonthLabels.isEmpty()) | 422 if (!m_standAloneMonthLabels.isEmpty()) |
| 423 return m_standAloneMonthLabels; | 423 return m_standAloneMonthLabels; |
| 424 UDateFormat* monthFormatter = openDateFormatForStandAloneMonthLabels(false); | 424 UDateFormat* monthFormatter = openDateFormatForStandAloneMonthLabels(false); |
| 425 if (monthFormatter) { | 425 if (monthFormatter) { |
| 426 if (std::unique_ptr<Vector<String>> labels = createLabelVector( | 426 if (std::unique_ptr<Vector<String>> labels = createLabelVector( |
| 427 monthFormatter, UDAT_STANDALONE_MONTHS, UCAL_JANUARY, 12)) { | 427 monthFormatter, UDAT_STANDALONE_MONTHS, UCAL_JANUARY, 12)) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 451 m_shortStandAloneMonthLabels = shortMonthLabels(); | 451 m_shortStandAloneMonthLabels = shortMonthLabels(); |
| 452 return m_shortStandAloneMonthLabels; | 452 return m_shortStandAloneMonthLabels; |
| 453 } | 453 } |
| 454 | 454 |
| 455 const Vector<String>& LocaleICU::timeAMPMLabels() { | 455 const Vector<String>& LocaleICU::timeAMPMLabels() { |
| 456 initializeDateTimeFormat(); | 456 initializeDateTimeFormat(); |
| 457 return m_timeAMPMLabels; | 457 return m_timeAMPMLabels; |
| 458 } | 458 } |
| 459 | 459 |
| 460 } // namespace blink | 460 } // namespace blink |
| OLD | NEW |