Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: third_party/WebKit/Source/platform/text/LocaleICU.cpp

Issue 2811453002: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in platform/text (Closed)
Patch Set: fix Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
66 udat_close(short_time_format_); 66 udat_close(short_time_format_);
67 } 67 }
68 68
69 std::unique_ptr<LocaleICU> LocaleICU::Create(const char* locale_string) { 69 std::unique_ptr<LocaleICU> LocaleICU::Create(const char* locale_string) {
70 return WTF::WrapUnique(new LocaleICU(locale_string)); 70 return WTF::WrapUnique(new LocaleICU(locale_string));
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 buffer_length = unum_getSymbol(number_format_, symbol, 0, 0, &status); 75 int32_t buffer_length = unum_getSymbol(number_format_, 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(buffer_length); 79 StringBuffer<UChar> buffer(buffer_length);
80 status = U_ZERO_ERROR; 80 status = U_ZERO_ERROR;
81 unum_getSymbol(number_format_, symbol, buffer.Characters(), buffer_length, 81 unum_getSymbol(number_format_, symbol, buffer.Characters(), buffer_length,
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 buffer_length = 90 int32_t buffer_length =
91 unum_getTextAttribute(number_format_, tag, 0, 0, &status); 91 unum_getTextAttribute(number_format_, 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(buffer_length); 95 StringBuffer<UChar> buffer(buffer_length);
96 status = U_ZERO_ERROR; 96 status = U_ZERO_ERROR;
97 unum_getTextAttribute(number_format_, tag, buffer.Characters(), buffer_length, 97 unum_getTextAttribute(number_format_, tag, buffer.Characters(), buffer_length,
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 (did_create_decimal_format_) 106 if (did_create_decimal_format_)
107 return; 107 return;
108 did_create_decimal_format_ = true; 108 did_create_decimal_format_ = true;
109 UErrorCode status = U_ZERO_ERROR; 109 UErrorCode status = U_ZERO_ERROR;
110 number_format_ = unum_open(UNUM_DECIMAL, 0, 0, locale_.Data(), 0, &status); 110 number_format_ = unum_open(UNUM_DECIMAL, 0, 0, locale_.Data(), 0, &status);
111 if (!U_SUCCESS(status)) 111 if (!U_SUCCESS(status))
112 return; 112 return;
113 113
114 Vector<String, kDecimalSymbolsSize> symbols; 114 Vector<String, kDecimalSymbolsSize> 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() == kDecimalSymbolsSize); 127 DCHECK_EQ(symbols.size(), kDecimalSymbolsSize);
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 (did_create_short_date_format_) 135 if (did_create_short_date_format_)
136 return short_date_format_; 136 return short_date_format_;
137 short_date_format_ = OpenDateFormat(UDAT_NONE, UDAT_SHORT); 137 short_date_format_ = OpenDateFormat(UDAT_NONE, UDAT_SHORT);
(...skipping 15 matching lines...) Expand all
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 is_short) const { 156 bool is_short) const {
157 const UChar kMonthPattern[4] = {'L', 'L', 'L', 'L'}; 157 const UChar kMonthPattern[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, locale_.Data(), 0, -1, 160 udat_open(UDAT_PATTERN, UDAT_PATTERN, locale_.Data(), 0, -1,
161 kMonthPattern, is_short ? 3 : 4, &status); 161 kMonthPattern, is_short ? 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* date_format) { 167 static String GetDateFormatPattern(const UDateFormat* date_format) {
168 if (!date_format) 168 if (!date_format)
169 return g_empty_string; 169 return g_empty_string;
170 170
171 UErrorCode status = U_ZERO_ERROR; 171 UErrorCode status = U_ZERO_ERROR;
172 int32_t length = udat_toPattern(date_format, TRUE, 0, 0, &status); 172 int32_t length = udat_toPattern(date_format, TRUE, 0, 0, &status);
173 if (status != U_BUFFER_OVERFLOW_ERROR || !length) 173 if (status != U_BUFFER_OVERFLOW_ERROR || !length)
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 short_stand_alone_month_labels_ = ShortMonthLabels(); 453 short_stand_alone_month_labels_ = ShortMonthLabels();
454 return short_stand_alone_month_labels_; 454 return short_stand_alone_month_labels_;
455 } 455 }
456 456
457 const Vector<String>& LocaleICU::TimeAMPMLabels() { 457 const Vector<String>& LocaleICU::TimeAMPMLabels() {
458 InitializeDateTimeFormat(); 458 InitializeDateTimeFormat();
459 return time_ampm_labels_; 459 return time_ampm_labels_;
460 } 460 }
461 461
462 } // namespace blink 462 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/text/DecodeEscapeSequences.h ('k') | third_party/WebKit/Source/platform/text/LocaleMac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698