2 *******************************************************************************
4 * Copyright (C) 2007, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: udatpg.cpp
10 * tab size: 8 (not used)
13 * created on: 2007jul30
14 * created by: Markus W. Scherer
17 #include "unicode/utypes.h"
19 #if !UCONFIG_NO_FORMATTING
21 #include "unicode/udatpg.h"
22 #include "unicode/uenum.h"
23 #include "unicode/strenum.h"
24 #include "unicode/dtptngen.h"
29 U_DRAFT UDateTimePatternGenerator
* U_EXPORT2
30 udatpg_open(const char *locale
, UErrorCode
*pErrorCode
) {
32 return (UDateTimePatternGenerator
*)DateTimePatternGenerator::createInstance(*pErrorCode
);
34 return (UDateTimePatternGenerator
*)DateTimePatternGenerator::createInstance(Locale(locale
), *pErrorCode
);
38 U_DRAFT UDateTimePatternGenerator
* U_EXPORT2
39 udatpg_openEmpty(UErrorCode
*pErrorCode
) {
40 return (UDateTimePatternGenerator
*)DateTimePatternGenerator::createEmptyInstance(*pErrorCode
);
43 U_DRAFT
void U_EXPORT2
44 udatpg_close(UDateTimePatternGenerator
*dtpg
) {
45 delete (DateTimePatternGenerator
*)dtpg
;
48 U_DRAFT UDateTimePatternGenerator
* U_EXPORT2
49 udatpg_clone(const UDateTimePatternGenerator
*dtpg
, UErrorCode
*pErrorCode
) {
50 if(U_FAILURE(*pErrorCode
)) {
53 return (UDateTimePatternGenerator
*)(((const DateTimePatternGenerator
*)dtpg
)->clone());
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
)) {
64 if(skeleton
==NULL
&& length
!=0) {
65 *pErrorCode
=U_ILLEGAL_ARGUMENT_ERROR
;
68 UnicodeString
skeletonString((UBool
)(length
<0), skeleton
, length
);
69 UnicodeString result
=((DateTimePatternGenerator
*)dtpg
)->getBestPattern(skeletonString
, *pErrorCode
);
70 return result
.extract(bestPattern
, capacity
, *pErrorCode
);
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
)) {
81 if(pattern
==NULL
&& length
!=0) {
82 *pErrorCode
=U_ILLEGAL_ARGUMENT_ERROR
;
85 UnicodeString
patternString((UBool
)(length
<0), pattern
, length
);
86 UnicodeString result
=((DateTimePatternGenerator
*)dtpg
)->getSkeleton(patternString
, *pErrorCode
);
87 return result
.extract(skeleton
, capacity
, *pErrorCode
);
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
)) {
98 if(pattern
==NULL
&& length
!=0) {
99 *pErrorCode
=U_ILLEGAL_ARGUMENT_ERROR
;
102 UnicodeString
patternString((UBool
)(length
<0), pattern
, length
);
103 UnicodeString result
=((DateTimePatternGenerator
*)dtpg
)->getBaseSkeleton(patternString
, *pErrorCode
);
104 return result
.extract(skeleton
, capacity
, *pErrorCode
);
107 U_DRAFT UDateTimePatternConflict U_EXPORT2
108 udatpg_addPattern(UDateTimePatternGenerator
*dtpg
,
109 const UChar
*pattern
, int32_t patternLength
,
111 UChar
*conflictingPattern
, int32_t capacity
, int32_t *pLength
,
112 UErrorCode
*pErrorCode
) {
113 if(U_FAILURE(*pErrorCode
)) {
114 return UDATPG_NO_CONFLICT
;
116 if(pattern
==NULL
&& patternLength
!=0) {
117 *pErrorCode
=U_ILLEGAL_ARGUMENT_ERROR
;
118 return UDATPG_NO_CONFLICT
;
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
);
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
);
139 U_DRAFT
const UChar
* U_EXPORT2
140 udatpg_getAppendItemFormat(const UDateTimePatternGenerator
*dtpg
,
141 UDateTimePatternField field
,
143 const UnicodeString
&result
=((const DateTimePatternGenerator
*)dtpg
)->getAppendItemFormat(field
);
145 *pLength
=result
.length();
147 return result
.getBuffer();
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
);
158 U_DRAFT
const UChar
* U_EXPORT2
159 udatpg_getAppendItemName(const UDateTimePatternGenerator
*dtpg
,
160 UDateTimePatternField field
,
162 const UnicodeString
&result
=((const DateTimePatternGenerator
*)dtpg
)->getAppendItemName(field
);
164 *pLength
=result
.length();
166 return result
.getBuffer();
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
);
176 U_DRAFT
const UChar
* U_EXPORT2
177 udatpg_getDateTimeFormat(const UDateTimePatternGenerator
*dtpg
,
179 const UnicodeString
&result
=((const DateTimePatternGenerator
*)dtpg
)->getDateTimeFormat();
181 *pLength
=result
.length();
183 return result
.getBuffer();
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
);
193 U_DRAFT
const UChar
* U_EXPORT2
194 udatpg_getDecimal(const UDateTimePatternGenerator
*dtpg
,
196 const UnicodeString
&result
=((const DateTimePatternGenerator
*)dtpg
)->getDecimal();
198 *pLength
=result
.length();
200 return result
.getBuffer();
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
)) {
212 if((pattern
==NULL
&& patternLength
!=0) || (skeleton
==NULL
&& skeletonLength
!=0)) {
213 *pErrorCode
=U_ILLEGAL_ARGUMENT_ERROR
;
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
);
222 U_DRAFT UEnumeration
* U_EXPORT2
223 udatpg_openSkeletons(const UDateTimePatternGenerator
*dtpg
, UErrorCode
*pErrorCode
) {
224 return uenum_openStringEnumeration(
225 ((DateTimePatternGenerator
*)dtpg
)->getSkeletons(*pErrorCode
),
229 U_DRAFT UEnumeration
* U_EXPORT2
230 udatpg_openBaseSkeletons(const UDateTimePatternGenerator
*dtpg
, UErrorCode
*pErrorCode
) {
231 return uenum_openStringEnumeration(
232 ((DateTimePatternGenerator
*)dtpg
)->getBaseSkeletons(*pErrorCode
),
236 U_DRAFT
const UChar
* U_EXPORT2
237 udatpg_getPatternForSkeleton(const UDateTimePatternGenerator
*dtpg
,
238 const UChar
*skeleton
, int32_t skeletonLength
,
240 UnicodeString
skeletonString((UBool
)(skeletonLength
<0), skeleton
, skeletonLength
);
241 const UnicodeString
&result
=((const DateTimePatternGenerator
*)dtpg
)->getPatternForSkeleton(skeletonString
);
243 *pLength
=result
.length();
245 return result
.getBuffer();