OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * Copyright (C) 1996-2010, International Business Machines | 3 * Copyright (C) 1996-2010, 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 |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 U_NAMESPACE_USE | 27 U_NAMESPACE_USE |
28 | 28 |
29 /** | 29 /** |
30 * Verify that fmt is a SimpleDateFormat. Invalid error if not. | 30 * Verify that fmt is a SimpleDateFormat. Invalid error if not. |
31 * @param fmt the UDateFormat, definitely a DateFormat, maybe something else | 31 * @param fmt the UDateFormat, definitely a DateFormat, maybe something else |
32 * @param status error code, will be set to failure if there is a familure or th
e fmt is NULL. | 32 * @param status error code, will be set to failure if there is a familure or th
e fmt is NULL. |
33 */ | 33 */ |
34 static void verifyIsSimpleDateFormat(const UDateFormat* fmt, UErrorCode *status)
{ | 34 static void verifyIsSimpleDateFormat(const UDateFormat* fmt, UErrorCode *status)
{ |
35 if(U_SUCCESS(*status) && | 35 if(U_SUCCESS(*status) && |
36 dynamic_cast<const SimpleDateFormat*>(reinterpret_cast<const DateFormat*>
(fmt))==NULL) { | 36 CR_DYNAMIC_CAST<const SimpleDateFormat*>(reinterpret_cast<const DateForma
t*>(fmt))==NULL) { |
37 *status = U_ILLEGAL_ARGUMENT_ERROR; | 37 *status = U_ILLEGAL_ARGUMENT_ERROR; |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 // This mirrors the correspondence between the | 41 // This mirrors the correspondence between the |
42 // SimpleDateFormat::fgPatternIndexToDateFormatField and | 42 // SimpleDateFormat::fgPatternIndexToDateFormatField and |
43 // SimpleDateFormat::fgPatternIndexToCalendarField arrays. | 43 // SimpleDateFormat::fgPatternIndexToCalendarField arrays. |
44 static UCalendarDateFields gDateFieldMapping[] = { | 44 static UCalendarDateFields gDateFieldMapping[] = { |
45 UCAL_ERA, // UDAT_ERA_FIELD = 0 | 45 UCAL_ERA, // UDAT_ERA_FIELD = 0 |
46 UCAL_YEAR, // UDAT_YEAR_FIELD = 1 | 46 UCAL_YEAR, // UDAT_YEAR_FIELD = 1 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 if(U_FAILURE(*status)) return -1; | 331 if(U_FAILURE(*status)) return -1; |
332 | 332 |
333 UnicodeString res; | 333 UnicodeString res; |
334 if(!(result==NULL && resultLength==0)) { | 334 if(!(result==NULL && resultLength==0)) { |
335 // NULL destination for pure preflighting: empty dummy string | 335 // NULL destination for pure preflighting: empty dummy string |
336 // otherwise, alias the destination buffer | 336 // otherwise, alias the destination buffer |
337 res.setTo(result, 0, resultLength); | 337 res.setTo(result, 0, resultLength); |
338 } | 338 } |
339 | 339 |
340 const DateFormat *df=reinterpret_cast<const DateFormat *>(fmt); | 340 const DateFormat *df=reinterpret_cast<const DateFormat *>(fmt); |
341 const SimpleDateFormat *sdtfmt=dynamic_cast<const SimpleDateFormat *>(df); | 341 const SimpleDateFormat *sdtfmt=CR_DYNAMIC_CAST<const SimpleDateFormat *>(df)
; |
342 const RelativeDateFormat *reldtfmt; | 342 const RelativeDateFormat *reldtfmt; |
343 if (sdtfmt!=NULL) { | 343 if (sdtfmt!=NULL) { |
344 if(localized) | 344 if(localized) |
345 sdtfmt->toLocalizedPattern(res, *status); | 345 sdtfmt->toLocalizedPattern(res, *status); |
346 else | 346 else |
347 sdtfmt->toPattern(res); | 347 sdtfmt->toPattern(res); |
348 } else if (!localized && (reldtfmt=dynamic_cast<const RelativeDateFormat *>(
df))!=NULL) { | 348 } else if (!localized && (reldtfmt=CR_DYNAMIC_CAST<const RelativeDateFormat
*>(df))!=NULL) { |
349 reldtfmt->toPattern(res, *status); | 349 reldtfmt->toPattern(res, *status); |
350 } else { | 350 } else { |
351 *status = U_ILLEGAL_ARGUMENT_ERROR; | 351 *status = U_ILLEGAL_ARGUMENT_ERROR; |
352 return -1; | 352 return -1; |
353 } | 353 } |
354 | 354 |
355 return res.extract(result, resultLength, *status); | 355 return res.extract(result, resultLength, *status); |
356 } | 356 } |
357 | 357 |
358 // TODO: should this take an UErrorCode? | 358 // TODO: should this take an UErrorCode? |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 return ((Format*)fmt)->getLocaleID(type, *status); | 893 return ((Format*)fmt)->getLocaleID(type, *status); |
894 } | 894 } |
895 | 895 |
896 /** | 896 /** |
897 * Verify that fmt is a RelativeDateFormat. Invalid error if not. | 897 * Verify that fmt is a RelativeDateFormat. Invalid error if not. |
898 * @param fmt the UDateFormat, definitely a DateFormat, maybe something else | 898 * @param fmt the UDateFormat, definitely a DateFormat, maybe something else |
899 * @param status error code, will be set to failure if there is a familure or th
e fmt is NULL. | 899 * @param status error code, will be set to failure if there is a familure or th
e fmt is NULL. |
900 */ | 900 */ |
901 static void verifyIsRelativeDateFormat(const UDateFormat* fmt, UErrorCode *statu
s) { | 901 static void verifyIsRelativeDateFormat(const UDateFormat* fmt, UErrorCode *statu
s) { |
902 if(U_SUCCESS(*status) && | 902 if(U_SUCCESS(*status) && |
903 dynamic_cast<const RelativeDateFormat*>(reinterpret_cast<const DateFormat
*>(fmt))==NULL) { | 903 CR_DYNAMIC_CAST<const RelativeDateFormat*>(reinterpret_cast<const DateFor
mat*>(fmt))==NULL) { |
904 *status = U_ILLEGAL_ARGUMENT_ERROR; | 904 *status = U_ILLEGAL_ARGUMENT_ERROR; |
905 } | 905 } |
906 } | 906 } |
907 | 907 |
908 | 908 |
909 U_CAPI int32_t U_EXPORT2 | 909 U_CAPI int32_t U_EXPORT2 |
910 udat_toPatternRelativeDate(const UDateFormat *fmt, | 910 udat_toPatternRelativeDate(const UDateFormat *fmt, |
911 UChar *result, | 911 UChar *result, |
912 int32_t resultLength, | 912 int32_t resultLength, |
913 UErrorCode *status) | 913 UErrorCode *status) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 UErrorCode *status) | 953 UErrorCode *status) |
954 { | 954 { |
955 verifyIsRelativeDateFormat(format, status); | 955 verifyIsRelativeDateFormat(format, status); |
956 if(U_FAILURE(*status)) return; | 956 if(U_FAILURE(*status)) return; |
957 const UnicodeString datePat((UBool)(datePatternLength == -1), datePattern, d
atePatternLength); | 957 const UnicodeString datePat((UBool)(datePatternLength == -1), datePattern, d
atePatternLength); |
958 const UnicodeString timePat((UBool)(timePatternLength == -1), timePattern, t
imePatternLength); | 958 const UnicodeString timePat((UBool)(timePatternLength == -1), timePattern, t
imePatternLength); |
959 ((RelativeDateFormat*)format)->applyPatterns(datePat, timePat, *status); | 959 ((RelativeDateFormat*)format)->applyPatterns(datePat, timePat, *status); |
960 } | 960 } |
961 | 961 |
962 #endif /* #if !UCONFIG_NO_FORMATTING */ | 962 #endif /* #if !UCONFIG_NO_FORMATTING */ |
OLD | NEW |