1c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/*
2c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott*******************************************************************************
3c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott*   Copyright (C) 1996-2009, International Business Machines
4c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott*   Corporation and others.  All Rights Reserved.
5c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott*******************************************************************************
6c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott*/
7c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
8c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/utypes.h"
9c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
10c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#if !UCONFIG_NO_FORMATTING
11c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
12c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/udat.h"
13c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
14c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/uloc.h"
15c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/datefmt.h"
16c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/timezone.h"
17c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/smpdtfmt.h"
18c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/fieldpos.h"
19c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/parsepos.h"
20c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/calendar.h"
21c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/numfmt.h"
22c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/dtfmtsym.h"
23c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/ustring.h"
24c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "cpputils.h"
25c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "reldtfmt.h"
26c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
27c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_NAMESPACE_USE
28c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
29c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/**
30c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * Verify that fmt is a SimpleDateFormat. Invalid error if not.
31c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @param fmt the UDateFormat, definitely a DateFormat, maybe something else
32c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @param status error code, will be set to failure if there is a familure or the fmt is NULL.
33c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott */
34c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottstatic void verifyIsSimpleDateFormat(const UDateFormat* fmt, UErrorCode *status) {
35c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott   if(!U_FAILURE(*status) &&
36c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott       ((DateFormat*)fmt)->getDynamicClassID()!=SimpleDateFormat::getStaticClassID()) {
37c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott       *status = U_ILLEGAL_ARGUMENT_ERROR;
38c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott   }
39c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
40c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
41c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI UDateFormat* U_EXPORT2
42c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_open(UDateFormatStyle  timeStyle,
43c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott          UDateFormatStyle  dateStyle,
44c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott          const char        *locale,
45c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott          const UChar       *tzID,
46c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott          int32_t           tzIDLength,
47c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott          const UChar       *pattern,
48c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott          int32_t           patternLength,
49c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott          UErrorCode        *status)
50c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
51c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    DateFormat *fmt;
52c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(*status)) {
53c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        return 0;
54c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
55c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(timeStyle != UDAT_IGNORE) {
56c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        if(locale == 0) {
57c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
58c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                (DateFormat::EStyle)timeStyle);
59c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        }
60c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        else {
61c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
62c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                (DateFormat::EStyle)timeStyle,
63c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                Locale(locale));
64c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        }
65c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
66c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    else {
67c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        UnicodeString pat((UBool)(patternLength == -1), pattern, patternLength);
68c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
69c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        if(locale == 0) {
70c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            fmt = new SimpleDateFormat(pat, *status);
71c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        }
72c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        else {
73c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            fmt = new SimpleDateFormat(pat, Locale(locale), *status);
74c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        }
75c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
76c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
77c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(fmt == 0) {
78c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        *status = U_MEMORY_ALLOCATION_ERROR;
79c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        return 0;
80c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
81c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
82c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(tzID != 0) {
83c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        TimeZone *zone = TimeZone::createTimeZone(UnicodeString((UBool)(tzIDLength == -1), tzID, tzIDLength));
84c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        if(zone == 0) {
85c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            *status = U_MEMORY_ALLOCATION_ERROR;
86c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            delete fmt;
87c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            return 0;
88c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        }
89c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        fmt->adoptTimeZone(zone);
90c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
91c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
92c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return (UDateFormat*)fmt;
93c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
94c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
95c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
96c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI void U_EXPORT2
97c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_close(UDateFormat* format)
98c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
99c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    delete (DateFormat*)format;
100c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
101c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
102c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI UDateFormat* U_EXPORT2
103c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_clone(const UDateFormat *fmt,
104c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott       UErrorCode *status)
105c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
106c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(*status)) return 0;
107c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
108c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    Format *res = ((DateFormat*)fmt)->clone();
109c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
110c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(res == 0) {
111c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        *status = U_MEMORY_ALLOCATION_ERROR;
112c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        return 0;
113c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
114c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
115c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return (UDateFormat*) res;
116c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
117c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
118c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI int32_t U_EXPORT2
119c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_format(    const    UDateFormat*    format,
120c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        UDate           dateToFormat,
121c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        UChar*          result,
122c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        int32_t         resultLength,
123c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        UFieldPosition* position,
124c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        UErrorCode*     status)
125c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
126c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(*status)) return -1;
127c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
128c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    UnicodeString res;
129c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(!(result==NULL && resultLength==0)) {
130c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        // NULL destination for pure preflighting: empty dummy string
131c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        // otherwise, alias the destination buffer
132c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res.setTo(result, 0, resultLength);
133c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
134c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
135c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    FieldPosition fp;
136c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
137c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(position != 0)
138c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        fp.setField(position->field);
139c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
140c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    ((DateFormat*)format)->format(dateToFormat, res, fp);
141c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
142c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(position != 0) {
143c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        position->beginIndex = fp.getBeginIndex();
144c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        position->endIndex = fp.getEndIndex();
145c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
146c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
147c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return res.extract(result, resultLength, *status);
148c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
149c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
150c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI UDate U_EXPORT2
151c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_parse(    const    UDateFormat*        format,
152c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const    UChar*          text,
153c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        int32_t         textLength,
154c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        int32_t         *parsePos,
155c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        UErrorCode      *status)
156c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
157c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(*status)) return (UDate)0;
158c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
159c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    const UnicodeString src((UBool)(textLength == -1), text, textLength);
160c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    ParsePosition pp;
161c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    int32_t stackParsePos = 0;
162c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    UDate res;
163c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
164c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(parsePos == NULL) {
165c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        parsePos = &stackParsePos;
166c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
167c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
168c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    pp.setIndex(*parsePos);
169c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
170c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    res = ((DateFormat*)format)->parse(src, pp);
171c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
172c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(pp.getErrorIndex() == -1)
173c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        *parsePos = pp.getIndex();
174c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    else {
175c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        *parsePos = pp.getErrorIndex();
176c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        *status = U_PARSE_ERROR;
177c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
178c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
179c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return res;
180c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
181c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
182c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI void U_EXPORT2
183c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_parseCalendar(const    UDateFormat*    format,
184c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                            UCalendar*      calendar,
185c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                   const    UChar*          text,
186c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                            int32_t         textLength,
187c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                            int32_t         *parsePos,
188c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                            UErrorCode      *status)
189c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
190c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(*status)) return;
191c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
192c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    const UnicodeString src((UBool)(textLength == -1), text, textLength);
193c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    ParsePosition pp;
194c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
195c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(parsePos != 0)
196c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        pp.setIndex(*parsePos);
197c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
198c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    ((DateFormat*)format)->parse(src, *(Calendar*)calendar, pp);
199c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
200c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(parsePos != 0) {
201c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        if(pp.getErrorIndex() == -1)
202c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            *parsePos = pp.getIndex();
203c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        else {
204c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            *parsePos = pp.getErrorIndex();
205c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            *status = U_PARSE_ERROR;
206c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        }
207c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
208c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
209c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
210c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI UBool U_EXPORT2
211c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_isLenient(const UDateFormat* fmt)
212c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
213c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return ((DateFormat*)fmt)->isLenient();
214c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
215c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
216c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI void U_EXPORT2
217c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_setLenient(    UDateFormat*    fmt,
218c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            UBool          isLenient)
219c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
220c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    ((DateFormat*)fmt)->setLenient(isLenient);
221c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
222c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
223c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI const UCalendar* U_EXPORT2
224c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_getCalendar(const UDateFormat* fmt)
225c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
226c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return (const UCalendar*) ((DateFormat*)fmt)->getCalendar();
227c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
228c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
229c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI void U_EXPORT2
230c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_setCalendar(UDateFormat*    fmt,
231c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                 const   UCalendar*      calendarToSet)
232c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
233c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    ((DateFormat*)fmt)->setCalendar(*((Calendar*)calendarToSet));
234c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
235c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
236c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI const UNumberFormat* U_EXPORT2
237c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_getNumberFormat(const UDateFormat* fmt)
238c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
239c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return (const UNumberFormat*) ((DateFormat*)fmt)->getNumberFormat();
240c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
241c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
242c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI void U_EXPORT2
243c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_setNumberFormat(UDateFormat*    fmt,
244c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                     const   UNumberFormat*  numberFormatToSet)
245c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
246c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    ((DateFormat*)fmt)->setNumberFormat(*((NumberFormat*)numberFormatToSet));
247c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
248c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
249c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI const char* U_EXPORT2
250c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_getAvailable(int32_t index)
251c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
252c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return uloc_getAvailable(index);
253c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
254c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
255c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI int32_t U_EXPORT2
256c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_countAvailable()
257c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
258c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return uloc_countAvailable();
259c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
260c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
261c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI UDate U_EXPORT2
262c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_get2DigitYearStart(    const   UDateFormat     *fmt,
263c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                        UErrorCode      *status)
264c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
265c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    verifyIsSimpleDateFormat(fmt, status);
266c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(*status)) return (UDate)0;
267c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return ((SimpleDateFormat*)fmt)->get2DigitYearStart(*status);
268c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
269c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
270c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI void U_EXPORT2
271c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_set2DigitYearStart(    UDateFormat     *fmt,
272c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                        UDate           d,
273c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                        UErrorCode      *status)
274c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
275c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    verifyIsSimpleDateFormat(fmt, status);
276c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(*status)) return;
277c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    ((SimpleDateFormat*)fmt)->set2DigitYearStart(d, *status);
278c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
279c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
280c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI int32_t U_EXPORT2
281c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_toPattern(    const   UDateFormat     *fmt,
282c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        UBool          localized,
283c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        UChar           *result,
284c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        int32_t         resultLength,
285c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        UErrorCode      *status)
286c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
287c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(*status)) return -1;
288c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
289c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    UnicodeString res;
290c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(!(result==NULL && resultLength==0)) {
291c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        // NULL destination for pure preflighting: empty dummy string
292c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        // otherwise, alias the destination buffer
293c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res.setTo(result, 0, resultLength);
294c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
295c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
296c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if ( ((DateFormat*)fmt)->getDynamicClassID()==SimpleDateFormat::getStaticClassID() ) {
297c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        if(localized)
298c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            ((SimpleDateFormat*)fmt)->toLocalizedPattern(res, *status);
299c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        else
300c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            ((SimpleDateFormat*)fmt)->toPattern(res);
301c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    } else if ( !localized && ((DateFormat*)fmt)->getDynamicClassID()==RelativeDateFormat::getStaticClassID() ) {
302c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        ((RelativeDateFormat*)fmt)->toPattern(res, *status);
303c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    } else {
304c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        *status = U_ILLEGAL_ARGUMENT_ERROR;
305c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        return -1;
306c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
307c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
308c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return res.extract(result, resultLength, *status);
309c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
310c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
311c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// TODO: should this take an UErrorCode?
312c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// A: Yes. Of course.
313c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI void U_EXPORT2
314c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_applyPattern(  UDateFormat     *format,
315c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                    UBool          localized,
316c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                    const   UChar           *pattern,
317c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                    int32_t         patternLength)
318c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
319c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    const UnicodeString pat((UBool)(patternLength == -1), pattern, patternLength);
320c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    UErrorCode status = U_ZERO_ERROR;
321c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
322c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    verifyIsSimpleDateFormat(format, &status);
323c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(status)) {
324c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        return;
325c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
326c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
327c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(localized)
328c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        ((SimpleDateFormat*)format)->applyLocalizedPattern(pat, status);
329c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    else
330c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        ((SimpleDateFormat*)format)->applyPattern(pat);
331c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
332c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
333c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI int32_t U_EXPORT2
334c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_getSymbols(const   UDateFormat     *fmt,
335c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                UDateFormatSymbolType   type,
336c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                int32_t                 index,
337c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                UChar                   *result,
338c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                int32_t                 resultLength,
339c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                UErrorCode              *status)
340c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
341c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    verifyIsSimpleDateFormat(fmt, status);
342c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(*status)) return -1;
343c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
344c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    const DateFormatSymbols *syms =
345c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        ((SimpleDateFormat*)fmt)->getDateFormatSymbols();
346c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    int32_t count;
347c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    const UnicodeString *res = NULL;
348c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
349c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    switch(type) {
350c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_ERAS:
351c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getEras(count);
352c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
353c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
354c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_ERA_NAMES:
355c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getEraNames(count);
356c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
357c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
358c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_MONTHS:
359c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getMonths(count);
360c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
361c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
362c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_SHORT_MONTHS:
363c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getShortMonths(count);
364c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
365c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
366c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_WEEKDAYS:
367c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getWeekdays(count);
368c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
369c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
370c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_SHORT_WEEKDAYS:
371c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getShortWeekdays(count);
372c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
373c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
374c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_AM_PMS:
375c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getAmPmStrings(count);
376c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
377c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
378c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_LOCALIZED_CHARS:
379c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        {
380c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            UnicodeString res1;
381c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            if(!(result==NULL && resultLength==0)) {
382c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                // NULL destination for pure preflighting: empty dummy string
383c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                // otherwise, alias the destination buffer
384c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                res1.setTo(result, 0, resultLength);
385c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            }
386c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            syms->getLocalPatternChars(res1);
387c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            return res1.extract(result, resultLength, *status);
388c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        }
389c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
390c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_NARROW_MONTHS:
391c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getMonths(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
392c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
393c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
394c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_NARROW_WEEKDAYS:
395c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getWeekdays(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
396c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
397c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
398c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_MONTHS:
399c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
400c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
401c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
402c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_SHORT_MONTHS:
403c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
404c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
405c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
406c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_NARROW_MONTHS:
407c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
408c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
409c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
410c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_WEEKDAYS:
411c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
412c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
413c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
414c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_SHORT_WEEKDAYS:
415c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
416c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
417c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
418c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_NARROW_WEEKDAYS:
419c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
420c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
421c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
422c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_QUARTERS:
423c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
424c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
425c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
426c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_SHORT_QUARTERS:
427c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
428c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
429c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
430c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_QUARTERS:
431c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
432c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
433c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
434c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_SHORT_QUARTERS:
435c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        res = syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
436c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
437c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
438c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
439c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
440c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(index < count) {
441c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        return res[index].extract(result, resultLength, *status);
442c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
443c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return 0;
444c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
445c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
446c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// TODO: also needs an errorCode.
447c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI int32_t U_EXPORT2
448c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_countSymbols(    const    UDateFormat                *fmt,
449c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            UDateFormatSymbolType    type)
450c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
451c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    UErrorCode status = U_ZERO_ERROR;
452c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
453c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    verifyIsSimpleDateFormat(fmt, &status);
454c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(status)) {
455c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        return 0;
456c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
457c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
458c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    const DateFormatSymbols *syms =
459c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        ((SimpleDateFormat*)fmt)->getDateFormatSymbols();
460c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    int32_t count = 0;
461c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
462c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    switch(type) {
463c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_ERAS:
464c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getEras(count);
465c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
466c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
467c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_MONTHS:
468c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getMonths(count);
469c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
470c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
471c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_SHORT_MONTHS:
472c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getShortMonths(count);
473c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
474c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
475c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_WEEKDAYS:
476c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getWeekdays(count);
477c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
478c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
479c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_SHORT_WEEKDAYS:
480c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getShortWeekdays(count);
481c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
482c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
483c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_AM_PMS:
484c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getAmPmStrings(count);
485c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
486c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
487c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_LOCALIZED_CHARS:
488c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        count = 1;
489c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
490c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
491c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_ERA_NAMES:
492c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getEraNames(count);
493c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
494c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
495c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_NARROW_MONTHS:
496c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getMonths(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
497c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
498c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
499c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_NARROW_WEEKDAYS:
500c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getWeekdays(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
501c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
502c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
503c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_MONTHS:
504c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
505c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
506c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
507c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_SHORT_MONTHS:
508c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
509c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
510c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
511c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_NARROW_MONTHS:
512c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
513c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
514c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
515c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_WEEKDAYS:
516c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
517c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
518c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
519c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_SHORT_WEEKDAYS:
520c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
521c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
522c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
523c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_NARROW_WEEKDAYS:
524c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
525c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
526c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
527c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_QUARTERS:
528c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
529c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
530c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
531c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_SHORT_QUARTERS:
532c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
533c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
534c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
535c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_QUARTERS:
536c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
537c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
538c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
539c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_SHORT_QUARTERS:
540c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
541c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
542c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
543c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
544c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
545c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return count;
546c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
547c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
548c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_NAMESPACE_BEGIN
549c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
550c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/*
551c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * This DateFormatSymbolsSingleSetter class is a friend of DateFormatSymbols
552c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * solely for the purpose of avoiding to clone the array of strings
553c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * just to modify one of them and then setting all of them back.
554c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * For example, the old code looked like this:
555c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *  case UDAT_MONTHS:
556c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *    res = syms->getMonths(count);
557c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *    array = new UnicodeString[count];
558c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *    if(array == 0) {
559c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *      *status = U_MEMORY_ALLOCATION_ERROR;
560c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *      return;
561c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *    }
562c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *    uprv_arrayCopy(res, array, count);
563c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *    if(index < count)
564c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *      array[index] = val;
565c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *    syms->setMonths(array, count);
566c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *    break;
567c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *
568c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * Even worse, the old code actually cloned the entire DateFormatSymbols object,
569c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * cloned one value array, changed one value, and then made the SimpleDateFormat
570c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * replace its DateFormatSymbols object with the new one.
571c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *
572c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * markus 2002-oct-14
573c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott */
574c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass DateFormatSymbolsSingleSetter /* not : public UObject because all methods are static */ {
575c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic:
576c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
577c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(UnicodeString *array, int32_t count, int32_t index,
578c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
579c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
580c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        if(array!=NULL) {
581c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            if(index>=count) {
582c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
583c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            } else if(value==NULL) {
584c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                errorCode=U_ILLEGAL_ARGUMENT_ERROR;
585c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            } else {
586c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                array[index].setTo(value, valueLength);
587c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            }
588c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        }
589c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
590c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
591c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
592c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setEra(DateFormatSymbols *syms, int32_t index,
593c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
594c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
595c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fEras, syms->fErasCount, index, value, valueLength, errorCode);
596c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
597c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
598c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
599c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setEraName(DateFormatSymbols *syms, int32_t index,
600c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
601c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
602c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fEraNames, syms->fEraNamesCount, index, value, valueLength, errorCode);
603c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
604c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
605c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
606c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setMonth(DateFormatSymbols *syms, int32_t index,
607c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
608c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
609c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fMonths, syms->fMonthsCount, index, value, valueLength, errorCode);
610c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
611c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
612c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
613c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setShortMonth(DateFormatSymbols *syms, int32_t index,
614c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
615c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
616c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fShortMonths, syms->fShortMonthsCount, index, value, valueLength, errorCode);
617c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
618c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
619c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
620c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setNarrowMonth(DateFormatSymbols *syms, int32_t index,
621c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
622c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
623c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fNarrowMonths, syms->fNarrowMonthsCount, index, value, valueLength, errorCode);
624c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
625c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
626c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
627c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setStandaloneMonth(DateFormatSymbols *syms, int32_t index,
628c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
629c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
630c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fStandaloneMonths, syms->fStandaloneMonthsCount, index, value, valueLength, errorCode);
631c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
632c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
633c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
634c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setStandaloneShortMonth(DateFormatSymbols *syms, int32_t index,
635c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
636c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
637c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fStandaloneShortMonths, syms->fStandaloneShortMonthsCount, index, value, valueLength, errorCode);
638c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
639c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
640c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
641c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setStandaloneNarrowMonth(DateFormatSymbols *syms, int32_t index,
642c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
643c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
644c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fStandaloneNarrowMonths, syms->fStandaloneNarrowMonthsCount, index, value, valueLength, errorCode);
645c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
646c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
647c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
648c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setWeekday(DateFormatSymbols *syms, int32_t index,
649c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
650c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
651c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fWeekdays, syms->fWeekdaysCount, index, value, valueLength, errorCode);
652c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
653c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
654c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
655c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setShortWeekday(DateFormatSymbols *syms, int32_t index,
656c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
657c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
658c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fShortWeekdays, syms->fShortWeekdaysCount, index, value, valueLength, errorCode);
659c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
660c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
661c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
662c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setNarrowWeekday(DateFormatSymbols *syms, int32_t index,
663c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
664c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
665c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fNarrowWeekdays, syms->fNarrowWeekdaysCount, index, value, valueLength, errorCode);
666c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
667c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
668c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
669c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setStandaloneWeekday(DateFormatSymbols *syms, int32_t index,
670c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
671c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
672c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fStandaloneWeekdays, syms->fStandaloneWeekdaysCount, index, value, valueLength, errorCode);
673c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
674c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
675c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
676c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setStandaloneShortWeekday(DateFormatSymbols *syms, int32_t index,
677c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
678c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
679c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fStandaloneShortWeekdays, syms->fStandaloneShortWeekdaysCount, index, value, valueLength, errorCode);
680c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
681c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
682c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
683c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setStandaloneNarrowWeekday(DateFormatSymbols *syms, int32_t index,
684c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
685c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
686c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fStandaloneNarrowWeekdays, syms->fStandaloneNarrowWeekdaysCount, index, value, valueLength, errorCode);
687c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
688c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
689c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
690c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setQuarter(DateFormatSymbols *syms, int32_t index,
691c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
692c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
693c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fQuarters, syms->fQuartersCount, index, value, valueLength, errorCode);
694c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
695c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
696c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
697c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setShortQuarter(DateFormatSymbols *syms, int32_t index,
698c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
699c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
700c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fShortQuarters, syms->fShortQuartersCount, index, value, valueLength, errorCode);
701c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
702c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
703c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
704c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setStandaloneQuarter(DateFormatSymbols *syms, int32_t index,
705c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
706c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
707c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fStandaloneQuarters, syms->fStandaloneQuartersCount, index, value, valueLength, errorCode);
708c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
709c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
710c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
711c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setStandaloneShortQuarter(DateFormatSymbols *syms, int32_t index,
712c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
713c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
714c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fStandaloneShortQuarters, syms->fStandaloneShortQuartersCount, index, value, valueLength, errorCode);
715c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
716c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
717c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
718c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setAmPm(DateFormatSymbols *syms, int32_t index,
719c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
720c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
721c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(syms->fAmPms, syms->fAmPmsCount, index, value, valueLength, errorCode);
722c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
723c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
724c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    static void
725c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setLocalPatternChars(DateFormatSymbols *syms,
726c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        const UChar *value, int32_t valueLength, UErrorCode &errorCode)
727c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    {
728c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        setSymbol(&syms->fLocalPatternChars, 1, 0, value, valueLength, errorCode);
729c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
730c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott};
731c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
732c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_NAMESPACE_END
733c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
734c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI void U_EXPORT2
735c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_setSymbols(    UDateFormat             *format,
736c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            UDateFormatSymbolType   type,
737c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            int32_t                 index,
738c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            UChar                   *value,
739c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            int32_t                 valueLength,
740c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            UErrorCode              *status)
741c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
742c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
743c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(*status)) return;
744c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
745c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    DateFormatSymbols *syms = (DateFormatSymbols *)((SimpleDateFormat *)format)->getDateFormatSymbols();
746c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
747c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    switch(type) {
748c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_ERAS:
749c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setEra(syms, index, value, valueLength, *status);
750c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
751c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
752c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_ERA_NAMES:
753c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setEraName(syms, index, value, valueLength, *status);
754c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
755c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
756c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_MONTHS:
757c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setMonth(syms, index, value, valueLength, *status);
758c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
759c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
760c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_SHORT_MONTHS:
761c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setShortMonth(syms, index, value, valueLength, *status);
762c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
763c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
764c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_NARROW_MONTHS:
765c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setNarrowMonth(syms, index, value, valueLength, *status);
766c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
767c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
768c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_MONTHS:
769c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setStandaloneMonth(syms, index, value, valueLength, *status);
770c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
771c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
772c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_SHORT_MONTHS:
773c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setStandaloneShortMonth(syms, index, value, valueLength, *status);
774c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
775c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
776c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_NARROW_MONTHS:
777c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setStandaloneNarrowMonth(syms, index, value, valueLength, *status);
778c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
779c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
780c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_WEEKDAYS:
781c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setWeekday(syms, index, value, valueLength, *status);
782c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
783c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
784c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_SHORT_WEEKDAYS:
785c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setShortWeekday(syms, index, value, valueLength, *status);
786c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
787c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
788c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_NARROW_WEEKDAYS:
789c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setNarrowWeekday(syms, index, value, valueLength, *status);
790c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
791c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
792c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_WEEKDAYS:
793c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setStandaloneWeekday(syms, index, value, valueLength, *status);
794c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
795c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
796c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_SHORT_WEEKDAYS:
797c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setStandaloneShortWeekday(syms, index, value, valueLength, *status);
798c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
799c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
800c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_NARROW_WEEKDAYS:
801c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setStandaloneNarrowWeekday(syms, index, value, valueLength, *status);
802c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
803c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
804c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_QUARTERS:
805c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setQuarter(syms, index, value, valueLength, *status);
806c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
807c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
808c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_SHORT_QUARTERS:
809c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setShortQuarter(syms, index, value, valueLength, *status);
810c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
811c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
812c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_QUARTERS:
813c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setStandaloneQuarter(syms, index, value, valueLength, *status);
814c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
815c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
816c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_STANDALONE_SHORT_QUARTERS:
817c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setStandaloneShortQuarter(syms, index, value, valueLength, *status);
818c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
819c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
820c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_AM_PMS:
821c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setAmPm(syms, index, value, valueLength, *status);
822c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
823c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
824c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    case UDAT_LOCALIZED_CHARS:
825c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        DateFormatSymbolsSingleSetter::setLocalPatternChars(syms, value, valueLength, *status);
826c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
827c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
828c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    default:
829c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        *status = U_UNSUPPORTED_ERROR;
830c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        break;
831c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
832c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
833c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
834c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
835c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI const char* U_EXPORT2
836c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_getLocaleByType(const UDateFormat *fmt,
837c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                     ULocDataLocaleType type,
838c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                     UErrorCode* status)
839c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
840c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if (fmt == NULL) {
841c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        if (U_SUCCESS(*status)) {
842c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            *status = U_ILLEGAL_ARGUMENT_ERROR;
843c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        }
844c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        return NULL;
845c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
846c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return ((Format*)fmt)->getLocaleID(type, *status);
847c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
848c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
849c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/**
850c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * Verify that fmt is a RelativeDateFormat. Invalid error if not.
851c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @param fmt the UDateFormat, definitely a DateFormat, maybe something else
852c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @param status error code, will be set to failure if there is a familure or the fmt is NULL.
853c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott */
854c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottstatic void verifyIsRelativeDateFormat(const UDateFormat* fmt, UErrorCode *status) {
855c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott   if(!U_FAILURE(*status) &&
856c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott       ((DateFormat*)fmt)->getDynamicClassID()!=RelativeDateFormat::getStaticClassID()) {
857c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott       *status = U_ILLEGAL_ARGUMENT_ERROR;
858c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott   }
859c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
860c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
861c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
862c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI int32_t U_EXPORT2
863c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_toPatternRelativeDate(const UDateFormat *fmt,
864c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                           UChar             *result,
865c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                           int32_t           resultLength,
866c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                           UErrorCode        *status)
867c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
868c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    verifyIsRelativeDateFormat(fmt, status);
869c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(*status)) return -1;
870c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
871c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    UnicodeString datePattern;
872c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(!(result==NULL && resultLength==0)) {
873c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        // NULL destination for pure preflighting: empty dummy string
874c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        // otherwise, alias the destination buffer
875c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        datePattern.setTo(result, 0, resultLength);
876c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
877c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    ((RelativeDateFormat*)fmt)->toPatternDate(datePattern, *status);
878c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return datePattern.extract(result, resultLength, *status);
879c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
880c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
881c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI int32_t U_EXPORT2
882c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_toPatternRelativeTime(const UDateFormat *fmt,
883c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                           UChar             *result,
884c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                           int32_t           resultLength,
885c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                           UErrorCode        *status)
886c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
887c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    verifyIsRelativeDateFormat(fmt, status);
888c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(*status)) return -1;
889c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
890c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    UnicodeString timePattern;
891c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(!(result==NULL && resultLength==0)) {
892c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        // NULL destination for pure preflighting: empty dummy string
893c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        // otherwise, alias the destination buffer
894c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        timePattern.setTo(result, 0, resultLength);
895c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
896c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    ((RelativeDateFormat*)fmt)->toPatternTime(timePattern, *status);
897c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return timePattern.extract(result, resultLength, *status);
898c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
899c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
900c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick ScottU_CAPI void U_EXPORT2
901c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottudat_applyPatternRelative(UDateFormat *format,
902c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                          const UChar *datePattern,
903c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                          int32_t     datePatternLength,
904c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                          const UChar *timePattern,
905c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                          int32_t     timePatternLength,
906c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                          UErrorCode  *status)
907c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott{
908c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    verifyIsRelativeDateFormat(format, status);
909c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if(U_FAILURE(*status)) return;
910c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    const UnicodeString datePat((UBool)(datePatternLength == -1), datePattern, datePatternLength);
911c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    const UnicodeString timePat((UBool)(timePatternLength == -1), timePattern, timePatternLength);
912c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    ((RelativeDateFormat*)format)->applyPatterns(datePat, timePat, *status);
913c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}
914c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
915c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#endif /* #if !UCONFIG_NO_FORMATTING */
916