]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/ucsdet.cpp
2 ********************************************************************************
3 * Copyright (C) 2005-2007, 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"
19 #define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
21 #define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type))
22 #define DELETE_ARRAY(array) uprv_free((void *) (array))
26 U_CAPI UCharsetDetector
* U_EXPORT2
27 ucsdet_open(UErrorCode
*status
)
29 if(U_FAILURE(*status
)) {
33 CharsetDetector
* csd
= new CharsetDetector(*status
);
35 if (U_FAILURE(*status
)) {
40 return (UCharsetDetector
*) csd
;
44 ucsdet_close(UCharsetDetector
*ucsd
)
46 CharsetDetector
*csd
= (CharsetDetector
*) ucsd
;
51 ucsdet_setText(UCharsetDetector
*ucsd
, const char *textIn
, int32_t len
, UErrorCode
*status
)
53 if(U_FAILURE(*status
)) {
57 ((CharsetDetector
*) ucsd
)->setText(textIn
, len
);
60 U_CAPI
const char * U_EXPORT2
61 ucsdet_getName(const UCharsetMatch
*ucsm
, UErrorCode
*status
)
63 if(U_FAILURE(*status
)) {
67 return ((CharsetMatch
*) ucsm
)->getName();
70 U_CAPI
int32_t U_EXPORT2
71 ucsdet_getConfidence(const UCharsetMatch
*ucsm
, UErrorCode
*status
)
73 if(U_FAILURE(*status
)) {
77 return ((CharsetMatch
*) ucsm
)->getConfidence();
80 U_CAPI
const char * U_EXPORT2
81 ucsdet_getLanguage(const UCharsetMatch
*ucsm
, UErrorCode
*status
)
83 if(U_FAILURE(*status
)) {
87 return ((CharsetMatch
*) ucsm
)->getLanguage();
90 U_CAPI
const UCharsetMatch
* U_EXPORT2
91 ucsdet_detect(UCharsetDetector
*ucsd
, UErrorCode
*status
)
93 if(U_FAILURE(*status
)) {
97 return (const UCharsetMatch
*) ((CharsetDetector
*) ucsd
)->detect(*status
);
100 U_CAPI
void U_EXPORT2
101 ucsdet_setDeclaredEncoding(UCharsetDetector
*ucsd
, const char *encoding
, int32_t length
, UErrorCode
*status
)
103 if(U_FAILURE(*status
)) {
107 ((CharsetDetector
*) ucsd
)->setDeclaredEncoding(encoding
,length
);
110 U_CAPI
const UCharsetMatch
**
111 ucsdet_detectAll(UCharsetDetector
*ucsd
,
112 int32_t *maxMatchesFound
, UErrorCode
*status
)
114 if(U_FAILURE(*status
)) {
118 CharsetDetector
*csd
= (CharsetDetector
*) ucsd
;
120 return (const UCharsetMatch
**)csd
->detectAll(*maxMatchesFound
,*status
);
123 // U_CAPI const char * U_EXPORT2
124 // ucsdet_getDetectableCharsetName(const UCharsetDetector *csd, int32_t index, UErrorCode *status)
126 // if(U_FAILURE(*status)) {
129 // return csd->getCharsetName(index,*status);
132 // U_CAPI int32_t U_EXPORT2
133 // ucsdet_getDetectableCharsetsCount(const UCharsetDetector *csd, UErrorCode *status)
135 // if(U_FAILURE(*status)) {
138 // return UCharsetDetector::getDetectableCount();
141 U_CAPI UBool U_EXPORT2
142 ucsdet_isInputFilterEnabled(const UCharsetDetector
*ucsd
)
144 // todo: could use an error return...
149 return ((CharsetDetector
*) ucsd
)->getStripTagsFlag();
152 U_CAPI UBool U_EXPORT2
153 ucsdet_enableInputFilter(UCharsetDetector
*ucsd
, UBool filter
)
155 // todo: could use an error return...
160 CharsetDetector
*csd
= (CharsetDetector
*) ucsd
;
161 UBool prev
= csd
->getStripTagsFlag();
163 csd
->setStripTagsFlag(filter
);
168 U_CAPI
int32_t U_EXPORT2
169 ucsdet_getUChars(const UCharsetMatch
*ucsm
,
170 UChar
*buf
, int32_t cap
, UErrorCode
*status
)
172 if(U_FAILURE(*status
)) {
176 return ((CharsetMatch
*) ucsm
)->getUChars(buf
, cap
, status
);