]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/udatpg.cpp
ICU-400.38.tar.gz
[apple/icu.git] / icuSources / i18n / udatpg.cpp
CommitLineData
46f4442e
A
1/*
2*******************************************************************************
3*
4* Copyright (C) 2007, International Business Machines
5* Corporation and others. All Rights Reserved.
6*
7*******************************************************************************
8* file name: udatpg.cpp
9* encoding: US-ASCII
10* tab size: 8 (not used)
11* indentation:4
12*
13* created on: 2007jul30
14* created by: Markus W. Scherer
15*/
16
17#include "unicode/utypes.h"
18
19#if !UCONFIG_NO_FORMATTING
20
21#include "unicode/udatpg.h"
22#include "unicode/uenum.h"
23#include "unicode/strenum.h"
24#include "unicode/dtptngen.h"
25#include "ustrenum.h"
26
27U_NAMESPACE_USE
28
29U_DRAFT UDateTimePatternGenerator * U_EXPORT2
30udatpg_open(const char *locale, UErrorCode *pErrorCode) {
31 if(locale==NULL) {
32 return (UDateTimePatternGenerator *)DateTimePatternGenerator::createInstance(*pErrorCode);
33 } else {
34 return (UDateTimePatternGenerator *)DateTimePatternGenerator::createInstance(Locale(locale), *pErrorCode);
35 }
36}
37
38U_DRAFT UDateTimePatternGenerator * U_EXPORT2
39udatpg_openEmpty(UErrorCode *pErrorCode) {
40 return (UDateTimePatternGenerator *)DateTimePatternGenerator::createEmptyInstance(*pErrorCode);
41}
42
43U_DRAFT void U_EXPORT2
44udatpg_close(UDateTimePatternGenerator *dtpg) {
45 delete (DateTimePatternGenerator *)dtpg;
46}
47
48U_DRAFT UDateTimePatternGenerator * U_EXPORT2
49udatpg_clone(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) {
50 if(U_FAILURE(*pErrorCode)) {
51 return NULL;
52 }
53 return (UDateTimePatternGenerator *)(((const DateTimePatternGenerator *)dtpg)->clone());
54}
55
56U_DRAFT int32_t U_EXPORT2
57udatpg_getBestPattern(UDateTimePatternGenerator *dtpg,
58 const UChar *skeleton, int32_t length,
59 UChar *bestPattern, int32_t capacity,
60 UErrorCode *pErrorCode) {
61 if(U_FAILURE(*pErrorCode)) {
62 return 0;
63 }
64 if(skeleton==NULL && length!=0) {
65 *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
66 return 0;
67 }
68 UnicodeString skeletonString((UBool)(length<0), skeleton, length);
69 UnicodeString result=((DateTimePatternGenerator *)dtpg)->getBestPattern(skeletonString, *pErrorCode);
70 return result.extract(bestPattern, capacity, *pErrorCode);
71}
72
73U_DRAFT int32_t U_EXPORT2
74udatpg_getSkeleton(UDateTimePatternGenerator *dtpg,
75 const UChar *pattern, int32_t length,
76 UChar *skeleton, int32_t capacity,
77 UErrorCode *pErrorCode) {
78 if(U_FAILURE(*pErrorCode)) {
79 return 0;
80 }
81 if(pattern==NULL && length!=0) {
82 *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
83 return 0;
84 }
85 UnicodeString patternString((UBool)(length<0), pattern, length);
86 UnicodeString result=((DateTimePatternGenerator *)dtpg)->getSkeleton(patternString, *pErrorCode);
87 return result.extract(skeleton, capacity, *pErrorCode);
88}
89
90U_DRAFT int32_t U_EXPORT2
91udatpg_getBaseSkeleton(UDateTimePatternGenerator *dtpg,
92 const UChar *pattern, int32_t length,
93 UChar *skeleton, int32_t capacity,
94 UErrorCode *pErrorCode) {
95 if(U_FAILURE(*pErrorCode)) {
96 return 0;
97 }
98 if(pattern==NULL && length!=0) {
99 *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
100 return 0;
101 }
102 UnicodeString patternString((UBool)(length<0), pattern, length);
103 UnicodeString result=((DateTimePatternGenerator *)dtpg)->getBaseSkeleton(patternString, *pErrorCode);
104 return result.extract(skeleton, capacity, *pErrorCode);
105}
106
107U_DRAFT UDateTimePatternConflict U_EXPORT2
108udatpg_addPattern(UDateTimePatternGenerator *dtpg,
109 const UChar *pattern, int32_t patternLength,
110 UBool override,
111 UChar *conflictingPattern, int32_t capacity, int32_t *pLength,
112 UErrorCode *pErrorCode) {
113 if(U_FAILURE(*pErrorCode)) {
114 return UDATPG_NO_CONFLICT;
115 }
116 if(pattern==NULL && patternLength!=0) {
117 *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
118 return UDATPG_NO_CONFLICT;
119 }
120 UnicodeString patternString((UBool)(patternLength<0), pattern, patternLength);
121 UnicodeString conflictingPatternString;
122 UDateTimePatternConflict result=((DateTimePatternGenerator *)dtpg)->
123 addPattern(patternString, override, conflictingPatternString, *pErrorCode);
124 int32_t length=conflictingPatternString.extract(conflictingPattern, capacity, *pErrorCode);
125 if(pLength!=NULL) {
126 *pLength=length;
127 }
128 return result;
129}
130
131U_DRAFT void U_EXPORT2
132udatpg_setAppendItemFormat(UDateTimePatternGenerator *dtpg,
133 UDateTimePatternField field,
134 const UChar *value, int32_t length) {
135 UnicodeString valueString((UBool)(length<0), value, length);
136 ((DateTimePatternGenerator *)dtpg)->setAppendItemFormat(field, valueString);
137}
138
139U_DRAFT const UChar * U_EXPORT2
140udatpg_getAppendItemFormat(const UDateTimePatternGenerator *dtpg,
141 UDateTimePatternField field,
142 int32_t *pLength) {
143 const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getAppendItemFormat(field);
144 if(pLength!=NULL) {
145 *pLength=result.length();
146 }
147 return result.getBuffer();
148}
149
150U_DRAFT void U_EXPORT2
151udatpg_setAppendItemName(UDateTimePatternGenerator *dtpg,
152 UDateTimePatternField field,
153 const UChar *value, int32_t length) {
154 UnicodeString valueString((UBool)(length<0), value, length);
155 ((DateTimePatternGenerator *)dtpg)->setAppendItemName(field, valueString);
156}
157
158U_DRAFT const UChar * U_EXPORT2
159udatpg_getAppendItemName(const UDateTimePatternGenerator *dtpg,
160 UDateTimePatternField field,
161 int32_t *pLength) {
162 const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getAppendItemName(field);
163 if(pLength!=NULL) {
164 *pLength=result.length();
165 }
166 return result.getBuffer();
167}
168
169U_DRAFT void U_EXPORT2
170udatpg_setDateTimeFormat(const UDateTimePatternGenerator *dtpg,
171 const UChar *dtFormat, int32_t length) {
172 UnicodeString dtFormatString((UBool)(length<0), dtFormat, length);
173 ((DateTimePatternGenerator *)dtpg)->setDateTimeFormat(dtFormatString);
174}
175
176U_DRAFT const UChar * U_EXPORT2
177udatpg_getDateTimeFormat(const UDateTimePatternGenerator *dtpg,
178 int32_t *pLength) {
179 const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getDateTimeFormat();
180 if(pLength!=NULL) {
181 *pLength=result.length();
182 }
183 return result.getBuffer();
184}
185
186U_DRAFT void U_EXPORT2
187udatpg_setDecimal(UDateTimePatternGenerator *dtpg,
188 const UChar *decimal, int32_t length) {
189 UnicodeString decimalString((UBool)(length<0), decimal, length);
190 ((DateTimePatternGenerator *)dtpg)->setDecimal(decimalString);
191}
192
193U_DRAFT const UChar * U_EXPORT2
194udatpg_getDecimal(const UDateTimePatternGenerator *dtpg,
195 int32_t *pLength) {
196 const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getDecimal();
197 if(pLength!=NULL) {
198 *pLength=result.length();
199 }
200 return result.getBuffer();
201}
202
203U_DRAFT int32_t U_EXPORT2
204udatpg_replaceFieldTypes(UDateTimePatternGenerator *dtpg,
205 const UChar *pattern, int32_t patternLength,
206 const UChar *skeleton, int32_t skeletonLength,
207 UChar *dest, int32_t destCapacity,
208 UErrorCode *pErrorCode) {
209 if(U_FAILURE(*pErrorCode)) {
210 return 0;
211 }
212 if((pattern==NULL && patternLength!=0) || (skeleton==NULL && skeletonLength!=0)) {
213 *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
214 return 0;
215 }
216 UnicodeString patternString((UBool)(patternLength<0), pattern, patternLength);
217 UnicodeString skeletonString((UBool)(skeletonLength<0), skeleton, skeletonLength);
218 UnicodeString result=((DateTimePatternGenerator *)dtpg)->replaceFieldTypes(patternString, skeletonString, *pErrorCode);
219 return result.extract(dest, destCapacity, *pErrorCode);
220}
221
222U_DRAFT UEnumeration * U_EXPORT2
223udatpg_openSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) {
224 return uenum_openStringEnumeration(
225 ((DateTimePatternGenerator *)dtpg)->getSkeletons(*pErrorCode),
226 pErrorCode);
227}
228
229U_DRAFT UEnumeration * U_EXPORT2
230udatpg_openBaseSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) {
231 return uenum_openStringEnumeration(
232 ((DateTimePatternGenerator *)dtpg)->getBaseSkeletons(*pErrorCode),
233 pErrorCode);
234}
235
236U_DRAFT const UChar * U_EXPORT2
237udatpg_getPatternForSkeleton(const UDateTimePatternGenerator *dtpg,
238 const UChar *skeleton, int32_t skeletonLength,
239 int32_t *pLength) {
240 UnicodeString skeletonString((UBool)(skeletonLength<0), skeleton, skeletonLength);
241 const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getPatternForSkeleton(skeletonString);
242 if(pLength!=NULL) {
243 *pLength=result.length();
244 }
245 return result.getBuffer();
246}
247
248#endif