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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 m_didCreateTimeFormat(false) {} | 60 m_didCreateTimeFormat(false) {} |
61 | 61 |
62 LocaleICU::~LocaleICU() { | 62 LocaleICU::~LocaleICU() { |
63 unum_close(m_numberFormat); | 63 unum_close(m_numberFormat); |
64 udat_close(m_shortDateFormat); | 64 udat_close(m_shortDateFormat); |
65 udat_close(m_mediumTimeFormat); | 65 udat_close(m_mediumTimeFormat); |
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 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 ASSERT(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; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 std::unique_ptr<Vector<String>> LocaleICU::createLabelVector( | 183 std::unique_ptr<Vector<String>> LocaleICU::createLabelVector( |
184 const UDateFormat* dateFormat, | 184 const UDateFormat* dateFormat, |
185 UDateFormatSymbolType type, | 185 UDateFormatSymbolType type, |
186 int32_t startIndex, | 186 int32_t startIndex, |
187 int32_t size) { | 187 int32_t size) { |
188 if (!dateFormat) | 188 if (!dateFormat) |
189 return std::unique_ptr<Vector<String>>(); | 189 return std::unique_ptr<Vector<String>>(); |
190 if (udat_countSymbols(dateFormat, type) != startIndex + size) | 190 if (udat_countSymbols(dateFormat, type) != startIndex + size) |
191 return std::unique_ptr<Vector<String>>(); | 191 return std::unique_ptr<Vector<String>>(); |
192 | 192 |
193 std::unique_ptr<Vector<String>> labels = makeUnique<Vector<String>>(); | 193 std::unique_ptr<Vector<String>> labels = WTF::makeUnique<Vector<String>>(); |
194 labels->reserveCapacity(size); | 194 labels->reserveCapacity(size); |
195 bool isStandAloneMonth = (type == UDAT_STANDALONE_MONTHS) || | 195 bool isStandAloneMonth = (type == UDAT_STANDALONE_MONTHS) || |
196 (type == UDAT_STANDALONE_SHORT_MONTHS); | 196 (type == UDAT_STANDALONE_SHORT_MONTHS); |
197 for (int32_t i = 0; i < size; ++i) { | 197 for (int32_t i = 0; i < size; ++i) { |
198 UErrorCode status = U_ZERO_ERROR; | 198 UErrorCode status = U_ZERO_ERROR; |
199 int32_t length; | 199 int32_t length; |
200 static const UDate kEpoch = U_MILLIS_PER_DAY * 15u; // 1970-01-15 | 200 static const UDate kEpoch = U_MILLIS_PER_DAY * 15u; // 1970-01-15 |
201 static const UDate kMonth = U_MILLIS_PER_DAY * 30u; // 30 days in ms | 201 static const UDate kMonth = U_MILLIS_PER_DAY * 30u; // 30 days in ms |
202 if (isStandAloneMonth) { | 202 if (isStandAloneMonth) { |
203 length = udat_format(dateFormat, kEpoch + i * kMonth, 0, 0, 0, &status); | 203 length = udat_format(dateFormat, kEpoch + i * kMonth, 0, 0, 0, &status); |
(...skipping 12 matching lines...) Expand all Loading... |
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->append(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 = 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->append("Sun"); |
229 labels->append("Mon"); | 229 labels->append("Mon"); |
230 labels->append("Tue"); | 230 labels->append("Tue"); |
231 labels->append("Wed"); | 231 labels->append("Wed"); |
232 labels->append("Thu"); | 232 labels->append("Thu"); |
233 labels->append("Fri"); | 233 labels->append("Fri"); |
234 labels->append("Sat"); | 234 labels->append("Sat"); |
235 return labels; | 235 return labels; |
236 } | 236 } |
(...skipping 11 matching lines...) Expand all Loading... |
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 = 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->append(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()) { |
(...skipping 16 matching lines...) Expand all Loading... |
285 return m_firstDayOfWeek; | 285 return m_firstDayOfWeek; |
286 } | 286 } |
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 = 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->append("AM"); |
298 labels->append("PM"); | 298 labels->append("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 |
(...skipping 145 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 |