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

Side by Side Diff: Source/core/platform/text/LocaleICU.cpp

Issue 20002008: Don't use Vector<UChar> to build strings (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix unit test Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/platform/graphics/Color.cpp ('k') | Source/wtf/text/StringBuffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 18 matching lines...) Expand all
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/platform/text/LocaleICU.h" 32 #include "core/platform/text/LocaleICU.h"
33 33
34 #include <unicode/udatpg.h> 34 #include <unicode/udatpg.h>
35 #include <unicode/uloc.h> 35 #include <unicode/uloc.h>
36 #include <limits> 36 #include <limits>
37 #include "wtf/DateMath.h" 37 #include "wtf/DateMath.h"
38 #include "wtf/PassOwnPtr.h" 38 #include "wtf/PassOwnPtr.h"
39 #include "wtf/text/StringBuffer.h"
39 #include "wtf/text/StringBuilder.h" 40 #include "wtf/text/StringBuilder.h"
40 41
41 using namespace icu; 42 using namespace icu;
42 using namespace std; 43 using namespace std;
43 44
44 namespace WebCore { 45 namespace WebCore {
45 46
46 PassOwnPtr<Locale> Locale::create(const AtomicString& locale) 47 PassOwnPtr<Locale> Locale::create(const AtomicString& locale)
47 { 48 {
48 return LocaleICU::create(locale.string().utf8().data()); 49 return LocaleICU::create(locale.string().utf8().data());
(...skipping 27 matching lines...) Expand all
76 return adoptPtr(new LocaleICU(localeString)); 77 return adoptPtr(new LocaleICU(localeString));
77 } 78 }
78 79
79 String LocaleICU::decimalSymbol(UNumberFormatSymbol symbol) 80 String LocaleICU::decimalSymbol(UNumberFormatSymbol symbol)
80 { 81 {
81 UErrorCode status = U_ZERO_ERROR; 82 UErrorCode status = U_ZERO_ERROR;
82 int32_t bufferLength = unum_getSymbol(m_numberFormat, symbol, 0, 0, &status) ; 83 int32_t bufferLength = unum_getSymbol(m_numberFormat, symbol, 0, 0, &status) ;
83 ASSERT(U_SUCCESS(status) || status == U_BUFFER_OVERFLOW_ERROR); 84 ASSERT(U_SUCCESS(status) || status == U_BUFFER_OVERFLOW_ERROR);
84 if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) 85 if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR)
85 return String(); 86 return String();
86 Vector<UChar> buffer(bufferLength); 87 StringBuffer<UChar> buffer(bufferLength);
87 status = U_ZERO_ERROR; 88 status = U_ZERO_ERROR;
88 unum_getSymbol(m_numberFormat, symbol, buffer.data(), bufferLength, &status) ; 89 unum_getSymbol(m_numberFormat, symbol, buffer.characters(), bufferLength, &s tatus);
89 if (U_FAILURE(status)) 90 if (U_FAILURE(status))
90 return String(); 91 return String();
91 return String::adopt(buffer); 92 return String::adopt(buffer);
92 } 93 }
93 94
94 String LocaleICU::decimalTextAttribute(UNumberFormatTextAttribute tag) 95 String LocaleICU::decimalTextAttribute(UNumberFormatTextAttribute tag)
95 { 96 {
96 UErrorCode status = U_ZERO_ERROR; 97 UErrorCode status = U_ZERO_ERROR;
97 int32_t bufferLength = unum_getTextAttribute(m_numberFormat, tag, 0, 0, &sta tus); 98 int32_t bufferLength = unum_getTextAttribute(m_numberFormat, tag, 0, 0, &sta tus);
98 ASSERT(U_SUCCESS(status) || status == U_BUFFER_OVERFLOW_ERROR); 99 ASSERT(U_SUCCESS(status) || status == U_BUFFER_OVERFLOW_ERROR);
99 if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) 100 if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR)
100 return String(); 101 return String();
101 Vector<UChar> buffer(bufferLength); 102 StringBuffer<UChar> buffer(bufferLength);
102 status = U_ZERO_ERROR; 103 status = U_ZERO_ERROR;
103 unum_getTextAttribute(m_numberFormat, tag, buffer.data(), bufferLength, &sta tus); 104 unum_getTextAttribute(m_numberFormat, tag, buffer.characters(), bufferLength , &status);
104 ASSERT(U_SUCCESS(status)); 105 ASSERT(U_SUCCESS(status));
105 if (U_FAILURE(status)) 106 if (U_FAILURE(status))
106 return String(); 107 return String();
107 return String::adopt(buffer); 108 return String::adopt(buffer);
108 } 109 }
109 110
110 void LocaleICU::initializeLocaleData() 111 void LocaleICU::initializeLocaleData()
111 { 112 {
112 if (m_didCreateDecimalFormat) 113 if (m_didCreateDecimalFormat)
113 return; 114 return;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 153
153 static String getDateFormatPattern(const UDateFormat* dateFormat) 154 static String getDateFormatPattern(const UDateFormat* dateFormat)
154 { 155 {
155 if (!dateFormat) 156 if (!dateFormat)
156 return emptyString(); 157 return emptyString();
157 158
158 UErrorCode status = U_ZERO_ERROR; 159 UErrorCode status = U_ZERO_ERROR;
159 int32_t length = udat_toPattern(dateFormat, TRUE, 0, 0, &status); 160 int32_t length = udat_toPattern(dateFormat, TRUE, 0, 0, &status);
160 if (status != U_BUFFER_OVERFLOW_ERROR || !length) 161 if (status != U_BUFFER_OVERFLOW_ERROR || !length)
161 return emptyString(); 162 return emptyString();
162 Vector<UChar> buffer(length); 163 StringBuffer<UChar> buffer(length);
163 status = U_ZERO_ERROR; 164 status = U_ZERO_ERROR;
164 udat_toPattern(dateFormat, TRUE, buffer.data(), length, &status); 165 udat_toPattern(dateFormat, TRUE, buffer.characters(), length, &status);
165 if (U_FAILURE(status)) 166 if (U_FAILURE(status))
166 return emptyString(); 167 return emptyString();
167 return String::adopt(buffer); 168 return String::adopt(buffer);
168 } 169 }
169 170
170 PassOwnPtr<Vector<String> > LocaleICU::createLabelVector(const UDateFormat* date Format, UDateFormatSymbolType type, int32_t startIndex, int32_t size) 171 PassOwnPtr<Vector<String> > LocaleICU::createLabelVector(const UDateFormat* date Format, UDateFormatSymbolType type, int32_t startIndex, int32_t size)
171 { 172 {
172 if (!dateFormat) 173 if (!dateFormat)
173 return PassOwnPtr<Vector<String> >(); 174 return PassOwnPtr<Vector<String> >();
174 if (udat_countSymbols(dateFormat, type) != startIndex + size) 175 if (udat_countSymbols(dateFormat, type) != startIndex + size)
175 return PassOwnPtr<Vector<String> >(); 176 return PassOwnPtr<Vector<String> >();
176 177
177 OwnPtr<Vector<String> > labels = adoptPtr(new Vector<String>()); 178 OwnPtr<Vector<String> > labels = adoptPtr(new Vector<String>());
178 labels->reserveCapacity(size); 179 labels->reserveCapacity(size);
179 for (int32_t i = 0; i < size; ++i) { 180 for (int32_t i = 0; i < size; ++i) {
180 UErrorCode status = U_ZERO_ERROR; 181 UErrorCode status = U_ZERO_ERROR;
181 int32_t length = udat_getSymbols(dateFormat, type, startIndex + i, 0, 0, &status); 182 int32_t length = udat_getSymbols(dateFormat, type, startIndex + i, 0, 0, &status);
182 if (status != U_BUFFER_OVERFLOW_ERROR) 183 if (status != U_BUFFER_OVERFLOW_ERROR)
183 return PassOwnPtr<Vector<String> >(); 184 return PassOwnPtr<Vector<String> >();
184 Vector<UChar> buffer(length); 185 StringBuffer<UChar> buffer(length);
185 status = U_ZERO_ERROR; 186 status = U_ZERO_ERROR;
186 udat_getSymbols(dateFormat, type, startIndex + i, buffer.data(), length, &status); 187 udat_getSymbols(dateFormat, type, startIndex + i, buffer.characters(), l ength, &status);
187 if (U_FAILURE(status)) 188 if (U_FAILURE(status))
188 return PassOwnPtr<Vector<String> >(); 189 return PassOwnPtr<Vector<String> >();
189 labels->append(String::adopt(buffer)); 190 labels->append(String::adopt(buffer));
190 } 191 }
191 return labels.release(); 192 return labels.release();
192 } 193 }
193 194
194 #if ENABLE(CALENDAR_PICKER) 195 #if ENABLE(CALENDAR_PICKER)
195 static PassOwnPtr<Vector<String> > createFallbackWeekDayShortLabels() 196 static PassOwnPtr<Vector<String> > createFallbackWeekDayShortLabels()
196 { 197 {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 String format = ASCIILiteral("yyyy-MM"); 321 String format = ASCIILiteral("yyyy-MM");
321 UErrorCode status = U_ZERO_ERROR; 322 UErrorCode status = U_ZERO_ERROR;
322 UDateTimePatternGenerator* patternGenerator = udatpg_open(locale, &status); 323 UDateTimePatternGenerator* patternGenerator = udatpg_open(locale, &status);
323 if (!patternGenerator) 324 if (!patternGenerator)
324 return format; 325 return format;
325 status = U_ZERO_ERROR; 326 status = U_ZERO_ERROR;
326 Vector<UChar> skeletonCharacters; 327 Vector<UChar> skeletonCharacters;
327 skeleton.appendTo(skeletonCharacters); 328 skeleton.appendTo(skeletonCharacters);
328 int32_t length = udatpg_getBestPattern(patternGenerator, skeletonCharacters. data(), skeletonCharacters.size(), 0, 0, &status); 329 int32_t length = udatpg_getBestPattern(patternGenerator, skeletonCharacters. data(), skeletonCharacters.size(), 0, 0, &status);
329 if (status == U_BUFFER_OVERFLOW_ERROR && length) { 330 if (status == U_BUFFER_OVERFLOW_ERROR && length) {
330 Vector<UChar> buffer(length); 331 StringBuffer<UChar> buffer(length);
331 status = U_ZERO_ERROR; 332 status = U_ZERO_ERROR;
332 udatpg_getBestPattern(patternGenerator, skeletonCharacters.data(), skele tonCharacters.size(), buffer.data(), length, &status); 333 udatpg_getBestPattern(patternGenerator, skeletonCharacters.data(), skele tonCharacters.size(), buffer.characters(), length, &status);
333 if (U_SUCCESS(status)) 334 if (U_SUCCESS(status))
334 format = String::adopt(buffer); 335 format = String::adopt(buffer);
335 } 336 }
336 udatpg_close(patternGenerator); 337 udatpg_close(patternGenerator);
337 return format; 338 return format;
338 } 339 }
339 340
340 String LocaleICU::monthFormat() 341 String LocaleICU::monthFormat()
341 { 342 {
342 if (!m_monthFormat.isNull()) 343 if (!m_monthFormat.isNull())
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 425 }
425 426
426 const Vector<String>& LocaleICU::timeAMPMLabels() 427 const Vector<String>& LocaleICU::timeAMPMLabels()
427 { 428 {
428 initializeDateTimeFormat(); 429 initializeDateTimeFormat();
429 return m_timeAMPMLabels; 430 return m_timeAMPMLabels;
430 } 431 }
431 432
432 } // namespace WebCore 433 } // namespace WebCore
433 434
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/Color.cpp ('k') | Source/wtf/text/StringBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698