1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/ucsdet.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,205 @@ 1.4 +/* 1.5 + ******************************************************************************** 1.6 + * Copyright (C) 2005-2013, International Business Machines 1.7 + * Corporation and others. All Rights Reserved. 1.8 + ******************************************************************************** 1.9 + */ 1.10 + 1.11 +#include "unicode/utypes.h" 1.12 + 1.13 +#if !UCONFIG_NO_CONVERSION 1.14 +#include "unicode/ucsdet.h" 1.15 +#include "csdetect.h" 1.16 +#include "csmatch.h" 1.17 +#include "csrsbcs.h" 1.18 +#include "csrmbcs.h" 1.19 +#include "csrutf8.h" 1.20 +#include "csrucode.h" 1.21 +#include "csr2022.h" 1.22 + 1.23 +#include "cmemory.h" 1.24 + 1.25 +U_NAMESPACE_USE 1.26 + 1.27 +#define ARRAY_SIZE(array) (sizeof array / sizeof array[0]) 1.28 + 1.29 +#define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type)) 1.30 +#define DELETE_ARRAY(array) uprv_free((void *) (array)) 1.31 + 1.32 +U_CDECL_BEGIN 1.33 + 1.34 +U_CAPI UCharsetDetector * U_EXPORT2 1.35 +ucsdet_open(UErrorCode *status) 1.36 +{ 1.37 + if(U_FAILURE(*status)) { 1.38 + return 0; 1.39 + } 1.40 + 1.41 + CharsetDetector* csd = new CharsetDetector(*status); 1.42 + 1.43 + if (U_FAILURE(*status)) { 1.44 + delete csd; 1.45 + csd = NULL; 1.46 + } 1.47 + 1.48 + return (UCharsetDetector *) csd; 1.49 +} 1.50 + 1.51 +U_CAPI void U_EXPORT2 1.52 +ucsdet_close(UCharsetDetector *ucsd) 1.53 +{ 1.54 + CharsetDetector *csd = (CharsetDetector *) ucsd; 1.55 + delete csd; 1.56 +} 1.57 + 1.58 +U_CAPI void U_EXPORT2 1.59 +ucsdet_setText(UCharsetDetector *ucsd, const char *textIn, int32_t len, UErrorCode *status) 1.60 +{ 1.61 + if(U_FAILURE(*status)) { 1.62 + return; 1.63 + } 1.64 + 1.65 + ((CharsetDetector *) ucsd)->setText(textIn, len); 1.66 +} 1.67 + 1.68 +U_CAPI const char * U_EXPORT2 1.69 +ucsdet_getName(const UCharsetMatch *ucsm, UErrorCode *status) 1.70 +{ 1.71 + if(U_FAILURE(*status)) { 1.72 + return NULL; 1.73 + } 1.74 + 1.75 + return ((CharsetMatch *) ucsm)->getName(); 1.76 +} 1.77 + 1.78 +U_CAPI int32_t U_EXPORT2 1.79 +ucsdet_getConfidence(const UCharsetMatch *ucsm, UErrorCode *status) 1.80 +{ 1.81 + if(U_FAILURE(*status)) { 1.82 + return 0; 1.83 + } 1.84 + 1.85 + return ((CharsetMatch *) ucsm)->getConfidence(); 1.86 +} 1.87 + 1.88 +U_CAPI const char * U_EXPORT2 1.89 +ucsdet_getLanguage(const UCharsetMatch *ucsm, UErrorCode *status) 1.90 +{ 1.91 + if(U_FAILURE(*status)) { 1.92 + return NULL; 1.93 + } 1.94 + 1.95 + return ((CharsetMatch *) ucsm)->getLanguage(); 1.96 +} 1.97 + 1.98 +U_CAPI const UCharsetMatch * U_EXPORT2 1.99 +ucsdet_detect(UCharsetDetector *ucsd, UErrorCode *status) 1.100 +{ 1.101 + if(U_FAILURE(*status)) { 1.102 + return NULL; 1.103 + } 1.104 + 1.105 + return (const UCharsetMatch *) ((CharsetDetector *) ucsd)->detect(*status); 1.106 +} 1.107 + 1.108 +U_CAPI void U_EXPORT2 1.109 +ucsdet_setDeclaredEncoding(UCharsetDetector *ucsd, const char *encoding, int32_t length, UErrorCode *status) 1.110 +{ 1.111 + if(U_FAILURE(*status)) { 1.112 + return; 1.113 + } 1.114 + 1.115 + ((CharsetDetector *) ucsd)->setDeclaredEncoding(encoding,length); 1.116 +} 1.117 + 1.118 +U_CAPI const UCharsetMatch** 1.119 +ucsdet_detectAll(UCharsetDetector *ucsd, 1.120 + int32_t *maxMatchesFound, UErrorCode *status) 1.121 +{ 1.122 + if(U_FAILURE(*status)) { 1.123 + return NULL; 1.124 + } 1.125 + 1.126 + CharsetDetector *csd = (CharsetDetector *) ucsd; 1.127 + 1.128 + return (const UCharsetMatch**)csd->detectAll(*maxMatchesFound,*status); 1.129 +} 1.130 + 1.131 +// U_CAPI const char * U_EXPORT2 1.132 +// ucsdet_getDetectableCharsetName(const UCharsetDetector *csd, int32_t index, UErrorCode *status) 1.133 +// { 1.134 +// if(U_FAILURE(*status)) { 1.135 +// return 0; 1.136 +// } 1.137 +// return csd->getCharsetName(index,*status); 1.138 +// } 1.139 + 1.140 +// U_CAPI int32_t U_EXPORT2 1.141 +// ucsdet_getDetectableCharsetsCount(const UCharsetDetector *csd, UErrorCode *status) 1.142 +// { 1.143 +// if(U_FAILURE(*status)) { 1.144 +// return -1; 1.145 +// } 1.146 +// return UCharsetDetector::getDetectableCount(); 1.147 +// } 1.148 + 1.149 +U_CAPI UBool U_EXPORT2 1.150 +ucsdet_isInputFilterEnabled(const UCharsetDetector *ucsd) 1.151 +{ 1.152 + // todo: could use an error return... 1.153 + if (ucsd == NULL) { 1.154 + return FALSE; 1.155 + } 1.156 + 1.157 + return ((CharsetDetector *) ucsd)->getStripTagsFlag(); 1.158 +} 1.159 + 1.160 +U_CAPI UBool U_EXPORT2 1.161 +ucsdet_enableInputFilter(UCharsetDetector *ucsd, UBool filter) 1.162 +{ 1.163 + // todo: could use an error return... 1.164 + if (ucsd == NULL) { 1.165 + return FALSE; 1.166 + } 1.167 + 1.168 + CharsetDetector *csd = (CharsetDetector *) ucsd; 1.169 + UBool prev = csd->getStripTagsFlag(); 1.170 + 1.171 + csd->setStripTagsFlag(filter); 1.172 + 1.173 + return prev; 1.174 +} 1.175 + 1.176 +U_CAPI int32_t U_EXPORT2 1.177 +ucsdet_getUChars(const UCharsetMatch *ucsm, 1.178 + UChar *buf, int32_t cap, UErrorCode *status) 1.179 +{ 1.180 + if(U_FAILURE(*status)) { 1.181 + return 0; 1.182 + } 1.183 + 1.184 + return ((CharsetMatch *) ucsm)->getUChars(buf, cap, status); 1.185 +} 1.186 + 1.187 +U_CAPI void U_EXPORT2 1.188 +ucsdet_setDetectableCharset(UCharsetDetector *ucsd, const char *encoding, UBool enabled, UErrorCode *status) 1.189 +{ 1.190 + ((CharsetDetector *)ucsd)->setDetectableCharset(encoding, enabled, *status); 1.191 +} 1.192 + 1.193 +U_CAPI UEnumeration * U_EXPORT2 1.194 +ucsdet_getAllDetectableCharsets(const UCharsetDetector * /*ucsd*/, UErrorCode *status) 1.195 +{ 1.196 + return CharsetDetector::getAllDetectableCharsets(*status); 1.197 +} 1.198 + 1.199 +U_DRAFT UEnumeration * U_EXPORT2 1.200 +ucsdet_getDetectableCharsets(const UCharsetDetector *ucsd, UErrorCode *status) 1.201 +{ 1.202 + return ((CharsetDetector *)ucsd)->getDetectableCharsets(*status); 1.203 +} 1.204 + 1.205 +U_CDECL_END 1.206 + 1.207 + 1.208 +#endif