| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 udat_close(m_shortTimeFormat); | 66 udat_close(m_shortTimeFormat); |
| 67 } | 67 } |
| 68 | 68 |
| 69 std::unique_ptr<LocaleICU> LocaleICU::create(const char* localeString) { | 69 std::unique_ptr<LocaleICU> LocaleICU::create(const char* localeString) { |
| 70 return WTF::wrapUnique(new LocaleICU(localeString)); | 70 return WTF::wrapUnique(new LocaleICU(localeString)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 String LocaleICU::decimalSymbol(UNumberFormatSymbol symbol) { | 73 String LocaleICU::decimalSymbol(UNumberFormatSymbol symbol) { |
| 74 UErrorCode status = U_ZERO_ERROR; | 74 UErrorCode status = U_ZERO_ERROR; |
| 75 int32_t bufferLength = unum_getSymbol(m_numberFormat, symbol, 0, 0, &status); | 75 int32_t bufferLength = unum_getSymbol(m_numberFormat, symbol, 0, 0, &status); |
| 76 ASSERT(U_SUCCESS(status) || status == U_BUFFER_OVERFLOW_ERROR); | 76 DCHECK(U_SUCCESS(status) || status == U_BUFFER_OVERFLOW_ERROR); |
| 77 if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) | 77 if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) |
| 78 return String(); | 78 return String(); |
| 79 StringBuffer<UChar> buffer(bufferLength); | 79 StringBuffer<UChar> buffer(bufferLength); |
| 80 status = U_ZERO_ERROR; | 80 status = U_ZERO_ERROR; |
| 81 unum_getSymbol(m_numberFormat, symbol, buffer.characters(), bufferLength, | 81 unum_getSymbol(m_numberFormat, symbol, buffer.characters(), bufferLength, |
| 82 &status); | 82 &status); |
| 83 if (U_FAILURE(status)) | 83 if (U_FAILURE(status)) |
| 84 return String(); | 84 return String(); |
| 85 return String::adopt(buffer); | 85 return String::adopt(buffer); |
| 86 } | 86 } |
| 87 | 87 |
| 88 String LocaleICU::decimalTextAttribute(UNumberFormatTextAttribute tag) { | 88 String LocaleICU::decimalTextAttribute(UNumberFormatTextAttribute tag) { |
| 89 UErrorCode status = U_ZERO_ERROR; | 89 UErrorCode status = U_ZERO_ERROR; |
| 90 int32_t bufferLength = | 90 int32_t bufferLength = |
| 91 unum_getTextAttribute(m_numberFormat, tag, 0, 0, &status); | 91 unum_getTextAttribute(m_numberFormat, tag, 0, 0, &status); |
| 92 ASSERT(U_SUCCESS(status) || status == U_BUFFER_OVERFLOW_ERROR); | 92 DCHECK(U_SUCCESS(status) || status == U_BUFFER_OVERFLOW_ERROR); |
| 93 if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) | 93 if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) |
| 94 return String(); | 94 return String(); |
| 95 StringBuffer<UChar> buffer(bufferLength); | 95 StringBuffer<UChar> buffer(bufferLength); |
| 96 status = U_ZERO_ERROR; | 96 status = U_ZERO_ERROR; |
| 97 unum_getTextAttribute(m_numberFormat, tag, buffer.characters(), bufferLength, | 97 unum_getTextAttribute(m_numberFormat, tag, buffer.characters(), bufferLength, |
| 98 &status); | 98 &status); |
| 99 ASSERT(U_SUCCESS(status)); | 99 DCHECK(U_SUCCESS(status)); |
| 100 if (U_FAILURE(status)) | 100 if (U_FAILURE(status)) |
| 101 return String(); | 101 return String(); |
| 102 return String::adopt(buffer); | 102 return String::adopt(buffer); |
| 103 } | 103 } |
| 104 | 104 |
| 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.push_back(decimalSymbol(UNUM_ZERO_DIGIT_SYMBOL)); | 115 symbols.push_back(decimalSymbol(UNUM_ZERO_DIGIT_SYMBOL)); |
| 116 symbols.push_back(decimalSymbol(UNUM_ONE_DIGIT_SYMBOL)); | 116 symbols.push_back(decimalSymbol(UNUM_ONE_DIGIT_SYMBOL)); |
| 117 symbols.push_back(decimalSymbol(UNUM_TWO_DIGIT_SYMBOL)); | 117 symbols.push_back(decimalSymbol(UNUM_TWO_DIGIT_SYMBOL)); |
| 118 symbols.push_back(decimalSymbol(UNUM_THREE_DIGIT_SYMBOL)); | 118 symbols.push_back(decimalSymbol(UNUM_THREE_DIGIT_SYMBOL)); |
| 119 symbols.push_back(decimalSymbol(UNUM_FOUR_DIGIT_SYMBOL)); | 119 symbols.push_back(decimalSymbol(UNUM_FOUR_DIGIT_SYMBOL)); |
| 120 symbols.push_back(decimalSymbol(UNUM_FIVE_DIGIT_SYMBOL)); | 120 symbols.push_back(decimalSymbol(UNUM_FIVE_DIGIT_SYMBOL)); |
| 121 symbols.push_back(decimalSymbol(UNUM_SIX_DIGIT_SYMBOL)); | 121 symbols.push_back(decimalSymbol(UNUM_SIX_DIGIT_SYMBOL)); |
| 122 symbols.push_back(decimalSymbol(UNUM_SEVEN_DIGIT_SYMBOL)); | 122 symbols.push_back(decimalSymbol(UNUM_SEVEN_DIGIT_SYMBOL)); |
| 123 symbols.push_back(decimalSymbol(UNUM_EIGHT_DIGIT_SYMBOL)); | 123 symbols.push_back(decimalSymbol(UNUM_EIGHT_DIGIT_SYMBOL)); |
| 124 symbols.push_back(decimalSymbol(UNUM_NINE_DIGIT_SYMBOL)); | 124 symbols.push_back(decimalSymbol(UNUM_NINE_DIGIT_SYMBOL)); |
| 125 symbols.push_back(decimalSymbol(UNUM_DECIMAL_SEPARATOR_SYMBOL)); | 125 symbols.push_back(decimalSymbol(UNUM_DECIMAL_SEPARATOR_SYMBOL)); |
| 126 symbols.push_back(decimalSymbol(UNUM_GROUPING_SEPARATOR_SYMBOL)); | 126 symbols.push_back(decimalSymbol(UNUM_GROUPING_SEPARATOR_SYMBOL)); |
| 127 ASSERT(symbols.size() == DecimalSymbolsSize); | 127 DCHECK_EQ(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; |
| 137 m_shortDateFormat = openDateFormat(UDAT_NONE, UDAT_SHORT); | 137 m_shortDateFormat = openDateFormat(UDAT_NONE, UDAT_SHORT); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 153 // display context to 'standalone'. See | 153 // display context to 'standalone'. See |
| 154 // http://bugs.icu-project.org/trac/ticket/11552 | 154 // http://bugs.icu-project.org/trac/ticket/11552 |
| 155 UDateFormat* LocaleICU::openDateFormatForStandAloneMonthLabels( | 155 UDateFormat* LocaleICU::openDateFormatForStandAloneMonthLabels( |
| 156 bool isShort) const { | 156 bool isShort) const { |
| 157 const UChar monthPattern[4] = {'L', 'L', 'L', 'L'}; | 157 const UChar monthPattern[4] = {'L', 'L', 'L', 'L'}; |
| 158 UErrorCode status = U_ZERO_ERROR; | 158 UErrorCode status = U_ZERO_ERROR; |
| 159 UDateFormat* formatter = | 159 UDateFormat* formatter = |
| 160 udat_open(UDAT_PATTERN, UDAT_PATTERN, m_locale.data(), 0, -1, | 160 udat_open(UDAT_PATTERN, UDAT_PATTERN, m_locale.data(), 0, -1, |
| 161 monthPattern, isShort ? 3 : 4, &status); | 161 monthPattern, isShort ? 3 : 4, &status); |
| 162 udat_setContext(formatter, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, &status); | 162 udat_setContext(formatter, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, &status); |
| 163 ASSERT(U_SUCCESS(status)); | 163 DCHECK(U_SUCCESS(status)); |
| 164 return formatter; | 164 return formatter; |
| 165 } | 165 } |
| 166 | 166 |
| 167 static String getDateFormatPattern(const UDateFormat* dateFormat) { | 167 static String getDateFormatPattern(const UDateFormat* dateFormat) { |
| 168 if (!dateFormat) | 168 if (!dateFormat) |
| 169 return emptyString; | 169 return emptyString; |
| 170 | 170 |
| 171 UErrorCode status = U_ZERO_ERROR; | 171 UErrorCode status = U_ZERO_ERROR; |
| 172 int32_t length = udat_toPattern(dateFormat, TRUE, 0, 0, &status); | 172 int32_t length = udat_toPattern(dateFormat, TRUE, 0, 0, &status); |
| 173 if (status != U_BUFFER_OVERFLOW_ERROR || !length) | 173 if (status != U_BUFFER_OVERFLOW_ERROR || !length) |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |