]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/ucsdet.cpp
2 ********************************************************************************
3 * Copyright (C) 2005-2016, 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 NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type))
25 #define DELETE_ARRAY(array) uprv_free((void *) (array))
29 U_CAPI UCharsetDetector
* U_EXPORT2
30 ucsdet_open(UErrorCode
*status
)
32 if(U_FAILURE(*status
)) {
36 CharsetDetector
* csd
= new CharsetDetector(*status
);
38 if (U_FAILURE(*status
)) {
43 return (UCharsetDetector
*) csd
;
47 ucsdet_close(UCharsetDetector
*ucsd
)
49 CharsetDetector
*csd
= (CharsetDetector
*) ucsd
;
54 ucsdet_setText(UCharsetDetector
*ucsd
, const char *textIn
, int32_t len
, UErrorCode
*status
)
56 if(U_FAILURE(*status
)) {
60 ((CharsetDetector
*) ucsd
)->setText(textIn
, len
);
63 U_CAPI
const char * U_EXPORT2
64 ucsdet_getName(const UCharsetMatch
*ucsm
, UErrorCode
*status
)
66 if(U_FAILURE(*status
)) {
70 return ((CharsetMatch
*) ucsm
)->getName();
73 U_CAPI
int32_t U_EXPORT2
74 ucsdet_getConfidence(const UCharsetMatch
*ucsm
, UErrorCode
*status
)
76 if(U_FAILURE(*status
)) {
80 return ((CharsetMatch
*) ucsm
)->getConfidence();
83 U_CAPI
const char * U_EXPORT2
84 ucsdet_getLanguage(const UCharsetMatch
*ucsm
, UErrorCode
*status
)
86 if(U_FAILURE(*status
)) {
90 return ((CharsetMatch
*) ucsm
)->getLanguage();
93 U_CAPI
const UCharsetMatch
* U_EXPORT2
94 ucsdet_detect(UCharsetDetector
*ucsd
, UErrorCode
*status
)
96 if(U_FAILURE(*status
)) {
100 return (const UCharsetMatch
*) ((CharsetDetector
*) ucsd
)->detect(*status
);
103 U_CAPI
void U_EXPORT2
104 ucsdet_setDeclaredEncoding(UCharsetDetector
*ucsd
, const char *encoding
, int32_t length
, UErrorCode
*status
)
106 if(U_FAILURE(*status
)) {
110 ((CharsetDetector
*) ucsd
)->setDeclaredEncoding(encoding
,length
);
113 U_CAPI
const UCharsetMatch
**
114 ucsdet_detectAll(UCharsetDetector
*ucsd
,
115 int32_t *maxMatchesFound
, UErrorCode
*status
)
117 if(U_FAILURE(*status
)) {
121 CharsetDetector
*csd
= (CharsetDetector
*) ucsd
;
123 return (const UCharsetMatch
**)csd
->detectAll(*maxMatchesFound
,*status
);
126 // U_CAPI const char * U_EXPORT2
127 // ucsdet_getDetectableCharsetName(const UCharsetDetector *csd, int32_t index, UErrorCode *status)
129 // if(U_FAILURE(*status)) {
132 // return csd->getCharsetName(index,*status);
135 // U_CAPI int32_t U_EXPORT2
136 // ucsdet_getDetectableCharsetsCount(const UCharsetDetector *csd, UErrorCode *status)
138 // if(U_FAILURE(*status)) {
141 // return UCharsetDetector::getDetectableCount();
144 U_CAPI UBool U_EXPORT2
145 ucsdet_isInputFilterEnabled(const UCharsetDetector
*ucsd
)
147 // todo: could use an error return...
152 return ((CharsetDetector
*) ucsd
)->getStripTagsFlag();
155 U_CAPI UBool U_EXPORT2
156 ucsdet_enableInputFilter(UCharsetDetector
*ucsd
, UBool filter
)
158 // todo: could use an error return...
163 CharsetDetector
*csd
= (CharsetDetector
*) ucsd
;
164 UBool prev
= csd
->getStripTagsFlag();
166 csd
->setStripTagsFlag(filter
);
171 U_CAPI
int32_t U_EXPORT2
172 ucsdet_getUChars(const UCharsetMatch
*ucsm
,
173 UChar
*buf
, int32_t cap
, UErrorCode
*status
)
175 if(U_FAILURE(*status
)) {
179 return ((CharsetMatch
*) ucsm
)->getUChars(buf
, cap
, status
);
182 U_CAPI
void U_EXPORT2
183 ucsdet_setDetectableCharset(UCharsetDetector
*ucsd
, const char *encoding
, UBool enabled
, UErrorCode
*status
)
185 ((CharsetDetector
*)ucsd
)->setDetectableCharset(encoding
, enabled
, *status
);
188 U_CAPI UEnumeration
* U_EXPORT2
189 ucsdet_getAllDetectableCharsets(const UCharsetDetector
* /*ucsd*/, UErrorCode
*status
)
191 return CharsetDetector::getAllDetectableCharsets(*status
);
194 U_DRAFT UEnumeration
* U_EXPORT2
195 ucsdet_getDetectableCharsets(const UCharsetDetector
*ucsd
, UErrorCode
*status
)
197 return ((CharsetDetector
*)ucsd
)->getDetectableCharsets(*status
);