2 ********************************************************************************
3 * Copyright (C) 2005-2013, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************************
8 #include "unicode/utypes.h"
10 #if !UCONFIG_NO_CONVERSION
11 #include "unicode/ucsdet.h"
24 #define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
26 #define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type))
27 #define DELETE_ARRAY(array) uprv_free((void *) (array))
31 U_CAPI UCharsetDetector * U_EXPORT2
32 ucsdet_open(UErrorCode *status)
34 if(U_FAILURE(*status)) {
38 CharsetDetector* csd = new CharsetDetector(*status);
40 if (U_FAILURE(*status)) {
45 return (UCharsetDetector *) csd;
49 ucsdet_close(UCharsetDetector *ucsd)
51 CharsetDetector *csd = (CharsetDetector *) ucsd;
56 ucsdet_setText(UCharsetDetector *ucsd, const char *textIn, int32_t len, UErrorCode *status)
58 if(U_FAILURE(*status)) {
62 ((CharsetDetector *) ucsd)->setText(textIn, len);
65 U_CAPI const char * U_EXPORT2
66 ucsdet_getName(const UCharsetMatch *ucsm, UErrorCode *status)
68 if(U_FAILURE(*status)) {
72 return ((CharsetMatch *) ucsm)->getName();
75 U_CAPI int32_t U_EXPORT2
76 ucsdet_getConfidence(const UCharsetMatch *ucsm, UErrorCode *status)
78 if(U_FAILURE(*status)) {
82 return ((CharsetMatch *) ucsm)->getConfidence();
85 U_CAPI const char * U_EXPORT2
86 ucsdet_getLanguage(const UCharsetMatch *ucsm, UErrorCode *status)
88 if(U_FAILURE(*status)) {
92 return ((CharsetMatch *) ucsm)->getLanguage();
95 U_CAPI const UCharsetMatch * U_EXPORT2
96 ucsdet_detect(UCharsetDetector *ucsd, UErrorCode *status)
98 if(U_FAILURE(*status)) {
102 return (const UCharsetMatch *) ((CharsetDetector *) ucsd)->detect(*status);
105 U_CAPI void U_EXPORT2
106 ucsdet_setDeclaredEncoding(UCharsetDetector *ucsd, const char *encoding, int32_t length, UErrorCode *status)
108 if(U_FAILURE(*status)) {
112 ((CharsetDetector *) ucsd)->setDeclaredEncoding(encoding,length);
115 U_CAPI const UCharsetMatch**
116 ucsdet_detectAll(UCharsetDetector *ucsd,
117 int32_t *maxMatchesFound, UErrorCode *status)
119 if(U_FAILURE(*status)) {
123 CharsetDetector *csd = (CharsetDetector *) ucsd;
125 return (const UCharsetMatch**)csd->detectAll(*maxMatchesFound,*status);
128 // U_CAPI const char * U_EXPORT2
129 // ucsdet_getDetectableCharsetName(const UCharsetDetector *csd, int32_t index, UErrorCode *status)
131 // if(U_FAILURE(*status)) {
134 // return csd->getCharsetName(index,*status);
137 // U_CAPI int32_t U_EXPORT2
138 // ucsdet_getDetectableCharsetsCount(const UCharsetDetector *csd, UErrorCode *status)
140 // if(U_FAILURE(*status)) {
143 // return UCharsetDetector::getDetectableCount();
146 U_CAPI UBool U_EXPORT2
147 ucsdet_isInputFilterEnabled(const UCharsetDetector *ucsd)
149 // todo: could use an error return...
154 return ((CharsetDetector *) ucsd)->getStripTagsFlag();
157 U_CAPI UBool U_EXPORT2
158 ucsdet_enableInputFilter(UCharsetDetector *ucsd, UBool filter)
160 // todo: could use an error return...
165 CharsetDetector *csd = (CharsetDetector *) ucsd;
166 UBool prev = csd->getStripTagsFlag();
168 csd->setStripTagsFlag(filter);
173 U_CAPI int32_t U_EXPORT2
174 ucsdet_getUChars(const UCharsetMatch *ucsm,
175 UChar *buf, int32_t cap, UErrorCode *status)
177 if(U_FAILURE(*status)) {
181 return ((CharsetMatch *) ucsm)->getUChars(buf, cap, status);
184 U_CAPI void U_EXPORT2
185 ucsdet_setDetectableCharset(UCharsetDetector *ucsd, const char *encoding, UBool enabled, UErrorCode *status)
187 ((CharsetDetector *)ucsd)->setDetectableCharset(encoding, enabled, *status);
190 U_CAPI UEnumeration * U_EXPORT2
191 ucsdet_getAllDetectableCharsets(const UCharsetDetector * /*ucsd*/, UErrorCode *status)
193 return CharsetDetector::getAllDetectableCharsets(*status);
196 U_DRAFT UEnumeration * U_EXPORT2
197 ucsdet_getDetectableCharsets(const UCharsetDetector *ucsd, UErrorCode *status)
199 return ((CharsetDetector *)ucsd)->getDetectableCharsets(*status);