]>
Commit | Line | Data |
---|---|---|
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 | ||
27 | U_NAMESPACE_USE | |
28 | ||
29 | U_DRAFT UDateTimePatternGenerator * U_EXPORT2 | |
30 | udatpg_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 | ||
38 | U_DRAFT UDateTimePatternGenerator * U_EXPORT2 | |
39 | udatpg_openEmpty(UErrorCode *pErrorCode) { | |
40 | return (UDateTimePatternGenerator *)DateTimePatternGenerator::createEmptyInstance(*pErrorCode); | |
41 | } | |
42 | ||
43 | U_DRAFT void U_EXPORT2 | |
44 | udatpg_close(UDateTimePatternGenerator *dtpg) { | |
45 | delete (DateTimePatternGenerator *)dtpg; | |
46 | } | |
47 | ||
48 | U_DRAFT UDateTimePatternGenerator * U_EXPORT2 | |
49 | udatpg_clone(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) { | |
50 | if(U_FAILURE(*pErrorCode)) { | |
51 | return NULL; | |
52 | } | |
53 | return (UDateTimePatternGenerator *)(((const DateTimePatternGenerator *)dtpg)->clone()); | |
54 | } | |
55 | ||
56 | U_DRAFT int32_t U_EXPORT2 | |
57 | udatpg_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 | ||
73 | U_DRAFT int32_t U_EXPORT2 | |
74 | udatpg_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 | ||
90 | U_DRAFT int32_t U_EXPORT2 | |
91 | udatpg_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 | ||
107 | U_DRAFT UDateTimePatternConflict U_EXPORT2 | |
108 | udatpg_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 | ||
131 | U_DRAFT void U_EXPORT2 | |
132 | udatpg_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 | ||
139 | U_DRAFT const UChar * U_EXPORT2 | |
140 | udatpg_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 | ||
150 | U_DRAFT void U_EXPORT2 | |
151 | udatpg_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 | ||
158 | U_DRAFT const UChar * U_EXPORT2 | |
159 | udatpg_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 | ||
169 | U_DRAFT void U_EXPORT2 | |
170 | udatpg_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 | ||
176 | U_DRAFT const UChar * U_EXPORT2 | |
177 | udatpg_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 | ||
186 | U_DRAFT void U_EXPORT2 | |
187 | udatpg_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 | ||
193 | U_DRAFT const UChar * U_EXPORT2 | |
194 | udatpg_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 | ||
203 | U_DRAFT int32_t U_EXPORT2 | |
204 | udatpg_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 | ||
222 | U_DRAFT UEnumeration * U_EXPORT2 | |
223 | udatpg_openSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) { | |
224 | return uenum_openStringEnumeration( | |
225 | ((DateTimePatternGenerator *)dtpg)->getSkeletons(*pErrorCode), | |
226 | pErrorCode); | |
227 | } | |
228 | ||
229 | U_DRAFT UEnumeration * U_EXPORT2 | |
230 | udatpg_openBaseSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) { | |
231 | return uenum_openStringEnumeration( | |
232 | ((DateTimePatternGenerator *)dtpg)->getBaseSkeletons(*pErrorCode), | |
233 | pErrorCode); | |
234 | } | |
235 | ||
236 | U_DRAFT const UChar * U_EXPORT2 | |
237 | udatpg_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 |