LCOV - code coverage report
Current view: top level - intl/icu/source/i18n - udat.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 540 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 65 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // © 2016 and later: Unicode, Inc. and others.
       2             : // License & terms of use: http://www.unicode.org/copyright.html
       3             : /*
       4             : *******************************************************************************
       5             : *   Copyright (C) 1996-2015, International Business Machines
       6             : *   Corporation and others.  All Rights Reserved.
       7             : *******************************************************************************
       8             : */
       9             : 
      10             : #include "unicode/utypes.h"
      11             : 
      12             : #if !UCONFIG_NO_FORMATTING
      13             : 
      14             : #include "unicode/udat.h"
      15             : 
      16             : #include "unicode/uloc.h"
      17             : #include "unicode/datefmt.h"
      18             : #include "unicode/timezone.h"
      19             : #include "unicode/smpdtfmt.h"
      20             : #include "unicode/fieldpos.h"
      21             : #include "unicode/parsepos.h"
      22             : #include "unicode/calendar.h"
      23             : #include "unicode/numfmt.h"
      24             : #include "unicode/dtfmtsym.h"
      25             : #include "unicode/ustring.h"
      26             : #include "unicode/udisplaycontext.h"
      27             : #include "unicode/ufieldpositer.h"
      28             : #include "cpputils.h"
      29             : #include "reldtfmt.h"
      30             : #include "umutex.h"
      31             : 
      32             : U_NAMESPACE_USE
      33             : 
      34             : /**
      35             :  * Verify that fmt is a SimpleDateFormat. Invalid error if not.
      36             :  * @param fmt the UDateFormat, definitely a DateFormat, maybe something else
      37             :  * @param status error code, will be set to failure if there is a familure or the fmt is NULL.
      38             :  */
      39           0 : static void verifyIsSimpleDateFormat(const UDateFormat* fmt, UErrorCode *status) {
      40           0 :    if(U_SUCCESS(*status) &&
      41           0 :        dynamic_cast<const SimpleDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))==NULL) {
      42           0 :        *status = U_ILLEGAL_ARGUMENT_ERROR;
      43             :    }
      44           0 : }
      45             : 
      46             : // This mirrors the correspondence between the
      47             : // SimpleDateFormat::fgPatternIndexToDateFormatField and
      48             : // SimpleDateFormat::fgPatternIndexToCalendarField arrays.
      49             : static UCalendarDateFields gDateFieldMapping[] = {
      50             :     UCAL_ERA,                  // UDAT_ERA_FIELD = 0
      51             :     UCAL_YEAR,                 // UDAT_YEAR_FIELD = 1
      52             :     UCAL_MONTH,                // UDAT_MONTH_FIELD = 2
      53             :     UCAL_DATE,                 // UDAT_DATE_FIELD = 3
      54             :     UCAL_HOUR_OF_DAY,          // UDAT_HOUR_OF_DAY1_FIELD = 4
      55             :     UCAL_HOUR_OF_DAY,          // UDAT_HOUR_OF_DAY0_FIELD = 5
      56             :     UCAL_MINUTE,               // UDAT_MINUTE_FIELD = 6
      57             :     UCAL_SECOND,               // UDAT_SECOND_FIELD = 7
      58             :     UCAL_MILLISECOND,          // UDAT_FRACTIONAL_SECOND_FIELD = 8
      59             :     UCAL_DAY_OF_WEEK,          // UDAT_DAY_OF_WEEK_FIELD = 9
      60             :     UCAL_DAY_OF_YEAR,          // UDAT_DAY_OF_YEAR_FIELD = 10
      61             :     UCAL_DAY_OF_WEEK_IN_MONTH, // UDAT_DAY_OF_WEEK_IN_MONTH_FIELD = 11
      62             :     UCAL_WEEK_OF_YEAR,         // UDAT_WEEK_OF_YEAR_FIELD = 12
      63             :     UCAL_WEEK_OF_MONTH,        // UDAT_WEEK_OF_MONTH_FIELD = 13
      64             :     UCAL_AM_PM,                // UDAT_AM_PM_FIELD = 14
      65             :     UCAL_HOUR,                 // UDAT_HOUR1_FIELD = 15
      66             :     UCAL_HOUR,                 // UDAT_HOUR0_FIELD = 16
      67             :     UCAL_ZONE_OFFSET,          // UDAT_TIMEZONE_FIELD = 17
      68             :     UCAL_YEAR_WOY,             // UDAT_YEAR_WOY_FIELD = 18
      69             :     UCAL_DOW_LOCAL,            // UDAT_DOW_LOCAL_FIELD = 19
      70             :     UCAL_EXTENDED_YEAR,        // UDAT_EXTENDED_YEAR_FIELD = 20
      71             :     UCAL_JULIAN_DAY,           // UDAT_JULIAN_DAY_FIELD = 21
      72             :     UCAL_MILLISECONDS_IN_DAY,  // UDAT_MILLISECONDS_IN_DAY_FIELD = 22
      73             :     UCAL_ZONE_OFFSET,          // UDAT_TIMEZONE_RFC_FIELD = 23 (also UCAL_DST_OFFSET)
      74             :     UCAL_ZONE_OFFSET,          // UDAT_TIMEZONE_GENERIC_FIELD = 24 (also UCAL_DST_OFFSET)
      75             :     UCAL_DOW_LOCAL,            // UDAT_STANDALONE_DAY_FIELD = 25
      76             :     UCAL_MONTH,                // UDAT_STANDALONE_MONTH_FIELD = 26
      77             :     UCAL_MONTH,                // UDAT_QUARTER_FIELD = 27
      78             :     UCAL_MONTH,                // UDAT_STANDALONE_QUARTER_FIELD = 28
      79             :     UCAL_ZONE_OFFSET,          // UDAT_TIMEZONE_SPECIAL_FIELD = 29 (also UCAL_DST_OFFSET)
      80             :     UCAL_YEAR,                 // UDAT_YEAR_NAME_FIELD = 30
      81             :     UCAL_ZONE_OFFSET,          // UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD = 31 (also UCAL_DST_OFFSET)
      82             :     UCAL_ZONE_OFFSET,          // UDAT_TIMEZONE_ISO_FIELD = 32 (also UCAL_DST_OFFSET)
      83             :     UCAL_ZONE_OFFSET,          // UDAT_TIMEZONE_ISO_LOCAL_FIELD = 33 (also UCAL_DST_OFFSET)
      84             :     UCAL_EXTENDED_YEAR,        // UDAT_RELATED_YEAR_FIELD = 34 (not an exact match)
      85             :     UCAL_FIELD_COUNT,          // UDAT_FIELD_COUNT = 35
      86             :     // UCAL_IS_LEAP_MONTH is not the target of a mapping
      87             : };
      88             : 
      89             : U_CAPI UCalendarDateFields U_EXPORT2
      90           0 : udat_toCalendarDateField(UDateFormatField field) {
      91           0 :   return gDateFieldMapping[field];
      92             : }
      93             : 
      94             : /* For now- one opener. */
      95             : static UDateFormatOpener gOpener = NULL;
      96             : 
      97             : U_INTERNAL void U_EXPORT2
      98           0 : udat_registerOpener(UDateFormatOpener opener, UErrorCode *status)
      99             : {
     100           0 :   if(U_FAILURE(*status)) return;
     101           0 :   umtx_lock(NULL);
     102           0 :   if(gOpener==NULL) {
     103           0 :     gOpener = opener;
     104             :   } else {
     105           0 :     *status = U_ILLEGAL_ARGUMENT_ERROR;
     106             :   }
     107           0 :   umtx_unlock(NULL);
     108             : }
     109             : 
     110             : U_INTERNAL UDateFormatOpener U_EXPORT2
     111           0 : udat_unregisterOpener(UDateFormatOpener opener, UErrorCode *status)
     112             : {
     113           0 :   if(U_FAILURE(*status)) return NULL;
     114           0 :   UDateFormatOpener oldOpener = NULL;
     115           0 :   umtx_lock(NULL);
     116           0 :   if(gOpener==NULL || gOpener!=opener) {
     117           0 :     *status = U_ILLEGAL_ARGUMENT_ERROR;
     118             :   } else {
     119           0 :     oldOpener=gOpener;
     120           0 :     gOpener=NULL;
     121             :   }
     122           0 :   umtx_unlock(NULL);
     123           0 :   return oldOpener;
     124             : }
     125             : 
     126             : 
     127             : 
     128             : U_CAPI UDateFormat* U_EXPORT2
     129           0 : udat_open(UDateFormatStyle  timeStyle,
     130             :           UDateFormatStyle  dateStyle,
     131             :           const char        *locale,
     132             :           const UChar       *tzID,
     133             :           int32_t           tzIDLength,
     134             :           const UChar       *pattern,
     135             :           int32_t           patternLength,
     136             :           UErrorCode        *status)
     137             : {
     138             :     DateFormat *fmt;
     139           0 :     if(U_FAILURE(*status)) {
     140           0 :         return 0;
     141             :     }
     142           0 :     if(gOpener!=NULL) { // if it's registered
     143           0 :       fmt = (DateFormat*) (*gOpener)(timeStyle,dateStyle,locale,tzID,tzIDLength,pattern,patternLength,status);
     144           0 :       if(fmt!=NULL) {
     145           0 :         return (UDateFormat*)fmt;
     146             :       } // else fall through.
     147             :     }
     148           0 :     if(timeStyle != UDAT_PATTERN) {
     149           0 :         if(locale == 0) {
     150           0 :             fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
     151           0 :                 (DateFormat::EStyle)timeStyle);
     152             :         }
     153             :         else {
     154             :             fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
     155             :                 (DateFormat::EStyle)timeStyle,
     156           0 :                 Locale(locale));
     157             :         }
     158             :     }
     159             :     else {
     160           0 :         UnicodeString pat((UBool)(patternLength == -1), pattern, patternLength);
     161             : 
     162           0 :         if(locale == 0) {
     163           0 :             fmt = new SimpleDateFormat(pat, *status);
     164             :         }
     165             :         else {
     166           0 :             fmt = new SimpleDateFormat(pat, Locale(locale), *status);
     167             :         }
     168             :     }
     169             : 
     170           0 :     if(fmt == 0) {
     171           0 :         *status = U_MEMORY_ALLOCATION_ERROR;
     172           0 :         return 0;
     173             :     }
     174             : 
     175           0 :     if(tzID != 0) {
     176           0 :         TimeZone *zone = TimeZone::createTimeZone(UnicodeString((UBool)(tzIDLength == -1), tzID, tzIDLength));
     177           0 :         if(zone == 0) {
     178           0 :             *status = U_MEMORY_ALLOCATION_ERROR;
     179           0 :             delete fmt;
     180           0 :             return 0;
     181             :         }
     182           0 :         fmt->adoptTimeZone(zone);
     183             :     }
     184             : 
     185           0 :     return (UDateFormat*)fmt;
     186             : }
     187             : 
     188             : 
     189             : U_CAPI void U_EXPORT2
     190           0 : udat_close(UDateFormat* format)
     191             : {
     192           0 :     delete (DateFormat*)format;
     193           0 : }
     194             : 
     195             : U_CAPI UDateFormat* U_EXPORT2
     196           0 : udat_clone(const UDateFormat *fmt,
     197             :        UErrorCode *status)
     198             : {
     199           0 :     if(U_FAILURE(*status)) return 0;
     200             : 
     201           0 :     Format *res = ((DateFormat*)fmt)->clone();
     202             : 
     203           0 :     if(res == 0) {
     204           0 :         *status = U_MEMORY_ALLOCATION_ERROR;
     205           0 :         return 0;
     206             :     }
     207             : 
     208           0 :     return (UDateFormat*) res;
     209             : }
     210             : 
     211             : U_CAPI int32_t U_EXPORT2
     212           0 : udat_format(    const    UDateFormat*    format,
     213             :         UDate           dateToFormat,
     214             :         UChar*          result,
     215             :         int32_t         resultLength,
     216             :         UFieldPosition* position,
     217             :         UErrorCode*     status)
     218             : {
     219           0 :     if(U_FAILURE(*status)) {
     220           0 :         return -1;
     221             :     }
     222           0 :     if (result == NULL ? resultLength != 0 : resultLength < 0) {
     223           0 :         *status = U_ILLEGAL_ARGUMENT_ERROR;
     224           0 :         return -1;
     225             :     }
     226             : 
     227           0 :     UnicodeString res;
     228           0 :     if (result != NULL) {
     229             :         // NULL destination for pure preflighting: empty dummy string
     230             :         // otherwise, alias the destination buffer
     231           0 :         res.setTo(result, 0, resultLength);
     232             :     }
     233             : 
     234           0 :     FieldPosition fp;
     235             : 
     236           0 :     if(position != 0)
     237           0 :         fp.setField(position->field);
     238             : 
     239           0 :     ((DateFormat*)format)->format(dateToFormat, res, fp);
     240             : 
     241           0 :     if(position != 0) {
     242           0 :         position->beginIndex = fp.getBeginIndex();
     243           0 :         position->endIndex = fp.getEndIndex();
     244             :     }
     245             : 
     246           0 :     return res.extract(result, resultLength, *status);
     247             : }
     248             : 
     249             : U_CAPI int32_t U_EXPORT2
     250           0 : udat_formatCalendar(const UDateFormat*  format,
     251             :         UCalendar*      calendar,
     252             :         UChar*          result,
     253             :         int32_t         resultLength,
     254             :         UFieldPosition* position,
     255             :         UErrorCode*     status)
     256             : {
     257           0 :     if(U_FAILURE(*status)) {
     258           0 :         return -1;
     259             :     }
     260           0 :     if (result == NULL ? resultLength != 0 : resultLength < 0) {
     261           0 :         *status = U_ILLEGAL_ARGUMENT_ERROR;
     262           0 :         return -1;
     263             :     }
     264             : 
     265           0 :     UnicodeString res;
     266           0 :     if (result != NULL) {
     267             :         // NULL destination for pure preflighting: empty dummy string
     268             :         // otherwise, alias the destination buffer
     269           0 :         res.setTo(result, 0, resultLength);
     270             :     }
     271             : 
     272           0 :     FieldPosition fp;
     273             : 
     274           0 :     if(position != 0)
     275           0 :         fp.setField(position->field);
     276             : 
     277           0 :     ((DateFormat*)format)->format(*(Calendar*)calendar, res, fp);
     278             : 
     279           0 :     if(position != 0) {
     280           0 :         position->beginIndex = fp.getBeginIndex();
     281           0 :         position->endIndex = fp.getEndIndex();
     282             :     }
     283             : 
     284           0 :     return res.extract(result, resultLength, *status);
     285             : }
     286             : 
     287             : U_CAPI int32_t U_EXPORT2
     288           0 : udat_formatForFields(    const    UDateFormat*    format,
     289             :         UDate           dateToFormat,
     290             :         UChar*          result,
     291             :         int32_t         resultLength,
     292             :         UFieldPositionIterator* fpositer,
     293             :         UErrorCode*     status)
     294             : {
     295           0 :     if(U_FAILURE(*status)) {
     296           0 :         return -1;
     297             :     }
     298           0 :     if (result == NULL ? resultLength != 0 : resultLength < 0) {
     299           0 :         *status = U_ILLEGAL_ARGUMENT_ERROR;
     300           0 :         return -1;
     301             :     }
     302             : 
     303           0 :     UnicodeString res;
     304           0 :     if (result != NULL) {
     305             :         // NULL destination for pure preflighting: empty dummy string
     306             :         // otherwise, alias the destination buffer
     307           0 :         res.setTo(result, 0, resultLength);
     308             :     }
     309             : 
     310           0 :     ((DateFormat*)format)->format(dateToFormat, res, (FieldPositionIterator*)fpositer, *status);
     311             : 
     312           0 :     return res.extract(result, resultLength, *status);
     313             : }
     314             : 
     315             : U_CAPI int32_t U_EXPORT2
     316           0 : udat_formatCalendarForFields(const UDateFormat*  format,
     317             :         UCalendar*      calendar,
     318             :         UChar*          result,
     319             :         int32_t         resultLength,
     320             :         UFieldPositionIterator* fpositer,
     321             :         UErrorCode*     status)
     322             : {
     323           0 :     if(U_FAILURE(*status)) {
     324           0 :         return -1;
     325             :     }
     326           0 :     if (result == NULL ? resultLength != 0 : resultLength < 0) {
     327           0 :         *status = U_ILLEGAL_ARGUMENT_ERROR;
     328           0 :         return -1;
     329             :     }
     330             : 
     331           0 :     UnicodeString res;
     332           0 :     if (result != NULL) {
     333             :         // NULL destination for pure preflighting: empty dummy string
     334             :         // otherwise, alias the destination buffer
     335           0 :         res.setTo(result, 0, resultLength);
     336             :     }
     337             : 
     338           0 :     ((DateFormat*)format)->format(*(Calendar*)calendar, res, (FieldPositionIterator*)fpositer, *status);
     339             : 
     340           0 :     return res.extract(result, resultLength, *status);
     341             : }
     342             : 
     343             : U_CAPI UDate U_EXPORT2
     344           0 : udat_parse(    const    UDateFormat*        format,
     345             :         const    UChar*          text,
     346             :         int32_t         textLength,
     347             :         int32_t         *parsePos,
     348             :         UErrorCode      *status)
     349             : {
     350           0 :     if(U_FAILURE(*status)) return (UDate)0;
     351             : 
     352           0 :     const UnicodeString src((UBool)(textLength == -1), text, textLength);
     353           0 :     ParsePosition pp;
     354           0 :     int32_t stackParsePos = 0;
     355             :     UDate res;
     356             : 
     357           0 :     if(parsePos == NULL) {
     358           0 :         parsePos = &stackParsePos;
     359             :     }
     360             : 
     361           0 :     pp.setIndex(*parsePos);
     362             : 
     363           0 :     res = ((DateFormat*)format)->parse(src, pp);
     364             : 
     365           0 :     if(pp.getErrorIndex() == -1)
     366           0 :         *parsePos = pp.getIndex();
     367             :     else {
     368           0 :         *parsePos = pp.getErrorIndex();
     369           0 :         *status = U_PARSE_ERROR;
     370             :     }
     371             : 
     372           0 :     return res;
     373             : }
     374             : 
     375             : U_CAPI void U_EXPORT2
     376           0 : udat_parseCalendar(const    UDateFormat*    format,
     377             :                             UCalendar*      calendar,
     378             :                    const    UChar*          text,
     379             :                             int32_t         textLength,
     380             :                             int32_t         *parsePos,
     381             :                             UErrorCode      *status)
     382             : {
     383           0 :     if(U_FAILURE(*status)) return;
     384             : 
     385           0 :     const UnicodeString src((UBool)(textLength == -1), text, textLength);
     386           0 :     ParsePosition pp;
     387           0 :     int32_t stackParsePos = 0;
     388             : 
     389           0 :     if(parsePos == NULL) {
     390           0 :         parsePos = &stackParsePos;
     391             :     }
     392             : 
     393           0 :     pp.setIndex(*parsePos);
     394             : 
     395           0 :     ((DateFormat*)format)->parse(src, *(Calendar*)calendar, pp);
     396             : 
     397           0 :     if(pp.getErrorIndex() == -1)
     398           0 :         *parsePos = pp.getIndex();
     399             :     else {
     400           0 :         *parsePos = pp.getErrorIndex();
     401           0 :         *status = U_PARSE_ERROR;
     402             :     }
     403             : }
     404             : 
     405             : U_CAPI UBool U_EXPORT2
     406           0 : udat_isLenient(const UDateFormat* fmt)
     407             : {
     408           0 :     return ((DateFormat*)fmt)->isLenient();
     409             : }
     410             : 
     411             : U_CAPI void U_EXPORT2
     412           0 : udat_setLenient(    UDateFormat*    fmt,
     413             :             UBool          isLenient)
     414             : {
     415           0 :     ((DateFormat*)fmt)->setLenient(isLenient);
     416           0 : }
     417             : 
     418             : U_DRAFT UBool U_EXPORT2
     419           0 : udat_getBooleanAttribute(const UDateFormat* fmt, 
     420             :                          UDateFormatBooleanAttribute attr, 
     421             :                          UErrorCode* status)
     422             : {
     423           0 :     if(U_FAILURE(*status)) return FALSE;
     424           0 :     return ((DateFormat*)fmt)->getBooleanAttribute(attr, *status);
     425             :     //return FALSE;
     426             : }
     427             : 
     428             : U_DRAFT void U_EXPORT2
     429           0 : udat_setBooleanAttribute(UDateFormat *fmt, 
     430             :                          UDateFormatBooleanAttribute attr, 
     431             :                          UBool newValue, 
     432             :                          UErrorCode* status)
     433             : {
     434           0 :     if(U_FAILURE(*status)) return;
     435           0 :     ((DateFormat*)fmt)->setBooleanAttribute(attr, newValue, *status);
     436             : }
     437             : 
     438             : U_CAPI const UCalendar* U_EXPORT2
     439           0 : udat_getCalendar(const UDateFormat* fmt)
     440             : {
     441           0 :     return (const UCalendar*) ((DateFormat*)fmt)->getCalendar();
     442             : }
     443             : 
     444             : U_CAPI void U_EXPORT2
     445           0 : udat_setCalendar(UDateFormat*    fmt,
     446             :                  const   UCalendar*      calendarToSet)
     447             : {
     448           0 :     ((DateFormat*)fmt)->setCalendar(*((Calendar*)calendarToSet));
     449           0 : }
     450             : 
     451             : U_DRAFT const UNumberFormat* U_EXPORT2 
     452           0 : udat_getNumberFormatForField(const UDateFormat* fmt, UChar field)
     453             : {
     454           0 :     UErrorCode status = U_ZERO_ERROR;
     455           0 :     verifyIsSimpleDateFormat(fmt, &status);
     456           0 :     if (U_FAILURE(status)) return (const UNumberFormat*) ((DateFormat*)fmt)->getNumberFormat();
     457           0 :     return (const UNumberFormat*) ((SimpleDateFormat*)fmt)->getNumberFormatForField(field);
     458             : }
     459             : 
     460             : U_CAPI const UNumberFormat* U_EXPORT2
     461           0 : udat_getNumberFormat(const UDateFormat* fmt)
     462             : {
     463           0 :     return (const UNumberFormat*) ((DateFormat*)fmt)->getNumberFormat();
     464             : }
     465             : 
     466             : U_DRAFT void U_EXPORT2 
     467           0 : udat_adoptNumberFormatForFields(           UDateFormat*    fmt,
     468             :                                     const  UChar*          fields,
     469             :                                            UNumberFormat*  numberFormatToSet,
     470             :                                            UErrorCode*     status)
     471             : {
     472           0 :     verifyIsSimpleDateFormat(fmt, status);
     473           0 :     if (U_FAILURE(*status)) return;
     474             :     
     475           0 :     if (fields!=NULL) {
     476           0 :         UnicodeString overrideFields(fields);
     477           0 :         ((SimpleDateFormat*)fmt)->adoptNumberFormat(overrideFields, (NumberFormat*)numberFormatToSet, *status);
     478             :     }
     479             : }
     480             : 
     481             : U_CAPI void U_EXPORT2
     482           0 : udat_setNumberFormat(UDateFormat*    fmt,
     483             :                      const   UNumberFormat*  numberFormatToSet)
     484             : {
     485           0 :     ((DateFormat*)fmt)->setNumberFormat(*((NumberFormat*)numberFormatToSet));
     486           0 : }
     487             : 
     488             : U_DRAFT void U_EXPORT2
     489           0 : udat_adoptNumberFormat(      UDateFormat*    fmt,
     490             :                              UNumberFormat*  numberFormatToAdopt)
     491             : {
     492           0 :     ((DateFormat*)fmt)->adoptNumberFormat((NumberFormat*)numberFormatToAdopt);
     493           0 : }
     494             : 
     495             : U_CAPI const char* U_EXPORT2
     496           0 : udat_getAvailable(int32_t index)
     497             : {
     498           0 :     return uloc_getAvailable(index);
     499             : }
     500             : 
     501             : U_CAPI int32_t U_EXPORT2
     502           0 : udat_countAvailable()
     503             : {
     504           0 :     return uloc_countAvailable();
     505             : }
     506             : 
     507             : U_CAPI UDate U_EXPORT2
     508           0 : udat_get2DigitYearStart(    const   UDateFormat     *fmt,
     509             :                         UErrorCode      *status)
     510             : {
     511           0 :     verifyIsSimpleDateFormat(fmt, status);
     512           0 :     if(U_FAILURE(*status)) return (UDate)0;
     513           0 :     return ((SimpleDateFormat*)fmt)->get2DigitYearStart(*status);
     514             : }
     515             : 
     516             : U_CAPI void U_EXPORT2
     517           0 : udat_set2DigitYearStart(    UDateFormat     *fmt,
     518             :                         UDate           d,
     519             :                         UErrorCode      *status)
     520             : {
     521           0 :     verifyIsSimpleDateFormat(fmt, status);
     522           0 :     if(U_FAILURE(*status)) return;
     523           0 :     ((SimpleDateFormat*)fmt)->set2DigitYearStart(d, *status);
     524             : }
     525             : 
     526             : U_CAPI int32_t U_EXPORT2
     527           0 : udat_toPattern(    const   UDateFormat     *fmt,
     528             :         UBool          localized,
     529             :         UChar           *result,
     530             :         int32_t         resultLength,
     531             :         UErrorCode      *status)
     532             : {
     533           0 :     if(U_FAILURE(*status)) {
     534           0 :         return -1;
     535             :     }
     536           0 :     if (result == NULL ? resultLength != 0 : resultLength < 0) {
     537           0 :         *status = U_ILLEGAL_ARGUMENT_ERROR;
     538           0 :         return -1;
     539             :     }
     540             : 
     541           0 :     UnicodeString res;
     542           0 :     if (result != NULL) {
     543             :         // NULL destination for pure preflighting: empty dummy string
     544             :         // otherwise, alias the destination buffer
     545           0 :         res.setTo(result, 0, resultLength);
     546             :     }
     547             : 
     548           0 :     const DateFormat *df=reinterpret_cast<const DateFormat *>(fmt);
     549           0 :     const SimpleDateFormat *sdtfmt=dynamic_cast<const SimpleDateFormat *>(df);
     550             :     const RelativeDateFormat *reldtfmt;
     551           0 :     if (sdtfmt!=NULL) {
     552           0 :         if(localized)
     553           0 :             sdtfmt->toLocalizedPattern(res, *status);
     554             :         else
     555           0 :             sdtfmt->toPattern(res);
     556           0 :     } else if (!localized && (reldtfmt=dynamic_cast<const RelativeDateFormat *>(df))!=NULL) {
     557           0 :         reldtfmt->toPattern(res, *status);
     558             :     } else {
     559           0 :         *status = U_ILLEGAL_ARGUMENT_ERROR;
     560           0 :         return -1;
     561             :     }
     562             : 
     563           0 :     return res.extract(result, resultLength, *status);
     564             : }
     565             : 
     566             : // TODO: should this take an UErrorCode?
     567             : // A: Yes. Of course.
     568             : U_CAPI void U_EXPORT2
     569           0 : udat_applyPattern(  UDateFormat     *format,
     570             :                     UBool          localized,
     571             :                     const   UChar           *pattern,
     572             :                     int32_t         patternLength)
     573             : {
     574           0 :     const UnicodeString pat((UBool)(patternLength == -1), pattern, patternLength);
     575           0 :     UErrorCode status = U_ZERO_ERROR;
     576             : 
     577           0 :     verifyIsSimpleDateFormat(format, &status);
     578           0 :     if(U_FAILURE(status)) {
     579           0 :         return;
     580             :     }
     581             :     
     582           0 :     if(localized)
     583           0 :         ((SimpleDateFormat*)format)->applyLocalizedPattern(pat, status);
     584             :     else
     585           0 :         ((SimpleDateFormat*)format)->applyPattern(pat);
     586             : }
     587             : 
     588             : U_CAPI int32_t U_EXPORT2
     589           0 : udat_getSymbols(const   UDateFormat     *fmt,
     590             :                 UDateFormatSymbolType   type,
     591             :                 int32_t                 index,
     592             :                 UChar                   *result,
     593             :                 int32_t                 resultLength,
     594             :                 UErrorCode              *status)
     595             : {
     596             :     const DateFormatSymbols *syms;
     597             :     const SimpleDateFormat* sdtfmt;
     598             :     const RelativeDateFormat* rdtfmt;
     599           0 :     if ((sdtfmt = dynamic_cast<const SimpleDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))) != NULL) {
     600           0 :         syms = sdtfmt->getDateFormatSymbols();
     601           0 :     } else if ((rdtfmt = dynamic_cast<const RelativeDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))) != NULL) {
     602           0 :         syms = rdtfmt->getDateFormatSymbols();
     603             :     } else {
     604           0 :         return -1;
     605             :     }
     606             :     int32_t count;
     607           0 :     const UnicodeString *res = NULL;
     608             : 
     609           0 :     switch(type) {
     610             :     case UDAT_ERAS:
     611           0 :         res = syms->getEras(count);
     612           0 :         break;
     613             : 
     614             :     case UDAT_ERA_NAMES:
     615           0 :         res = syms->getEraNames(count);
     616           0 :         break;
     617             : 
     618             :     case UDAT_MONTHS:
     619           0 :         res = syms->getMonths(count);
     620           0 :         break;
     621             : 
     622             :     case UDAT_SHORT_MONTHS:
     623           0 :         res = syms->getShortMonths(count);
     624           0 :         break;
     625             : 
     626             :     case UDAT_WEEKDAYS:
     627           0 :         res = syms->getWeekdays(count);
     628           0 :         break;
     629             : 
     630             :     case UDAT_SHORT_WEEKDAYS:
     631           0 :         res = syms->getShortWeekdays(count);
     632           0 :         break;
     633             : 
     634             :     case UDAT_AM_PMS:
     635           0 :         res = syms->getAmPmStrings(count);
     636           0 :         break;
     637             : 
     638             :     case UDAT_LOCALIZED_CHARS:
     639             :         {
     640           0 :             UnicodeString res1;
     641           0 :             if(!(result==NULL && resultLength==0)) {
     642             :                 // NULL destination for pure preflighting: empty dummy string
     643             :                 // otherwise, alias the destination buffer
     644           0 :                 res1.setTo(result, 0, resultLength);
     645             :             }
     646           0 :             syms->getLocalPatternChars(res1);
     647           0 :             return res1.extract(result, resultLength, *status);
     648             :         }
     649             : 
     650             :     case UDAT_NARROW_MONTHS:
     651           0 :         res = syms->getMonths(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
     652           0 :         break;
     653             : 
     654             :     case UDAT_SHORTER_WEEKDAYS:
     655           0 :         res = syms->getWeekdays(count, DateFormatSymbols::FORMAT, DateFormatSymbols::SHORT);
     656           0 :         break;
     657             : 
     658             :     case UDAT_NARROW_WEEKDAYS:
     659           0 :         res = syms->getWeekdays(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
     660           0 :         break;
     661             : 
     662             :     case UDAT_STANDALONE_MONTHS:
     663           0 :         res = syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
     664           0 :         break;
     665             : 
     666             :     case UDAT_STANDALONE_SHORT_MONTHS:
     667           0 :         res = syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
     668           0 :         break;
     669             : 
     670             :     case UDAT_STANDALONE_NARROW_MONTHS:
     671           0 :         res = syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
     672           0 :         break;
     673             : 
     674             :     case UDAT_STANDALONE_WEEKDAYS:
     675           0 :         res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
     676           0 :         break;
     677             : 
     678             :     case UDAT_STANDALONE_SHORT_WEEKDAYS:
     679           0 :         res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
     680           0 :         break;
     681             : 
     682             :     case UDAT_STANDALONE_SHORTER_WEEKDAYS:
     683           0 :         res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::SHORT);
     684           0 :         break;
     685             : 
     686             :     case UDAT_STANDALONE_NARROW_WEEKDAYS:
     687           0 :         res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
     688           0 :         break;
     689             : 
     690             :     case UDAT_QUARTERS:
     691           0 :         res = syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
     692           0 :         break;
     693             : 
     694             :     case UDAT_SHORT_QUARTERS:
     695           0 :         res = syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
     696           0 :         break;
     697             : 
     698             :     case UDAT_STANDALONE_QUARTERS:
     699           0 :         res = syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
     700           0 :         break;
     701             : 
     702             :     case UDAT_STANDALONE_SHORT_QUARTERS:
     703           0 :         res = syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
     704           0 :         break;
     705             : 
     706             :     case UDAT_CYCLIC_YEARS_WIDE:
     707           0 :         res = syms->getYearNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
     708           0 :         break;
     709             : 
     710             :     case UDAT_CYCLIC_YEARS_ABBREVIATED:
     711           0 :         res = syms->getYearNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
     712           0 :         break;
     713             : 
     714             :     case UDAT_CYCLIC_YEARS_NARROW:
     715           0 :         res = syms->getYearNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
     716           0 :         break;
     717             : 
     718             :     case UDAT_ZODIAC_NAMES_WIDE:
     719           0 :         res = syms->getZodiacNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
     720           0 :         break;
     721             : 
     722             :     case UDAT_ZODIAC_NAMES_ABBREVIATED:
     723           0 :         res = syms->getZodiacNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
     724           0 :         break;
     725             : 
     726             :     case UDAT_ZODIAC_NAMES_NARROW:
     727           0 :         res = syms->getZodiacNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
     728           0 :         break;
     729             : 
     730             :     }
     731             : 
     732           0 :     if(index < count) {
     733           0 :         return res[index].extract(result, resultLength, *status);
     734             :     }
     735           0 :     return 0;
     736             : }
     737             : 
     738             : // TODO: also needs an errorCode.
     739             : U_CAPI int32_t U_EXPORT2
     740           0 : udat_countSymbols(    const    UDateFormat                *fmt,
     741             :             UDateFormatSymbolType    type)
     742             : {
     743             :     const DateFormatSymbols *syms;
     744             :     const SimpleDateFormat* sdtfmt;
     745             :     const RelativeDateFormat* rdtfmt;
     746           0 :     if ((sdtfmt = dynamic_cast<const SimpleDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))) != NULL) {
     747           0 :         syms = sdtfmt->getDateFormatSymbols();
     748           0 :     } else if ((rdtfmt = dynamic_cast<const RelativeDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))) != NULL) {
     749           0 :         syms = rdtfmt->getDateFormatSymbols();
     750             :     } else {
     751           0 :         return 0;
     752             :     }
     753           0 :     int32_t count = 0;
     754             : 
     755           0 :     switch(type) {
     756             :     case UDAT_ERAS:
     757           0 :         syms->getEras(count);
     758           0 :         break;
     759             : 
     760             :     case UDAT_MONTHS:
     761           0 :         syms->getMonths(count);
     762           0 :         break;
     763             : 
     764             :     case UDAT_SHORT_MONTHS:
     765           0 :         syms->getShortMonths(count);
     766           0 :         break;
     767             : 
     768             :     case UDAT_WEEKDAYS:
     769           0 :         syms->getWeekdays(count);
     770           0 :         break;
     771             : 
     772             :     case UDAT_SHORT_WEEKDAYS:
     773           0 :         syms->getShortWeekdays(count);
     774           0 :         break;
     775             : 
     776             :     case UDAT_AM_PMS:
     777           0 :         syms->getAmPmStrings(count);
     778           0 :         break;
     779             : 
     780             :     case UDAT_LOCALIZED_CHARS:
     781           0 :         count = 1;
     782           0 :         break;
     783             : 
     784             :     case UDAT_ERA_NAMES:
     785           0 :         syms->getEraNames(count);
     786           0 :         break;
     787             : 
     788             :     case UDAT_NARROW_MONTHS:
     789           0 :         syms->getMonths(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
     790           0 :         break;
     791             : 
     792             :     case UDAT_SHORTER_WEEKDAYS:
     793           0 :         syms->getWeekdays(count, DateFormatSymbols::FORMAT, DateFormatSymbols::SHORT);
     794           0 :         break;
     795             : 
     796             :     case UDAT_NARROW_WEEKDAYS:
     797           0 :         syms->getWeekdays(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
     798           0 :         break;
     799             : 
     800             :     case UDAT_STANDALONE_MONTHS:
     801           0 :         syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
     802           0 :         break;
     803             : 
     804             :     case UDAT_STANDALONE_SHORT_MONTHS:
     805           0 :         syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
     806           0 :         break;
     807             : 
     808             :     case UDAT_STANDALONE_NARROW_MONTHS:
     809           0 :         syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
     810           0 :         break;
     811             : 
     812             :     case UDAT_STANDALONE_WEEKDAYS:
     813           0 :         syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
     814           0 :         break;
     815             : 
     816             :     case UDAT_STANDALONE_SHORT_WEEKDAYS:
     817           0 :         syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
     818           0 :         break;
     819             : 
     820             :     case UDAT_STANDALONE_SHORTER_WEEKDAYS:
     821           0 :         syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::SHORT);
     822           0 :         break;
     823             : 
     824             :     case UDAT_STANDALONE_NARROW_WEEKDAYS:
     825           0 :         syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
     826           0 :         break;
     827             : 
     828             :     case UDAT_QUARTERS:
     829           0 :         syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
     830           0 :         break;
     831             : 
     832             :     case UDAT_SHORT_QUARTERS:
     833           0 :         syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
     834           0 :         break;
     835             : 
     836             :     case UDAT_STANDALONE_QUARTERS:
     837           0 :         syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
     838           0 :         break;
     839             : 
     840             :     case UDAT_STANDALONE_SHORT_QUARTERS:
     841           0 :         syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
     842           0 :         break;
     843             : 
     844             :     case UDAT_CYCLIC_YEARS_WIDE:
     845           0 :         syms->getYearNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
     846           0 :         break;
     847             : 
     848             :     case UDAT_CYCLIC_YEARS_ABBREVIATED:
     849           0 :         syms->getYearNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
     850           0 :         break;
     851             : 
     852             :     case UDAT_CYCLIC_YEARS_NARROW:
     853           0 :         syms->getYearNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
     854           0 :         break;
     855             : 
     856             :     case UDAT_ZODIAC_NAMES_WIDE:
     857           0 :         syms->getZodiacNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
     858           0 :         break;
     859             : 
     860             :     case UDAT_ZODIAC_NAMES_ABBREVIATED:
     861           0 :         syms->getZodiacNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
     862           0 :         break;
     863             : 
     864             :     case UDAT_ZODIAC_NAMES_NARROW:
     865           0 :         syms->getZodiacNames(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
     866           0 :         break;
     867             : 
     868             :     }
     869             : 
     870           0 :     return count;
     871             : }
     872             : 
     873             : U_NAMESPACE_BEGIN
     874             : 
     875             : /*
     876             :  * This DateFormatSymbolsSingleSetter class is a friend of DateFormatSymbols
     877             :  * solely for the purpose of avoiding to clone the array of strings
     878             :  * just to modify one of them and then setting all of them back.
     879             :  * For example, the old code looked like this:
     880             :  *  case UDAT_MONTHS:
     881             :  *    res = syms->getMonths(count);
     882             :  *    array = new UnicodeString[count];
     883             :  *    if(array == 0) {
     884             :  *      *status = U_MEMORY_ALLOCATION_ERROR;
     885             :  *      return;
     886             :  *    }
     887             :  *    uprv_arrayCopy(res, array, count);
     888             :  *    if(index < count)
     889             :  *      array[index] = val;
     890             :  *    syms->setMonths(array, count);
     891             :  *    break;
     892             :  *
     893             :  * Even worse, the old code actually cloned the entire DateFormatSymbols object,
     894             :  * cloned one value array, changed one value, and then made the SimpleDateFormat
     895             :  * replace its DateFormatSymbols object with the new one.
     896             :  *
     897             :  * markus 2002-oct-14
     898             :  */
     899             : class DateFormatSymbolsSingleSetter /* not : public UObject because all methods are static */ {
     900             : public:
     901             :     static void
     902           0 :         setSymbol(UnicodeString *array, int32_t count, int32_t index,
     903             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
     904             :     {
     905           0 :         if(array!=NULL) {
     906           0 :             if(index>=count) {
     907           0 :                 errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
     908           0 :             } else if(value==NULL) {
     909           0 :                 errorCode=U_ILLEGAL_ARGUMENT_ERROR;
     910             :             } else {
     911           0 :                 array[index].setTo(value, valueLength);
     912             :             }
     913             :         }
     914           0 :     }
     915             : 
     916             :     static void
     917           0 :         setEra(DateFormatSymbols *syms, int32_t index,
     918             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
     919             :     {
     920           0 :         setSymbol(syms->fEras, syms->fErasCount, index, value, valueLength, errorCode);
     921           0 :     }
     922             : 
     923             :     static void
     924           0 :         setEraName(DateFormatSymbols *syms, int32_t index,
     925             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
     926             :     {
     927           0 :         setSymbol(syms->fEraNames, syms->fEraNamesCount, index, value, valueLength, errorCode);
     928           0 :     }
     929             : 
     930             :     static void
     931           0 :         setMonth(DateFormatSymbols *syms, int32_t index,
     932             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
     933             :     {
     934           0 :         setSymbol(syms->fMonths, syms->fMonthsCount, index, value, valueLength, errorCode);
     935           0 :     }
     936             : 
     937             :     static void
     938           0 :         setShortMonth(DateFormatSymbols *syms, int32_t index,
     939             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
     940             :     {
     941           0 :         setSymbol(syms->fShortMonths, syms->fShortMonthsCount, index, value, valueLength, errorCode);
     942           0 :     }
     943             : 
     944             :     static void
     945           0 :         setNarrowMonth(DateFormatSymbols *syms, int32_t index,
     946             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
     947             :     {
     948           0 :         setSymbol(syms->fNarrowMonths, syms->fNarrowMonthsCount, index, value, valueLength, errorCode);
     949           0 :     }
     950             : 
     951             :     static void
     952           0 :         setStandaloneMonth(DateFormatSymbols *syms, int32_t index,
     953             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
     954             :     {
     955           0 :         setSymbol(syms->fStandaloneMonths, syms->fStandaloneMonthsCount, index, value, valueLength, errorCode);
     956           0 :     }
     957             : 
     958             :     static void
     959           0 :         setStandaloneShortMonth(DateFormatSymbols *syms, int32_t index,
     960             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
     961             :     {
     962           0 :         setSymbol(syms->fStandaloneShortMonths, syms->fStandaloneShortMonthsCount, index, value, valueLength, errorCode);
     963           0 :     }
     964             : 
     965             :     static void
     966           0 :         setStandaloneNarrowMonth(DateFormatSymbols *syms, int32_t index,
     967             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
     968             :     {
     969           0 :         setSymbol(syms->fStandaloneNarrowMonths, syms->fStandaloneNarrowMonthsCount, index, value, valueLength, errorCode);
     970           0 :     }
     971             : 
     972             :     static void
     973           0 :         setWeekday(DateFormatSymbols *syms, int32_t index,
     974             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
     975             :     {
     976           0 :         setSymbol(syms->fWeekdays, syms->fWeekdaysCount, index, value, valueLength, errorCode);
     977           0 :     }
     978             : 
     979             :     static void
     980           0 :         setShortWeekday(DateFormatSymbols *syms, int32_t index,
     981             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
     982             :     {
     983           0 :         setSymbol(syms->fShortWeekdays, syms->fShortWeekdaysCount, index, value, valueLength, errorCode);
     984           0 :     }
     985             : 
     986             :     static void
     987           0 :         setShorterWeekday(DateFormatSymbols *syms, int32_t index,
     988             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
     989             :     {
     990           0 :         setSymbol(syms->fShorterWeekdays, syms->fShorterWeekdaysCount, index, value, valueLength, errorCode);
     991           0 :     }
     992             : 
     993             :     static void
     994           0 :         setNarrowWeekday(DateFormatSymbols *syms, int32_t index,
     995             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
     996             :     {
     997           0 :         setSymbol(syms->fNarrowWeekdays, syms->fNarrowWeekdaysCount, index, value, valueLength, errorCode);
     998           0 :     }
     999             : 
    1000             :     static void
    1001           0 :         setStandaloneWeekday(DateFormatSymbols *syms, int32_t index,
    1002             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
    1003             :     {
    1004           0 :         setSymbol(syms->fStandaloneWeekdays, syms->fStandaloneWeekdaysCount, index, value, valueLength, errorCode);
    1005           0 :     }
    1006             : 
    1007             :     static void
    1008           0 :         setStandaloneShortWeekday(DateFormatSymbols *syms, int32_t index,
    1009             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
    1010             :     {
    1011           0 :         setSymbol(syms->fStandaloneShortWeekdays, syms->fStandaloneShortWeekdaysCount, index, value, valueLength, errorCode);
    1012           0 :     }
    1013             : 
    1014             :     static void
    1015           0 :         setStandaloneShorterWeekday(DateFormatSymbols *syms, int32_t index,
    1016             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
    1017             :     {
    1018           0 :         setSymbol(syms->fStandaloneShorterWeekdays, syms->fStandaloneShorterWeekdaysCount, index, value, valueLength, errorCode);
    1019           0 :     }
    1020             : 
    1021             :     static void
    1022           0 :         setStandaloneNarrowWeekday(DateFormatSymbols *syms, int32_t index,
    1023             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
    1024             :     {
    1025           0 :         setSymbol(syms->fStandaloneNarrowWeekdays, syms->fStandaloneNarrowWeekdaysCount, index, value, valueLength, errorCode);
    1026           0 :     }
    1027             : 
    1028             :     static void
    1029           0 :         setQuarter(DateFormatSymbols *syms, int32_t index,
    1030             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
    1031             :     {
    1032           0 :         setSymbol(syms->fQuarters, syms->fQuartersCount, index, value, valueLength, errorCode);
    1033           0 :     }
    1034             : 
    1035             :     static void
    1036           0 :         setShortQuarter(DateFormatSymbols *syms, int32_t index,
    1037             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
    1038             :     {
    1039           0 :         setSymbol(syms->fShortQuarters, syms->fShortQuartersCount, index, value, valueLength, errorCode);
    1040           0 :     }
    1041             : 
    1042             :     static void
    1043           0 :         setStandaloneQuarter(DateFormatSymbols *syms, int32_t index,
    1044             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
    1045             :     {
    1046           0 :         setSymbol(syms->fStandaloneQuarters, syms->fStandaloneQuartersCount, index, value, valueLength, errorCode);
    1047           0 :     }
    1048             : 
    1049             :     static void
    1050           0 :         setStandaloneShortQuarter(DateFormatSymbols *syms, int32_t index,
    1051             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
    1052             :     {
    1053           0 :         setSymbol(syms->fStandaloneShortQuarters, syms->fStandaloneShortQuartersCount, index, value, valueLength, errorCode);
    1054           0 :     }
    1055             : 
    1056             :     static void
    1057           0 :         setShortYearNames(DateFormatSymbols *syms, int32_t index,
    1058             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
    1059             :     {
    1060           0 :         setSymbol(syms->fShortYearNames, syms->fShortYearNamesCount, index, value, valueLength, errorCode);
    1061           0 :     }
    1062             : 
    1063             :     static void
    1064           0 :         setShortZodiacNames(DateFormatSymbols *syms, int32_t index,
    1065             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
    1066             :     {
    1067           0 :         setSymbol(syms->fShortZodiacNames, syms->fShortZodiacNamesCount, index, value, valueLength, errorCode);
    1068           0 :     }
    1069             : 
    1070             :     static void
    1071           0 :         setAmPm(DateFormatSymbols *syms, int32_t index,
    1072             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
    1073             :     {
    1074           0 :         setSymbol(syms->fAmPms, syms->fAmPmsCount, index, value, valueLength, errorCode);
    1075           0 :     }
    1076             : 
    1077             :     static void
    1078           0 :         setLocalPatternChars(DateFormatSymbols *syms,
    1079             :         const UChar *value, int32_t valueLength, UErrorCode &errorCode)
    1080             :     {
    1081           0 :         setSymbol(&syms->fLocalPatternChars, 1, 0, value, valueLength, errorCode);
    1082           0 :     }
    1083             : };
    1084             : 
    1085             : U_NAMESPACE_END
    1086             : 
    1087             : U_CAPI void U_EXPORT2
    1088           0 : udat_setSymbols(    UDateFormat             *format,
    1089             :             UDateFormatSymbolType   type,
    1090             :             int32_t                 index,
    1091             :             UChar                   *value,
    1092             :             int32_t                 valueLength,
    1093             :             UErrorCode              *status)
    1094             : {
    1095           0 :     verifyIsSimpleDateFormat(format, status);
    1096           0 :     if(U_FAILURE(*status)) return;
    1097             : 
    1098           0 :     DateFormatSymbols *syms = (DateFormatSymbols *)((SimpleDateFormat *)format)->getDateFormatSymbols();
    1099             : 
    1100           0 :     switch(type) {
    1101             :     case UDAT_ERAS:
    1102           0 :         DateFormatSymbolsSingleSetter::setEra(syms, index, value, valueLength, *status);
    1103           0 :         break;
    1104             : 
    1105             :     case UDAT_ERA_NAMES:
    1106           0 :         DateFormatSymbolsSingleSetter::setEraName(syms, index, value, valueLength, *status);
    1107           0 :         break;
    1108             : 
    1109             :     case UDAT_MONTHS:
    1110           0 :         DateFormatSymbolsSingleSetter::setMonth(syms, index, value, valueLength, *status);
    1111           0 :         break;
    1112             : 
    1113             :     case UDAT_SHORT_MONTHS:
    1114           0 :         DateFormatSymbolsSingleSetter::setShortMonth(syms, index, value, valueLength, *status);
    1115           0 :         break;
    1116             : 
    1117             :     case UDAT_NARROW_MONTHS:
    1118           0 :         DateFormatSymbolsSingleSetter::setNarrowMonth(syms, index, value, valueLength, *status);
    1119           0 :         break;
    1120             : 
    1121             :     case UDAT_STANDALONE_MONTHS:
    1122           0 :         DateFormatSymbolsSingleSetter::setStandaloneMonth(syms, index, value, valueLength, *status);
    1123           0 :         break;
    1124             : 
    1125             :     case UDAT_STANDALONE_SHORT_MONTHS:
    1126           0 :         DateFormatSymbolsSingleSetter::setStandaloneShortMonth(syms, index, value, valueLength, *status);
    1127           0 :         break;
    1128             : 
    1129             :     case UDAT_STANDALONE_NARROW_MONTHS:
    1130           0 :         DateFormatSymbolsSingleSetter::setStandaloneNarrowMonth(syms, index, value, valueLength, *status);
    1131           0 :         break;
    1132             : 
    1133             :     case UDAT_WEEKDAYS:
    1134           0 :         DateFormatSymbolsSingleSetter::setWeekday(syms, index, value, valueLength, *status);
    1135           0 :         break;
    1136             : 
    1137             :     case UDAT_SHORT_WEEKDAYS:
    1138           0 :         DateFormatSymbolsSingleSetter::setShortWeekday(syms, index, value, valueLength, *status);
    1139           0 :         break;
    1140             : 
    1141             :     case UDAT_SHORTER_WEEKDAYS:
    1142           0 :         DateFormatSymbolsSingleSetter::setShorterWeekday(syms, index, value, valueLength, *status);
    1143           0 :         break;
    1144             : 
    1145             :     case UDAT_NARROW_WEEKDAYS:
    1146           0 :         DateFormatSymbolsSingleSetter::setNarrowWeekday(syms, index, value, valueLength, *status);
    1147           0 :         break;
    1148             : 
    1149             :     case UDAT_STANDALONE_WEEKDAYS:
    1150           0 :         DateFormatSymbolsSingleSetter::setStandaloneWeekday(syms, index, value, valueLength, *status);
    1151           0 :         break;
    1152             : 
    1153             :     case UDAT_STANDALONE_SHORT_WEEKDAYS:
    1154           0 :         DateFormatSymbolsSingleSetter::setStandaloneShortWeekday(syms, index, value, valueLength, *status);
    1155           0 :         break;
    1156             : 
    1157             :     case UDAT_STANDALONE_SHORTER_WEEKDAYS:
    1158           0 :         DateFormatSymbolsSingleSetter::setStandaloneShorterWeekday(syms, index, value, valueLength, *status);
    1159           0 :         break;
    1160             : 
    1161             :     case UDAT_STANDALONE_NARROW_WEEKDAYS:
    1162           0 :         DateFormatSymbolsSingleSetter::setStandaloneNarrowWeekday(syms, index, value, valueLength, *status);
    1163           0 :         break;
    1164             : 
    1165             :     case UDAT_QUARTERS:
    1166           0 :         DateFormatSymbolsSingleSetter::setQuarter(syms, index, value, valueLength, *status);
    1167           0 :         break;
    1168             : 
    1169             :     case UDAT_SHORT_QUARTERS:
    1170           0 :         DateFormatSymbolsSingleSetter::setShortQuarter(syms, index, value, valueLength, *status);
    1171           0 :         break;
    1172             : 
    1173             :     case UDAT_STANDALONE_QUARTERS:
    1174           0 :         DateFormatSymbolsSingleSetter::setStandaloneQuarter(syms, index, value, valueLength, *status);
    1175           0 :         break;
    1176             : 
    1177             :     case UDAT_STANDALONE_SHORT_QUARTERS:
    1178           0 :         DateFormatSymbolsSingleSetter::setStandaloneShortQuarter(syms, index, value, valueLength, *status);
    1179           0 :         break;
    1180             : 
    1181             :     case UDAT_CYCLIC_YEARS_ABBREVIATED:
    1182           0 :         DateFormatSymbolsSingleSetter::setShortYearNames(syms, index, value, valueLength, *status);
    1183           0 :         break;
    1184             : 
    1185             :     case UDAT_ZODIAC_NAMES_ABBREVIATED:
    1186           0 :         DateFormatSymbolsSingleSetter::setShortZodiacNames(syms, index, value, valueLength, *status);
    1187           0 :         break;
    1188             : 
    1189             :     case UDAT_AM_PMS:
    1190           0 :         DateFormatSymbolsSingleSetter::setAmPm(syms, index, value, valueLength, *status);
    1191           0 :         break;
    1192             : 
    1193             :     case UDAT_LOCALIZED_CHARS:
    1194           0 :         DateFormatSymbolsSingleSetter::setLocalPatternChars(syms, value, valueLength, *status);
    1195           0 :         break;
    1196             : 
    1197             :     default:
    1198           0 :         *status = U_UNSUPPORTED_ERROR;
    1199           0 :         break;
    1200             :         
    1201             :     }
    1202             : }
    1203             : 
    1204             : U_CAPI const char* U_EXPORT2
    1205           0 : udat_getLocaleByType(const UDateFormat *fmt,
    1206             :                      ULocDataLocaleType type,
    1207             :                      UErrorCode* status)
    1208             : {
    1209           0 :     if (fmt == NULL) {
    1210           0 :         if (U_SUCCESS(*status)) {
    1211           0 :             *status = U_ILLEGAL_ARGUMENT_ERROR;
    1212             :         }
    1213           0 :         return NULL;
    1214             :     }
    1215           0 :     return ((Format*)fmt)->getLocaleID(type, *status);
    1216             : }
    1217             : 
    1218             : U_CAPI void U_EXPORT2
    1219           0 : udat_setContext(UDateFormat* fmt, UDisplayContext value, UErrorCode* status)
    1220             : {
    1221           0 :     if (U_FAILURE(*status)) {
    1222           0 :         return;
    1223             :     }
    1224           0 :     ((DateFormat*)fmt)->setContext(value, *status);
    1225           0 :     return;
    1226             : }
    1227             : 
    1228             : U_CAPI UDisplayContext U_EXPORT2
    1229           0 : udat_getContext(const UDateFormat* fmt, UDisplayContextType type, UErrorCode* status)
    1230             : {
    1231           0 :     if (U_FAILURE(*status)) {
    1232           0 :         return (UDisplayContext)0;
    1233             :     }
    1234           0 :     return ((const DateFormat*)fmt)->getContext(type, *status);
    1235             : }
    1236             : 
    1237             : 
    1238             : /**
    1239             :  * Verify that fmt is a RelativeDateFormat. Invalid error if not.
    1240             :  * @param fmt the UDateFormat, definitely a DateFormat, maybe something else
    1241             :  * @param status error code, will be set to failure if there is a familure or the fmt is NULL.
    1242             :  */
    1243           0 : static void verifyIsRelativeDateFormat(const UDateFormat* fmt, UErrorCode *status) {
    1244           0 :    if(U_SUCCESS(*status) &&
    1245           0 :        dynamic_cast<const RelativeDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))==NULL) {
    1246           0 :        *status = U_ILLEGAL_ARGUMENT_ERROR;
    1247             :    }
    1248           0 : }
    1249             : 
    1250             : 
    1251             : U_CAPI int32_t U_EXPORT2 
    1252           0 : udat_toPatternRelativeDate(const UDateFormat *fmt,
    1253             :                            UChar             *result,
    1254             :                            int32_t           resultLength,
    1255             :                            UErrorCode        *status)
    1256             : {
    1257           0 :     verifyIsRelativeDateFormat(fmt, status);
    1258           0 :     if(U_FAILURE(*status)) {
    1259           0 :         return -1;
    1260             :     }
    1261           0 :     if (result == NULL ? resultLength != 0 : resultLength < 0) {
    1262           0 :         *status = U_ILLEGAL_ARGUMENT_ERROR;
    1263           0 :         return -1;
    1264             :     }
    1265             : 
    1266           0 :     UnicodeString datePattern;
    1267           0 :     if (result != NULL) {
    1268             :         // NULL destination for pure preflighting: empty dummy string
    1269             :         // otherwise, alias the destination buffer
    1270           0 :         datePattern.setTo(result, 0, resultLength);
    1271             :     }
    1272           0 :     ((RelativeDateFormat*)fmt)->toPatternDate(datePattern, *status);
    1273           0 :     return datePattern.extract(result, resultLength, *status);
    1274             : }
    1275             : 
    1276             : U_CAPI int32_t U_EXPORT2 
    1277           0 : udat_toPatternRelativeTime(const UDateFormat *fmt,
    1278             :                            UChar             *result,
    1279             :                            int32_t           resultLength,
    1280             :                            UErrorCode        *status)
    1281             : {
    1282           0 :     verifyIsRelativeDateFormat(fmt, status);
    1283           0 :     if(U_FAILURE(*status)) {
    1284           0 :         return -1;
    1285             :     }
    1286           0 :     if (result == NULL ? resultLength != 0 : resultLength < 0) {
    1287           0 :         *status = U_ILLEGAL_ARGUMENT_ERROR;
    1288           0 :         return -1;
    1289             :     }
    1290             : 
    1291           0 :     UnicodeString timePattern;
    1292           0 :     if (result != NULL) {
    1293             :         // NULL destination for pure preflighting: empty dummy string
    1294             :         // otherwise, alias the destination buffer
    1295           0 :         timePattern.setTo(result, 0, resultLength);
    1296             :     }
    1297           0 :     ((RelativeDateFormat*)fmt)->toPatternTime(timePattern, *status);
    1298           0 :     return timePattern.extract(result, resultLength, *status);
    1299             : }
    1300             : 
    1301             : U_CAPI void U_EXPORT2 
    1302           0 : udat_applyPatternRelative(UDateFormat *format,
    1303             :                           const UChar *datePattern,
    1304             :                           int32_t     datePatternLength,
    1305             :                           const UChar *timePattern,
    1306             :                           int32_t     timePatternLength,
    1307             :                           UErrorCode  *status)
    1308             : {
    1309           0 :     verifyIsRelativeDateFormat(format, status);
    1310           0 :     if(U_FAILURE(*status)) return;
    1311           0 :     const UnicodeString datePat((UBool)(datePatternLength == -1), datePattern, datePatternLength);
    1312           0 :     const UnicodeString timePat((UBool)(timePatternLength == -1), timePattern, timePatternLength);
    1313           0 :     ((RelativeDateFormat*)format)->applyPatterns(datePat, timePat, *status);
    1314             : }
    1315             : 
    1316             : #endif /* #if !UCONFIG_NO_FORMATTING */

Generated by: LCOV version 1.13