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

Side by Side Diff: source/i18n/udat.cpp

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 years, 11 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
« no previous file with comments | « source/i18n/ucurr.cpp ('k') | source/i18n/udatpg.cpp » ('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 ******************************************************************************* 2 *******************************************************************************
3 * Copyright (C) 1996-2014, International Business Machines 3 * Copyright (C) 1996-2015, International Business Machines
4 * Corporation and others. All Rights Reserved. 4 * Corporation and others. All Rights Reserved.
5 ******************************************************************************* 5 *******************************************************************************
6 */ 6 */
7 7
8 #include "unicode/utypes.h" 8 #include "unicode/utypes.h"
9 9
10 #if !UCONFIG_NO_FORMATTING 10 #if !UCONFIG_NO_FORMATTING
11 11
12 #include "unicode/udat.h" 12 #include "unicode/udat.h"
13 13
14 #include "unicode/uloc.h" 14 #include "unicode/uloc.h"
15 #include "unicode/datefmt.h" 15 #include "unicode/datefmt.h"
16 #include "unicode/timezone.h" 16 #include "unicode/timezone.h"
17 #include "unicode/smpdtfmt.h" 17 #include "unicode/smpdtfmt.h"
18 #include "unicode/fieldpos.h" 18 #include "unicode/fieldpos.h"
19 #include "unicode/parsepos.h" 19 #include "unicode/parsepos.h"
20 #include "unicode/calendar.h" 20 #include "unicode/calendar.h"
21 #include "unicode/numfmt.h" 21 #include "unicode/numfmt.h"
22 #include "unicode/dtfmtsym.h" 22 #include "unicode/dtfmtsym.h"
23 #include "unicode/ustring.h" 23 #include "unicode/ustring.h"
24 #include "unicode/udisplaycontext.h" 24 #include "unicode/udisplaycontext.h"
25 #include "unicode/ufieldpositer.h"
25 #include "cpputils.h" 26 #include "cpputils.h"
26 #include "reldtfmt.h" 27 #include "reldtfmt.h"
27 #include "umutex.h" 28 #include "umutex.h"
28 29
29 U_NAMESPACE_USE 30 U_NAMESPACE_USE
30 31
31 /** 32 /**
32 * Verify that fmt is a SimpleDateFormat. Invalid error if not. 33 * Verify that fmt is a SimpleDateFormat. Invalid error if not.
33 * @param fmt the UDateFormat, definitely a DateFormat, maybe something else 34 * @param fmt the UDateFormat, definitely a DateFormat, maybe something else
34 * @param status error code, will be set to failure if there is a familure or th e fmt is NULL. 35 * @param status error code, will be set to failure if there is a familure or th e fmt is NULL.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } 207 }
207 208
208 U_CAPI int32_t U_EXPORT2 209 U_CAPI int32_t U_EXPORT2
209 udat_format( const UDateFormat* format, 210 udat_format( const UDateFormat* format,
210 UDate dateToFormat, 211 UDate dateToFormat,
211 UChar* result, 212 UChar* result,
212 int32_t resultLength, 213 int32_t resultLength,
213 UFieldPosition* position, 214 UFieldPosition* position,
214 UErrorCode* status) 215 UErrorCode* status)
215 { 216 {
216 if(U_FAILURE(*status)) return -1; 217 if(U_FAILURE(*status)) {
218 return -1;
219 }
220 if (result == NULL ? resultLength != 0 : resultLength < 0) {
221 *status = U_ILLEGAL_ARGUMENT_ERROR;
222 return -1;
223 }
217 224
218 UnicodeString res; 225 UnicodeString res;
219 if(!(result==NULL && resultLength==0)) { 226 if (result != NULL) {
220 // NULL destination for pure preflighting: empty dummy string 227 // NULL destination for pure preflighting: empty dummy string
221 // otherwise, alias the destination buffer 228 // otherwise, alias the destination buffer
222 res.setTo(result, 0, resultLength); 229 res.setTo(result, 0, resultLength);
223 } 230 }
224 231
225 FieldPosition fp; 232 FieldPosition fp;
226 233
227 if(position != 0) 234 if(position != 0)
228 fp.setField(position->field); 235 fp.setField(position->field);
229 236
230 ((DateFormat*)format)->format(dateToFormat, res, fp); 237 ((DateFormat*)format)->format(dateToFormat, res, fp);
231 238
232 if(position != 0) { 239 if(position != 0) {
233 position->beginIndex = fp.getBeginIndex(); 240 position->beginIndex = fp.getBeginIndex();
234 position->endIndex = fp.getEndIndex(); 241 position->endIndex = fp.getEndIndex();
235 } 242 }
236 243
237 return res.extract(result, resultLength, *status); 244 return res.extract(result, resultLength, *status);
238 } 245 }
239 246
247 U_CAPI int32_t U_EXPORT2
248 udat_formatCalendar(const UDateFormat* format,
249 UCalendar* calendar,
250 UChar* result,
251 int32_t resultLength,
252 UFieldPosition* position,
253 UErrorCode* status)
254 {
255 if(U_FAILURE(*status)) {
256 return -1;
257 }
258 if (result == NULL ? resultLength != 0 : resultLength < 0) {
259 *status = U_ILLEGAL_ARGUMENT_ERROR;
260 return -1;
261 }
262
263 UnicodeString res;
264 if (result != NULL) {
265 // NULL destination for pure preflighting: empty dummy string
266 // otherwise, alias the destination buffer
267 res.setTo(result, 0, resultLength);
268 }
269
270 FieldPosition fp;
271
272 if(position != 0)
273 fp.setField(position->field);
274
275 ((DateFormat*)format)->format(*(Calendar*)calendar, res, fp);
276
277 if(position != 0) {
278 position->beginIndex = fp.getBeginIndex();
279 position->endIndex = fp.getEndIndex();
280 }
281
282 return res.extract(result, resultLength, *status);
283 }
284
285 U_CAPI int32_t U_EXPORT2
286 udat_formatForFields( const UDateFormat* format,
287 UDate dateToFormat,
288 UChar* result,
289 int32_t resultLength,
290 UFieldPositionIterator* fpositer,
291 UErrorCode* status)
292 {
293 if(U_FAILURE(*status)) {
294 return -1;
295 }
296 if (result == NULL ? resultLength != 0 : resultLength < 0) {
297 *status = U_ILLEGAL_ARGUMENT_ERROR;
298 return -1;
299 }
300
301 UnicodeString res;
302 if (result != NULL) {
303 // NULL destination for pure preflighting: empty dummy string
304 // otherwise, alias the destination buffer
305 res.setTo(result, 0, resultLength);
306 }
307
308 ((DateFormat*)format)->format(dateToFormat, res, (FieldPositionIterator*)fpo siter, *status);
309
310 return res.extract(result, resultLength, *status);
311 }
312
313 U_CAPI int32_t U_EXPORT2
314 udat_formatCalendarForFields(const UDateFormat* format,
315 UCalendar* calendar,
316 UChar* result,
317 int32_t resultLength,
318 UFieldPositionIterator* fpositer,
319 UErrorCode* status)
320 {
321 if(U_FAILURE(*status)) {
322 return -1;
323 }
324 if (result == NULL ? resultLength != 0 : resultLength < 0) {
325 *status = U_ILLEGAL_ARGUMENT_ERROR;
326 return -1;
327 }
328
329 UnicodeString res;
330 if (result != NULL) {
331 // NULL destination for pure preflighting: empty dummy string
332 // otherwise, alias the destination buffer
333 res.setTo(result, 0, resultLength);
334 }
335
336 ((DateFormat*)format)->format(*(Calendar*)calendar, res, (FieldPositionItera tor*)fpositer, *status);
337
338 return res.extract(result, resultLength, *status);
339 }
340
240 U_CAPI UDate U_EXPORT2 341 U_CAPI UDate U_EXPORT2
241 udat_parse( const UDateFormat* format, 342 udat_parse( const UDateFormat* format,
242 const UChar* text, 343 const UChar* text,
243 int32_t textLength, 344 int32_t textLength,
244 int32_t *parsePos, 345 int32_t *parsePos,
245 UErrorCode *status) 346 UErrorCode *status)
246 { 347 {
247 if(U_FAILURE(*status)) return (UDate)0; 348 if(U_FAILURE(*status)) return (UDate)0;
248 349
249 const UnicodeString src((UBool)(textLength == -1), text, textLength); 350 const UnicodeString src((UBool)(textLength == -1), text, textLength);
(...skipping 24 matching lines...) Expand all
274 UCalendar* calendar, 375 UCalendar* calendar,
275 const UChar* text, 376 const UChar* text,
276 int32_t textLength, 377 int32_t textLength,
277 int32_t *parsePos, 378 int32_t *parsePos,
278 UErrorCode *status) 379 UErrorCode *status)
279 { 380 {
280 if(U_FAILURE(*status)) return; 381 if(U_FAILURE(*status)) return;
281 382
282 const UnicodeString src((UBool)(textLength == -1), text, textLength); 383 const UnicodeString src((UBool)(textLength == -1), text, textLength);
283 ParsePosition pp; 384 ParsePosition pp;
385 int32_t stackParsePos = 0;
284 386
285 if(parsePos != 0) 387 if(parsePos == NULL) {
286 pp.setIndex(*parsePos); 388 parsePos = &stackParsePos;
389 }
390
391 pp.setIndex(*parsePos);
287 392
288 ((DateFormat*)format)->parse(src, *(Calendar*)calendar, pp); 393 ((DateFormat*)format)->parse(src, *(Calendar*)calendar, pp);
289 394
290 if(parsePos != 0) { 395 if(pp.getErrorIndex() == -1)
291 if(pp.getErrorIndex() == -1) 396 *parsePos = pp.getIndex();
292 *parsePos = pp.getIndex(); 397 else {
293 else { 398 *parsePos = pp.getErrorIndex();
294 *parsePos = pp.getErrorIndex(); 399 *status = U_PARSE_ERROR;
295 *status = U_PARSE_ERROR;
296 }
297 } 400 }
298 } 401 }
299 402
300 U_CAPI UBool U_EXPORT2 403 U_CAPI UBool U_EXPORT2
301 udat_isLenient(const UDateFormat* fmt) 404 udat_isLenient(const UDateFormat* fmt)
302 { 405 {
303 return ((DateFormat*)fmt)->isLenient(); 406 return ((DateFormat*)fmt)->isLenient();
304 } 407 }
305 408
306 U_CAPI void U_EXPORT2 409 U_CAPI void U_EXPORT2
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 ((SimpleDateFormat*)fmt)->set2DigitYearStart(d, *status); 521 ((SimpleDateFormat*)fmt)->set2DigitYearStart(d, *status);
419 } 522 }
420 523
421 U_CAPI int32_t U_EXPORT2 524 U_CAPI int32_t U_EXPORT2
422 udat_toPattern( const UDateFormat *fmt, 525 udat_toPattern( const UDateFormat *fmt,
423 UBool localized, 526 UBool localized,
424 UChar *result, 527 UChar *result,
425 int32_t resultLength, 528 int32_t resultLength,
426 UErrorCode *status) 529 UErrorCode *status)
427 { 530 {
428 if(U_FAILURE(*status)) return -1; 531 if(U_FAILURE(*status)) {
532 return -1;
533 }
534 if (result == NULL ? resultLength != 0 : resultLength < 0) {
535 *status = U_ILLEGAL_ARGUMENT_ERROR;
536 return -1;
537 }
429 538
430 UnicodeString res; 539 UnicodeString res;
431 if(!(result==NULL && resultLength==0)) { 540 if (result != NULL) {
432 // NULL destination for pure preflighting: empty dummy string 541 // NULL destination for pure preflighting: empty dummy string
433 // otherwise, alias the destination buffer 542 // otherwise, alias the destination buffer
434 res.setTo(result, 0, resultLength); 543 res.setTo(result, 0, resultLength);
435 } 544 }
436 545
437 const DateFormat *df=reinterpret_cast<const DateFormat *>(fmt); 546 const DateFormat *df=reinterpret_cast<const DateFormat *>(fmt);
438 const SimpleDateFormat *sdtfmt=dynamic_cast<const SimpleDateFormat *>(df); 547 const SimpleDateFormat *sdtfmt=dynamic_cast<const SimpleDateFormat *>(df);
439 const RelativeDateFormat *reldtfmt; 548 const RelativeDateFormat *reldtfmt;
440 if (sdtfmt!=NULL) { 549 if (sdtfmt!=NULL) {
441 if(localized) 550 if(localized)
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 } 1246 }
1138 1247
1139 1248
1140 U_CAPI int32_t U_EXPORT2 1249 U_CAPI int32_t U_EXPORT2
1141 udat_toPatternRelativeDate(const UDateFormat *fmt, 1250 udat_toPatternRelativeDate(const UDateFormat *fmt,
1142 UChar *result, 1251 UChar *result,
1143 int32_t resultLength, 1252 int32_t resultLength,
1144 UErrorCode *status) 1253 UErrorCode *status)
1145 { 1254 {
1146 verifyIsRelativeDateFormat(fmt, status); 1255 verifyIsRelativeDateFormat(fmt, status);
1147 if(U_FAILURE(*status)) return -1; 1256 if(U_FAILURE(*status)) {
1257 return -1;
1258 }
1259 if (result == NULL ? resultLength != 0 : resultLength < 0) {
1260 *status = U_ILLEGAL_ARGUMENT_ERROR;
1261 return -1;
1262 }
1148 1263
1149 UnicodeString datePattern; 1264 UnicodeString datePattern;
1150 if(!(result==NULL && resultLength==0)) { 1265 if (result != NULL) {
1151 // NULL destination for pure preflighting: empty dummy string 1266 // NULL destination for pure preflighting: empty dummy string
1152 // otherwise, alias the destination buffer 1267 // otherwise, alias the destination buffer
1153 datePattern.setTo(result, 0, resultLength); 1268 datePattern.setTo(result, 0, resultLength);
1154 } 1269 }
1155 ((RelativeDateFormat*)fmt)->toPatternDate(datePattern, *status); 1270 ((RelativeDateFormat*)fmt)->toPatternDate(datePattern, *status);
1156 return datePattern.extract(result, resultLength, *status); 1271 return datePattern.extract(result, resultLength, *status);
1157 } 1272 }
1158 1273
1159 U_CAPI int32_t U_EXPORT2 1274 U_CAPI int32_t U_EXPORT2
1160 udat_toPatternRelativeTime(const UDateFormat *fmt, 1275 udat_toPatternRelativeTime(const UDateFormat *fmt,
1161 UChar *result, 1276 UChar *result,
1162 int32_t resultLength, 1277 int32_t resultLength,
1163 UErrorCode *status) 1278 UErrorCode *status)
1164 { 1279 {
1165 verifyIsRelativeDateFormat(fmt, status); 1280 verifyIsRelativeDateFormat(fmt, status);
1166 if(U_FAILURE(*status)) return -1; 1281 if(U_FAILURE(*status)) {
1282 return -1;
1283 }
1284 if (result == NULL ? resultLength != 0 : resultLength < 0) {
1285 *status = U_ILLEGAL_ARGUMENT_ERROR;
1286 return -1;
1287 }
1167 1288
1168 UnicodeString timePattern; 1289 UnicodeString timePattern;
1169 if(!(result==NULL && resultLength==0)) { 1290 if (result != NULL) {
1170 // NULL destination for pure preflighting: empty dummy string 1291 // NULL destination for pure preflighting: empty dummy string
1171 // otherwise, alias the destination buffer 1292 // otherwise, alias the destination buffer
1172 timePattern.setTo(result, 0, resultLength); 1293 timePattern.setTo(result, 0, resultLength);
1173 } 1294 }
1174 ((RelativeDateFormat*)fmt)->toPatternTime(timePattern, *status); 1295 ((RelativeDateFormat*)fmt)->toPatternTime(timePattern, *status);
1175 return timePattern.extract(result, resultLength, *status); 1296 return timePattern.extract(result, resultLength, *status);
1176 } 1297 }
1177 1298
1178 U_CAPI void U_EXPORT2 1299 U_CAPI void U_EXPORT2
1179 udat_applyPatternRelative(UDateFormat *format, 1300 udat_applyPatternRelative(UDateFormat *format,
1180 const UChar *datePattern, 1301 const UChar *datePattern,
1181 int32_t datePatternLength, 1302 int32_t datePatternLength,
1182 const UChar *timePattern, 1303 const UChar *timePattern,
1183 int32_t timePatternLength, 1304 int32_t timePatternLength,
1184 UErrorCode *status) 1305 UErrorCode *status)
1185 { 1306 {
1186 verifyIsRelativeDateFormat(format, status); 1307 verifyIsRelativeDateFormat(format, status);
1187 if(U_FAILURE(*status)) return; 1308 if(U_FAILURE(*status)) return;
1188 const UnicodeString datePat((UBool)(datePatternLength == -1), datePattern, d atePatternLength); 1309 const UnicodeString datePat((UBool)(datePatternLength == -1), datePattern, d atePatternLength);
1189 const UnicodeString timePat((UBool)(timePatternLength == -1), timePattern, t imePatternLength); 1310 const UnicodeString timePat((UBool)(timePatternLength == -1), timePattern, t imePatternLength);
1190 ((RelativeDateFormat*)format)->applyPatterns(datePat, timePat, *status); 1311 ((RelativeDateFormat*)format)->applyPatterns(datePat, timePat, *status);
1191 } 1312 }
1192 1313
1193 #endif /* #if !UCONFIG_NO_FORMATTING */ 1314 #endif /* #if !UCONFIG_NO_FORMATTING */
OLDNEW
« no previous file with comments | « source/i18n/ucurr.cpp ('k') | source/i18n/udatpg.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698