X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/3d1f044b704633e2e541231cd17ae9ecf9ad5c7a..340931cb2e044a2141d11567dd0f782524e32994:/icuSources/i18n/udat.cpp diff --git a/icuSources/i18n/udat.cpp b/icuSources/i18n/udat.cpp index 28c22c2d..f6a04b05 100644 --- a/icuSources/i18n/udat.cpp +++ b/icuSources/i18n/udat.cpp @@ -83,13 +83,24 @@ static UCalendarDateFields gDateFieldMapping[] = { UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_ISO_FIELD = 32 (also UCAL_DST_OFFSET) UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_ISO_LOCAL_FIELD = 33 (also UCAL_DST_OFFSET) UCAL_EXTENDED_YEAR, // UDAT_RELATED_YEAR_FIELD = 34 (not an exact match) - UCAL_FIELD_COUNT, // UDAT_FIELD_COUNT = 35 + UCAL_FIELD_COUNT, // UDAT_AM_PM_MIDNIGHT_NOON_FIELD=35 (no match) + UCAL_FIELD_COUNT, // UDAT_FLEXIBLE_DAY_PERIOD_FIELD=36 (no match) + UCAL_FIELD_COUNT, // UDAT_TIME_SEPARATOR_FIELD = 37 (no match) + // UDAT_FIELD_COUNT = 38 as of ICU 66 // UCAL_IS_LEAP_MONTH is not the target of a mapping }; U_CAPI UCalendarDateFields U_EXPORT2 udat_toCalendarDateField(UDateFormatField field) { - return gDateFieldMapping[field]; + return (field >= UDAT_ERA_FIELD && field < UDAT_FIELD_COUNT)? gDateFieldMapping[field]: UCAL_FIELD_COUNT; +} + +// for Apple +U_CAPI UDateFormatField U_EXPORT2 +udat_patternCharToDateFormatField(UChar patternChar) { + const UChar* patternUChars = (UChar*)DateFormatSymbols::getPatternUChars(); + UChar* patternOffset = u_strchr(patternUChars, patternChar); + return (patternOffset)? (UDateFormatField)(patternOffset-patternUChars): UDAT_FIELD_COUNT; } /* For now- one opener. */ @@ -168,9 +179,13 @@ udat_open(UDateFormatStyle timeStyle, } } - if(fmt == 0) { + if(fmt == nullptr) { *status = U_MEMORY_ALLOCATION_ERROR; - return 0; + return nullptr; + } + if (U_FAILURE(*status)) { + delete fmt; + return nullptr; } if(tzID != 0) {