OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * | 3 * |
4 * Copyright (C) 2013-2014, International Business Machines | 4 * Copyright (C) 2013-2015, International Business Machines |
5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
6 * | 6 * |
7 ******************************************************************************* | 7 ******************************************************************************* |
8 * file name: listformatter.cpp | 8 * file name: listformatter.cpp |
9 * encoding: US-ASCII | 9 * encoding: US-ASCII |
10 * tab size: 8 (not used) | 10 * tab size: 8 (not used) |
11 * indentation:4 | 11 * indentation:4 |
12 * | 12 * |
13 * created on: 2012aug27 | 13 * created on: 2012aug27 |
14 * created by: Umesh P. Nair | 14 * created by: Umesh P. Nair |
(...skipping 14 matching lines...) Expand all Loading... |
29 struct ListFormatInternal : public UMemory { | 29 struct ListFormatInternal : public UMemory { |
30 SimplePatternFormatter twoPattern; | 30 SimplePatternFormatter twoPattern; |
31 SimplePatternFormatter startPattern; | 31 SimplePatternFormatter startPattern; |
32 SimplePatternFormatter middlePattern; | 32 SimplePatternFormatter middlePattern; |
33 SimplePatternFormatter endPattern; | 33 SimplePatternFormatter endPattern; |
34 | 34 |
35 ListFormatInternal( | 35 ListFormatInternal( |
36 const UnicodeString& two, | 36 const UnicodeString& two, |
37 const UnicodeString& start, | 37 const UnicodeString& start, |
38 const UnicodeString& middle, | 38 const UnicodeString& middle, |
39 const UnicodeString& end) : | 39 const UnicodeString& end, |
40 twoPattern(two), | 40 UErrorCode &errorCode) : |
41 startPattern(start), | 41 twoPattern(two, 2, 2, errorCode), |
42 middlePattern(middle), | 42 startPattern(start, 2, 2, errorCode), |
43 endPattern(end) {} | 43 middlePattern(middle, 2, 2, errorCode), |
| 44 endPattern(end, 2, 2, errorCode) {} |
44 | 45 |
45 ListFormatInternal(const ListFormatData &data) : | 46 ListFormatInternal(const ListFormatData &data) : |
46 twoPattern(data.twoPattern), | 47 twoPattern(data.twoPattern), |
47 startPattern(data.startPattern), | 48 startPattern(data.startPattern), |
48 middlePattern(data.middlePattern), | 49 middlePattern(data.middlePattern), |
49 endPattern(data.endPattern) { } | 50 endPattern(data.endPattern) { } |
50 | 51 |
51 ListFormatInternal(const ListFormatInternal &other) : | 52 ListFormatInternal(const ListFormatInternal &other) : |
52 twoPattern(other.twoPattern), | 53 twoPattern(other.twoPattern), |
53 startPattern(other.startPattern), | 54 startPattern(other.startPattern), |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 } | 185 } |
185 UnicodeString two, start, middle, end; | 186 UnicodeString two, start, middle, end; |
186 getStringByKey(rb, "2", two, errorCode); | 187 getStringByKey(rb, "2", two, errorCode); |
187 getStringByKey(rb, "start", start, errorCode); | 188 getStringByKey(rb, "start", start, errorCode); |
188 getStringByKey(rb, "middle", middle, errorCode); | 189 getStringByKey(rb, "middle", middle, errorCode); |
189 getStringByKey(rb, "end", end, errorCode); | 190 getStringByKey(rb, "end", end, errorCode); |
190 ures_close(rb); | 191 ures_close(rb); |
191 if (U_FAILURE(errorCode)) { | 192 if (U_FAILURE(errorCode)) { |
192 return NULL; | 193 return NULL; |
193 } | 194 } |
194 ListFormatInternal* result = new ListFormatInternal(two, start, middle, end)
; | 195 ListFormatInternal* result = new ListFormatInternal(two, start, middle, end,
errorCode); |
195 if (result == NULL) { | 196 if (result == NULL) { |
196 errorCode = U_MEMORY_ALLOCATION_ERROR; | 197 errorCode = U_MEMORY_ALLOCATION_ERROR; |
197 return NULL; | 198 return NULL; |
198 } | 199 } |
| 200 if (U_FAILURE(errorCode)) { |
| 201 delete result; |
| 202 return NULL; |
| 203 } |
199 return result; | 204 return result; |
200 } | 205 } |
201 | 206 |
202 static void getStringByKey(const UResourceBundle* rb, const char* key, UnicodeSt
ring& result, UErrorCode& errorCode) { | 207 static void getStringByKey(const UResourceBundle* rb, const char* key, UnicodeSt
ring& result, UErrorCode& errorCode) { |
203 int32_t len; | 208 int32_t len; |
204 const UChar* ustr = ures_getStringByKeyWithFallback(rb, key, &len, &errorCod
e); | 209 const UChar* ustr = ures_getStringByKeyWithFallback(rb, key, &len, &errorCod
e); |
205 if (U_FAILURE(errorCode)) { | 210 if (U_FAILURE(errorCode)) { |
206 return; | 211 return; |
207 } | 212 } |
208 result.setTo(ustr, len); | 213 result.setTo(ustr, len); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 if (U_SUCCESS(errorCode)) { | 360 if (U_SUCCESS(errorCode)) { |
356 if (offset >= 0) { | 361 if (offset >= 0) { |
357 offset += appendTo.length(); | 362 offset += appendTo.length(); |
358 } | 363 } |
359 appendTo += result; | 364 appendTo += result; |
360 } | 365 } |
361 return appendTo; | 366 return appendTo; |
362 } | 367 } |
363 | 368 |
364 U_NAMESPACE_END | 369 U_NAMESPACE_END |
OLD | NEW |