]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/ucsdet.cpp
2 ********************************************************************************
3 * Copyright (C) 2005-2006, 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"
17 #define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
19 #define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type))
20 #define DELETE_ARRAY(array) uprv_free((void *) (array))
24 U_CAPI UCharsetDetector
* U_EXPORT2
25 ucsdet_open(UErrorCode
*status
)
27 if(U_FAILURE(*status
)) {
31 CharsetDetector
* csd
= new CharsetDetector(*status
);
33 if (U_FAILURE(*status
)) {
38 return (UCharsetDetector
*) csd
;
42 ucsdet_close(UCharsetDetector
*ucsd
)
44 CharsetDetector
*csd
= (CharsetDetector
*) ucsd
;
49 ucsdet_setText(UCharsetDetector
*ucsd
, const char *textIn
, int32_t len
, UErrorCode
*status
)
51 if(U_FAILURE(*status
)) {
56 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
60 CharsetDetector
*csd
= (CharsetDetector
*) ucsd
;
62 csd
->setText(textIn
, len
);
65 U_CAPI
const char * U_EXPORT2
66 ucsdet_getName(const UCharsetMatch
*ucsm
, UErrorCode
*status
)
68 if(U_FAILURE(*status
)) {
73 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
77 CharsetMatch
*csm
= (CharsetMatch
*) ucsm
;
79 return csm
->getName();
82 U_CAPI
int32_t U_EXPORT2
83 ucsdet_getConfidence(const UCharsetMatch
*ucsm
, UErrorCode
*status
)
85 if(U_FAILURE(*status
)) {
90 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
94 CharsetMatch
*csm
= (CharsetMatch
*) ucsm
;
96 return csm
->getConfidence();
99 U_CAPI
const char * U_EXPORT2
100 ucsdet_getLanguage(const UCharsetMatch
*ucsm
, UErrorCode
*status
)
102 if(U_FAILURE(*status
)) {
107 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
111 CharsetMatch
*csm
= (CharsetMatch
*) ucsm
;
113 return csm
->getLanguage();
116 U_CAPI
const UCharsetMatch
* U_EXPORT2
117 ucsdet_detect(UCharsetDetector
*ucsd
, UErrorCode
*status
)
119 if(U_FAILURE(*status
)) {
124 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
128 CharsetDetector
*csd
= (CharsetDetector
*) ucsd
;
130 return (const UCharsetMatch
*) csd
->detect(*status
);
133 U_CAPI
void U_EXPORT2
134 ucsdet_setDeclaredEncoding(UCharsetDetector
*ucsd
, const char *encoding
, int32_t length
, UErrorCode
*status
)
136 if(U_FAILURE(*status
)) {
141 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
145 CharsetDetector
*csd
= (CharsetDetector
*) ucsd
;
147 csd
->setDeclaredEncoding(encoding
,length
);
150 U_CAPI
const UCharsetMatch
**
151 ucsdet_detectAll(UCharsetDetector
*ucsd
,
152 int32_t *maxMatchesFound
, UErrorCode
*status
)
154 if(U_FAILURE(*status
)) {
159 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
163 CharsetDetector
*csd
= (CharsetDetector
*) ucsd
;
165 return (const UCharsetMatch
**)csd
->detectAll(*maxMatchesFound
,*status
);
168 // U_CAPI const char * U_EXPORT2
169 // ucsdet_getDetectableCharsetName(const UCharsetDetector *csd, int32_t index, UErrorCode *status)
171 // if(U_FAILURE(*status)) {
174 // return csd->getCharsetName(index,*status);
177 // U_CAPI int32_t U_EXPORT2
178 // ucsdet_getDetectableCharsetsCount(const UCharsetDetector *csd, UErrorCode *status)
180 // if(U_FAILURE(*status)) {
183 // return UCharsetDetector::getDetectableCount();
186 U_CAPI UBool U_EXPORT2
187 ucsdet_isInputFilterEnabled(const UCharsetDetector
*ucsd
)
189 // todo: could use an error return...
194 CharsetDetector
*csd
= (CharsetDetector
*) ucsd
;
196 return csd
->getStripTagsFlag();
199 U_CAPI UBool U_EXPORT2
200 ucsdet_enableInputFilter(UCharsetDetector
*ucsd
, UBool filter
)
202 // todo: could use an error return...
207 CharsetDetector
*csd
= (CharsetDetector
*) ucsd
;
208 UBool prev
= csd
->getStripTagsFlag();
210 csd
->setStripTagsFlag(filter
);
215 U_CAPI
int32_t U_EXPORT2
216 ucsdet_getUChars(const UCharsetMatch
*ucsm
,
217 UChar
*buf
, int32_t cap
, UErrorCode
*status
)
219 if(U_FAILURE(*status
)) {
224 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
228 CharsetMatch
*csm
= (CharsetMatch
*) ucsm
;
230 return csm
->getUChars(buf
, cap
, status
);