michael@0: /* michael@0: ******************************************************************************** michael@0: * Copyright (C) 2005-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ******************************************************************************** michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_CONVERSION michael@0: #include "unicode/ucsdet.h" michael@0: #include "csdetect.h" michael@0: #include "csmatch.h" michael@0: #include "csrsbcs.h" michael@0: #include "csrmbcs.h" michael@0: #include "csrutf8.h" michael@0: #include "csrucode.h" michael@0: #include "csr2022.h" michael@0: michael@0: #include "cmemory.h" michael@0: michael@0: U_NAMESPACE_USE michael@0: michael@0: #define ARRAY_SIZE(array) (sizeof array / sizeof array[0]) michael@0: michael@0: #define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type)) michael@0: #define DELETE_ARRAY(array) uprv_free((void *) (array)) michael@0: michael@0: U_CDECL_BEGIN michael@0: michael@0: U_CAPI UCharsetDetector * U_EXPORT2 michael@0: ucsdet_open(UErrorCode *status) michael@0: { michael@0: if(U_FAILURE(*status)) { michael@0: return 0; michael@0: } michael@0: michael@0: CharsetDetector* csd = new CharsetDetector(*status); michael@0: michael@0: if (U_FAILURE(*status)) { michael@0: delete csd; michael@0: csd = NULL; michael@0: } michael@0: michael@0: return (UCharsetDetector *) csd; michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: ucsdet_close(UCharsetDetector *ucsd) michael@0: { michael@0: CharsetDetector *csd = (CharsetDetector *) ucsd; michael@0: delete csd; michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: ucsdet_setText(UCharsetDetector *ucsd, const char *textIn, int32_t len, UErrorCode *status) michael@0: { michael@0: if(U_FAILURE(*status)) { michael@0: return; michael@0: } michael@0: michael@0: ((CharsetDetector *) ucsd)->setText(textIn, len); michael@0: } michael@0: michael@0: U_CAPI const char * U_EXPORT2 michael@0: ucsdet_getName(const UCharsetMatch *ucsm, UErrorCode *status) michael@0: { michael@0: if(U_FAILURE(*status)) { michael@0: return NULL; michael@0: } michael@0: michael@0: return ((CharsetMatch *) ucsm)->getName(); michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: ucsdet_getConfidence(const UCharsetMatch *ucsm, UErrorCode *status) michael@0: { michael@0: if(U_FAILURE(*status)) { michael@0: return 0; michael@0: } michael@0: michael@0: return ((CharsetMatch *) ucsm)->getConfidence(); michael@0: } michael@0: michael@0: U_CAPI const char * U_EXPORT2 michael@0: ucsdet_getLanguage(const UCharsetMatch *ucsm, UErrorCode *status) michael@0: { michael@0: if(U_FAILURE(*status)) { michael@0: return NULL; michael@0: } michael@0: michael@0: return ((CharsetMatch *) ucsm)->getLanguage(); michael@0: } michael@0: michael@0: U_CAPI const UCharsetMatch * U_EXPORT2 michael@0: ucsdet_detect(UCharsetDetector *ucsd, UErrorCode *status) michael@0: { michael@0: if(U_FAILURE(*status)) { michael@0: return NULL; michael@0: } michael@0: michael@0: return (const UCharsetMatch *) ((CharsetDetector *) ucsd)->detect(*status); michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: ucsdet_setDeclaredEncoding(UCharsetDetector *ucsd, const char *encoding, int32_t length, UErrorCode *status) michael@0: { michael@0: if(U_FAILURE(*status)) { michael@0: return; michael@0: } michael@0: michael@0: ((CharsetDetector *) ucsd)->setDeclaredEncoding(encoding,length); michael@0: } michael@0: michael@0: U_CAPI const UCharsetMatch** michael@0: ucsdet_detectAll(UCharsetDetector *ucsd, michael@0: int32_t *maxMatchesFound, UErrorCode *status) michael@0: { michael@0: if(U_FAILURE(*status)) { michael@0: return NULL; michael@0: } michael@0: michael@0: CharsetDetector *csd = (CharsetDetector *) ucsd; michael@0: michael@0: return (const UCharsetMatch**)csd->detectAll(*maxMatchesFound,*status); michael@0: } michael@0: michael@0: // U_CAPI const char * U_EXPORT2 michael@0: // ucsdet_getDetectableCharsetName(const UCharsetDetector *csd, int32_t index, UErrorCode *status) michael@0: // { michael@0: // if(U_FAILURE(*status)) { michael@0: // return 0; michael@0: // } michael@0: // return csd->getCharsetName(index,*status); michael@0: // } michael@0: michael@0: // U_CAPI int32_t U_EXPORT2 michael@0: // ucsdet_getDetectableCharsetsCount(const UCharsetDetector *csd, UErrorCode *status) michael@0: // { michael@0: // if(U_FAILURE(*status)) { michael@0: // return -1; michael@0: // } michael@0: // return UCharsetDetector::getDetectableCount(); michael@0: // } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: ucsdet_isInputFilterEnabled(const UCharsetDetector *ucsd) michael@0: { michael@0: // todo: could use an error return... michael@0: if (ucsd == NULL) { michael@0: return FALSE; michael@0: } michael@0: michael@0: return ((CharsetDetector *) ucsd)->getStripTagsFlag(); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: ucsdet_enableInputFilter(UCharsetDetector *ucsd, UBool filter) michael@0: { michael@0: // todo: could use an error return... michael@0: if (ucsd == NULL) { michael@0: return FALSE; michael@0: } michael@0: michael@0: CharsetDetector *csd = (CharsetDetector *) ucsd; michael@0: UBool prev = csd->getStripTagsFlag(); michael@0: michael@0: csd->setStripTagsFlag(filter); michael@0: michael@0: return prev; michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: ucsdet_getUChars(const UCharsetMatch *ucsm, michael@0: UChar *buf, int32_t cap, UErrorCode *status) michael@0: { michael@0: if(U_FAILURE(*status)) { michael@0: return 0; michael@0: } michael@0: michael@0: return ((CharsetMatch *) ucsm)->getUChars(buf, cap, status); michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: ucsdet_setDetectableCharset(UCharsetDetector *ucsd, const char *encoding, UBool enabled, UErrorCode *status) michael@0: { michael@0: ((CharsetDetector *)ucsd)->setDetectableCharset(encoding, enabled, *status); michael@0: } michael@0: michael@0: U_CAPI UEnumeration * U_EXPORT2 michael@0: ucsdet_getAllDetectableCharsets(const UCharsetDetector * /*ucsd*/, UErrorCode *status) michael@0: { michael@0: return CharsetDetector::getAllDetectableCharsets(*status); michael@0: } michael@0: michael@0: U_DRAFT UEnumeration * U_EXPORT2 michael@0: ucsdet_getDetectableCharsets(const UCharsetDetector *ucsd, UErrorCode *status) michael@0: { michael@0: return ((CharsetDetector *)ucsd)->getDetectableCharsets(*status); michael@0: } michael@0: michael@0: U_CDECL_END michael@0: michael@0: michael@0: #endif