1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/udatpg.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,271 @@ 1.4 +/* 1.5 +******************************************************************************* 1.6 +* 1.7 +* Copyright (C) 2009-2012, International Business Machines 1.8 +* Corporation and others. All Rights Reserved. 1.9 +* 1.10 +******************************************************************************* 1.11 +* file name: udatpg.cpp 1.12 +* encoding: US-ASCII 1.13 +* tab size: 8 (not used) 1.14 +* indentation:4 1.15 +* 1.16 +* created on: 2007jul30 1.17 +* created by: Markus W. Scherer 1.18 +*/ 1.19 + 1.20 +#include "unicode/utypes.h" 1.21 + 1.22 +#if !UCONFIG_NO_FORMATTING 1.23 + 1.24 +#include "unicode/udatpg.h" 1.25 +#include "unicode/uenum.h" 1.26 +#include "unicode/strenum.h" 1.27 +#include "unicode/dtptngen.h" 1.28 +#include "ustrenum.h" 1.29 + 1.30 +U_NAMESPACE_USE 1.31 + 1.32 +U_CAPI UDateTimePatternGenerator * U_EXPORT2 1.33 +udatpg_open(const char *locale, UErrorCode *pErrorCode) { 1.34 + if(locale==NULL) { 1.35 + return (UDateTimePatternGenerator *)DateTimePatternGenerator::createInstance(*pErrorCode); 1.36 + } else { 1.37 + return (UDateTimePatternGenerator *)DateTimePatternGenerator::createInstance(Locale(locale), *pErrorCode); 1.38 + } 1.39 +} 1.40 + 1.41 +U_CAPI UDateTimePatternGenerator * U_EXPORT2 1.42 +udatpg_openEmpty(UErrorCode *pErrorCode) { 1.43 + return (UDateTimePatternGenerator *)DateTimePatternGenerator::createEmptyInstance(*pErrorCode); 1.44 +} 1.45 + 1.46 +U_CAPI void U_EXPORT2 1.47 +udatpg_close(UDateTimePatternGenerator *dtpg) { 1.48 + delete (DateTimePatternGenerator *)dtpg; 1.49 +} 1.50 + 1.51 +U_CAPI UDateTimePatternGenerator * U_EXPORT2 1.52 +udatpg_clone(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) { 1.53 + if(U_FAILURE(*pErrorCode)) { 1.54 + return NULL; 1.55 + } 1.56 + return (UDateTimePatternGenerator *)(((const DateTimePatternGenerator *)dtpg)->clone()); 1.57 +} 1.58 + 1.59 +U_CAPI int32_t U_EXPORT2 1.60 +udatpg_getBestPattern(UDateTimePatternGenerator *dtpg, 1.61 + const UChar *skeleton, int32_t length, 1.62 + UChar *bestPattern, int32_t capacity, 1.63 + UErrorCode *pErrorCode) { 1.64 + return udatpg_getBestPatternWithOptions(dtpg, skeleton, length, 1.65 + UDATPG_MATCH_NO_OPTIONS, 1.66 + bestPattern, capacity, pErrorCode); 1.67 +} 1.68 + 1.69 +U_CAPI int32_t U_EXPORT2 1.70 +udatpg_getBestPatternWithOptions(UDateTimePatternGenerator *dtpg, 1.71 + const UChar *skeleton, int32_t length, 1.72 + UDateTimePatternMatchOptions options, 1.73 + UChar *bestPattern, int32_t capacity, 1.74 + UErrorCode *pErrorCode) { 1.75 + if(U_FAILURE(*pErrorCode)) { 1.76 + return 0; 1.77 + } 1.78 + if(skeleton==NULL && length!=0) { 1.79 + *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; 1.80 + return 0; 1.81 + } 1.82 + UnicodeString skeletonString((UBool)(length<0), skeleton, length); 1.83 + UnicodeString result=((DateTimePatternGenerator *)dtpg)->getBestPattern(skeletonString, options, *pErrorCode); 1.84 + return result.extract(bestPattern, capacity, *pErrorCode); 1.85 +} 1.86 + 1.87 +U_CAPI int32_t U_EXPORT2 1.88 +udatpg_getSkeleton(UDateTimePatternGenerator *dtpg, 1.89 + const UChar *pattern, int32_t length, 1.90 + UChar *skeleton, int32_t capacity, 1.91 + UErrorCode *pErrorCode) { 1.92 + if(U_FAILURE(*pErrorCode)) { 1.93 + return 0; 1.94 + } 1.95 + if(pattern==NULL && length!=0) { 1.96 + *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; 1.97 + return 0; 1.98 + } 1.99 + UnicodeString patternString((UBool)(length<0), pattern, length); 1.100 + UnicodeString result=((DateTimePatternGenerator *)dtpg)->getSkeleton(patternString, *pErrorCode); 1.101 + return result.extract(skeleton, capacity, *pErrorCode); 1.102 +} 1.103 + 1.104 +U_CAPI int32_t U_EXPORT2 1.105 +udatpg_getBaseSkeleton(UDateTimePatternGenerator *dtpg, 1.106 + const UChar *pattern, int32_t length, 1.107 + UChar *skeleton, int32_t capacity, 1.108 + UErrorCode *pErrorCode) { 1.109 + if(U_FAILURE(*pErrorCode)) { 1.110 + return 0; 1.111 + } 1.112 + if(pattern==NULL && length!=0) { 1.113 + *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; 1.114 + return 0; 1.115 + } 1.116 + UnicodeString patternString((UBool)(length<0), pattern, length); 1.117 + UnicodeString result=((DateTimePatternGenerator *)dtpg)->getBaseSkeleton(patternString, *pErrorCode); 1.118 + return result.extract(skeleton, capacity, *pErrorCode); 1.119 +} 1.120 + 1.121 +U_CAPI UDateTimePatternConflict U_EXPORT2 1.122 +udatpg_addPattern(UDateTimePatternGenerator *dtpg, 1.123 + const UChar *pattern, int32_t patternLength, 1.124 + UBool override, 1.125 + UChar *conflictingPattern, int32_t capacity, int32_t *pLength, 1.126 + UErrorCode *pErrorCode) { 1.127 + if(U_FAILURE(*pErrorCode)) { 1.128 + return UDATPG_NO_CONFLICT; 1.129 + } 1.130 + if(pattern==NULL && patternLength!=0) { 1.131 + *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; 1.132 + return UDATPG_NO_CONFLICT; 1.133 + } 1.134 + UnicodeString patternString((UBool)(patternLength<0), pattern, patternLength); 1.135 + UnicodeString conflictingPatternString; 1.136 + UDateTimePatternConflict result=((DateTimePatternGenerator *)dtpg)-> 1.137 + addPattern(patternString, override, conflictingPatternString, *pErrorCode); 1.138 + int32_t length=conflictingPatternString.extract(conflictingPattern, capacity, *pErrorCode); 1.139 + if(pLength!=NULL) { 1.140 + *pLength=length; 1.141 + } 1.142 + return result; 1.143 +} 1.144 + 1.145 +U_CAPI void U_EXPORT2 1.146 +udatpg_setAppendItemFormat(UDateTimePatternGenerator *dtpg, 1.147 + UDateTimePatternField field, 1.148 + const UChar *value, int32_t length) { 1.149 + UnicodeString valueString((UBool)(length<0), value, length); 1.150 + ((DateTimePatternGenerator *)dtpg)->setAppendItemFormat(field, valueString); 1.151 +} 1.152 + 1.153 +U_CAPI const UChar * U_EXPORT2 1.154 +udatpg_getAppendItemFormat(const UDateTimePatternGenerator *dtpg, 1.155 + UDateTimePatternField field, 1.156 + int32_t *pLength) { 1.157 + const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getAppendItemFormat(field); 1.158 + if(pLength!=NULL) { 1.159 + *pLength=result.length(); 1.160 + } 1.161 + return result.getBuffer(); 1.162 +} 1.163 + 1.164 +U_CAPI void U_EXPORT2 1.165 +udatpg_setAppendItemName(UDateTimePatternGenerator *dtpg, 1.166 + UDateTimePatternField field, 1.167 + const UChar *value, int32_t length) { 1.168 + UnicodeString valueString((UBool)(length<0), value, length); 1.169 + ((DateTimePatternGenerator *)dtpg)->setAppendItemName(field, valueString); 1.170 +} 1.171 + 1.172 +U_CAPI const UChar * U_EXPORT2 1.173 +udatpg_getAppendItemName(const UDateTimePatternGenerator *dtpg, 1.174 + UDateTimePatternField field, 1.175 + int32_t *pLength) { 1.176 + const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getAppendItemName(field); 1.177 + if(pLength!=NULL) { 1.178 + *pLength=result.length(); 1.179 + } 1.180 + return result.getBuffer(); 1.181 +} 1.182 + 1.183 +U_CAPI void U_EXPORT2 1.184 +udatpg_setDateTimeFormat(const UDateTimePatternGenerator *dtpg, 1.185 + const UChar *dtFormat, int32_t length) { 1.186 + UnicodeString dtFormatString((UBool)(length<0), dtFormat, length); 1.187 + ((DateTimePatternGenerator *)dtpg)->setDateTimeFormat(dtFormatString); 1.188 +} 1.189 + 1.190 +U_CAPI const UChar * U_EXPORT2 1.191 +udatpg_getDateTimeFormat(const UDateTimePatternGenerator *dtpg, 1.192 + int32_t *pLength) { 1.193 + const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getDateTimeFormat(); 1.194 + if(pLength!=NULL) { 1.195 + *pLength=result.length(); 1.196 + } 1.197 + return result.getBuffer(); 1.198 +} 1.199 + 1.200 +U_CAPI void U_EXPORT2 1.201 +udatpg_setDecimal(UDateTimePatternGenerator *dtpg, 1.202 + const UChar *decimal, int32_t length) { 1.203 + UnicodeString decimalString((UBool)(length<0), decimal, length); 1.204 + ((DateTimePatternGenerator *)dtpg)->setDecimal(decimalString); 1.205 +} 1.206 + 1.207 +U_CAPI const UChar * U_EXPORT2 1.208 +udatpg_getDecimal(const UDateTimePatternGenerator *dtpg, 1.209 + int32_t *pLength) { 1.210 + const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getDecimal(); 1.211 + if(pLength!=NULL) { 1.212 + *pLength=result.length(); 1.213 + } 1.214 + return result.getBuffer(); 1.215 +} 1.216 + 1.217 +U_CAPI int32_t U_EXPORT2 1.218 +udatpg_replaceFieldTypes(UDateTimePatternGenerator *dtpg, 1.219 + const UChar *pattern, int32_t patternLength, 1.220 + const UChar *skeleton, int32_t skeletonLength, 1.221 + UChar *dest, int32_t destCapacity, 1.222 + UErrorCode *pErrorCode) { 1.223 + return udatpg_replaceFieldTypesWithOptions(dtpg, pattern, patternLength, skeleton, skeletonLength, 1.224 + UDATPG_MATCH_NO_OPTIONS, 1.225 + dest, destCapacity, pErrorCode); 1.226 +} 1.227 + 1.228 +U_CAPI int32_t U_EXPORT2 1.229 +udatpg_replaceFieldTypesWithOptions(UDateTimePatternGenerator *dtpg, 1.230 + const UChar *pattern, int32_t patternLength, 1.231 + const UChar *skeleton, int32_t skeletonLength, 1.232 + UDateTimePatternMatchOptions options, 1.233 + UChar *dest, int32_t destCapacity, 1.234 + UErrorCode *pErrorCode) { 1.235 + if(U_FAILURE(*pErrorCode)) { 1.236 + return 0; 1.237 + } 1.238 + if((pattern==NULL && patternLength!=0) || (skeleton==NULL && skeletonLength!=0)) { 1.239 + *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; 1.240 + return 0; 1.241 + } 1.242 + UnicodeString patternString((UBool)(patternLength<0), pattern, patternLength); 1.243 + UnicodeString skeletonString((UBool)(skeletonLength<0), skeleton, skeletonLength); 1.244 + UnicodeString result=((DateTimePatternGenerator *)dtpg)->replaceFieldTypes(patternString, skeletonString, options, *pErrorCode); 1.245 + return result.extract(dest, destCapacity, *pErrorCode); 1.246 +} 1.247 + 1.248 +U_CAPI UEnumeration * U_EXPORT2 1.249 +udatpg_openSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) { 1.250 + return uenum_openFromStringEnumeration( 1.251 + ((DateTimePatternGenerator *)dtpg)->getSkeletons(*pErrorCode), 1.252 + pErrorCode); 1.253 +} 1.254 + 1.255 +U_CAPI UEnumeration * U_EXPORT2 1.256 +udatpg_openBaseSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) { 1.257 + return uenum_openFromStringEnumeration( 1.258 + ((DateTimePatternGenerator *)dtpg)->getBaseSkeletons(*pErrorCode), 1.259 + pErrorCode); 1.260 +} 1.261 + 1.262 +U_CAPI const UChar * U_EXPORT2 1.263 +udatpg_getPatternForSkeleton(const UDateTimePatternGenerator *dtpg, 1.264 + const UChar *skeleton, int32_t skeletonLength, 1.265 + int32_t *pLength) { 1.266 + UnicodeString skeletonString((UBool)(skeletonLength<0), skeleton, skeletonLength); 1.267 + const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getPatternForSkeleton(skeletonString); 1.268 + if(pLength!=NULL) { 1.269 + *pLength=result.length(); 1.270 + } 1.271 + return result.getBuffer(); 1.272 +} 1.273 + 1.274 +#endif