Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************** |
michael@0 | 3 | * Copyright (C) 2005-2013, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ******************************************************************************** |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "unicode/utypes.h" |
michael@0 | 9 | |
michael@0 | 10 | #if !UCONFIG_NO_CONVERSION |
michael@0 | 11 | #include "unicode/ucsdet.h" |
michael@0 | 12 | #include "csdetect.h" |
michael@0 | 13 | #include "csmatch.h" |
michael@0 | 14 | #include "csrsbcs.h" |
michael@0 | 15 | #include "csrmbcs.h" |
michael@0 | 16 | #include "csrutf8.h" |
michael@0 | 17 | #include "csrucode.h" |
michael@0 | 18 | #include "csr2022.h" |
michael@0 | 19 | |
michael@0 | 20 | #include "cmemory.h" |
michael@0 | 21 | |
michael@0 | 22 | U_NAMESPACE_USE |
michael@0 | 23 | |
michael@0 | 24 | #define ARRAY_SIZE(array) (sizeof array / sizeof array[0]) |
michael@0 | 25 | |
michael@0 | 26 | #define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type)) |
michael@0 | 27 | #define DELETE_ARRAY(array) uprv_free((void *) (array)) |
michael@0 | 28 | |
michael@0 | 29 | U_CDECL_BEGIN |
michael@0 | 30 | |
michael@0 | 31 | U_CAPI UCharsetDetector * U_EXPORT2 |
michael@0 | 32 | ucsdet_open(UErrorCode *status) |
michael@0 | 33 | { |
michael@0 | 34 | if(U_FAILURE(*status)) { |
michael@0 | 35 | return 0; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | CharsetDetector* csd = new CharsetDetector(*status); |
michael@0 | 39 | |
michael@0 | 40 | if (U_FAILURE(*status)) { |
michael@0 | 41 | delete csd; |
michael@0 | 42 | csd = NULL; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | return (UCharsetDetector *) csd; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | U_CAPI void U_EXPORT2 |
michael@0 | 49 | ucsdet_close(UCharsetDetector *ucsd) |
michael@0 | 50 | { |
michael@0 | 51 | CharsetDetector *csd = (CharsetDetector *) ucsd; |
michael@0 | 52 | delete csd; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | U_CAPI void U_EXPORT2 |
michael@0 | 56 | ucsdet_setText(UCharsetDetector *ucsd, const char *textIn, int32_t len, UErrorCode *status) |
michael@0 | 57 | { |
michael@0 | 58 | if(U_FAILURE(*status)) { |
michael@0 | 59 | return; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | ((CharsetDetector *) ucsd)->setText(textIn, len); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | U_CAPI const char * U_EXPORT2 |
michael@0 | 66 | ucsdet_getName(const UCharsetMatch *ucsm, UErrorCode *status) |
michael@0 | 67 | { |
michael@0 | 68 | if(U_FAILURE(*status)) { |
michael@0 | 69 | return NULL; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | return ((CharsetMatch *) ucsm)->getName(); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 76 | ucsdet_getConfidence(const UCharsetMatch *ucsm, UErrorCode *status) |
michael@0 | 77 | { |
michael@0 | 78 | if(U_FAILURE(*status)) { |
michael@0 | 79 | return 0; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | return ((CharsetMatch *) ucsm)->getConfidence(); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | U_CAPI const char * U_EXPORT2 |
michael@0 | 86 | ucsdet_getLanguage(const UCharsetMatch *ucsm, UErrorCode *status) |
michael@0 | 87 | { |
michael@0 | 88 | if(U_FAILURE(*status)) { |
michael@0 | 89 | return NULL; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | return ((CharsetMatch *) ucsm)->getLanguage(); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | U_CAPI const UCharsetMatch * U_EXPORT2 |
michael@0 | 96 | ucsdet_detect(UCharsetDetector *ucsd, UErrorCode *status) |
michael@0 | 97 | { |
michael@0 | 98 | if(U_FAILURE(*status)) { |
michael@0 | 99 | return NULL; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | return (const UCharsetMatch *) ((CharsetDetector *) ucsd)->detect(*status); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | U_CAPI void U_EXPORT2 |
michael@0 | 106 | ucsdet_setDeclaredEncoding(UCharsetDetector *ucsd, const char *encoding, int32_t length, UErrorCode *status) |
michael@0 | 107 | { |
michael@0 | 108 | if(U_FAILURE(*status)) { |
michael@0 | 109 | return; |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | ((CharsetDetector *) ucsd)->setDeclaredEncoding(encoding,length); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | U_CAPI const UCharsetMatch** |
michael@0 | 116 | ucsdet_detectAll(UCharsetDetector *ucsd, |
michael@0 | 117 | int32_t *maxMatchesFound, UErrorCode *status) |
michael@0 | 118 | { |
michael@0 | 119 | if(U_FAILURE(*status)) { |
michael@0 | 120 | return NULL; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | CharsetDetector *csd = (CharsetDetector *) ucsd; |
michael@0 | 124 | |
michael@0 | 125 | return (const UCharsetMatch**)csd->detectAll(*maxMatchesFound,*status); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | // U_CAPI const char * U_EXPORT2 |
michael@0 | 129 | // ucsdet_getDetectableCharsetName(const UCharsetDetector *csd, int32_t index, UErrorCode *status) |
michael@0 | 130 | // { |
michael@0 | 131 | // if(U_FAILURE(*status)) { |
michael@0 | 132 | // return 0; |
michael@0 | 133 | // } |
michael@0 | 134 | // return csd->getCharsetName(index,*status); |
michael@0 | 135 | // } |
michael@0 | 136 | |
michael@0 | 137 | // U_CAPI int32_t U_EXPORT2 |
michael@0 | 138 | // ucsdet_getDetectableCharsetsCount(const UCharsetDetector *csd, UErrorCode *status) |
michael@0 | 139 | // { |
michael@0 | 140 | // if(U_FAILURE(*status)) { |
michael@0 | 141 | // return -1; |
michael@0 | 142 | // } |
michael@0 | 143 | // return UCharsetDetector::getDetectableCount(); |
michael@0 | 144 | // } |
michael@0 | 145 | |
michael@0 | 146 | U_CAPI UBool U_EXPORT2 |
michael@0 | 147 | ucsdet_isInputFilterEnabled(const UCharsetDetector *ucsd) |
michael@0 | 148 | { |
michael@0 | 149 | // todo: could use an error return... |
michael@0 | 150 | if (ucsd == NULL) { |
michael@0 | 151 | return FALSE; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | return ((CharsetDetector *) ucsd)->getStripTagsFlag(); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | U_CAPI UBool U_EXPORT2 |
michael@0 | 158 | ucsdet_enableInputFilter(UCharsetDetector *ucsd, UBool filter) |
michael@0 | 159 | { |
michael@0 | 160 | // todo: could use an error return... |
michael@0 | 161 | if (ucsd == NULL) { |
michael@0 | 162 | return FALSE; |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | CharsetDetector *csd = (CharsetDetector *) ucsd; |
michael@0 | 166 | UBool prev = csd->getStripTagsFlag(); |
michael@0 | 167 | |
michael@0 | 168 | csd->setStripTagsFlag(filter); |
michael@0 | 169 | |
michael@0 | 170 | return prev; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 174 | ucsdet_getUChars(const UCharsetMatch *ucsm, |
michael@0 | 175 | UChar *buf, int32_t cap, UErrorCode *status) |
michael@0 | 176 | { |
michael@0 | 177 | if(U_FAILURE(*status)) { |
michael@0 | 178 | return 0; |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | return ((CharsetMatch *) ucsm)->getUChars(buf, cap, status); |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | U_CAPI void U_EXPORT2 |
michael@0 | 185 | ucsdet_setDetectableCharset(UCharsetDetector *ucsd, const char *encoding, UBool enabled, UErrorCode *status) |
michael@0 | 186 | { |
michael@0 | 187 | ((CharsetDetector *)ucsd)->setDetectableCharset(encoding, enabled, *status); |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | U_CAPI UEnumeration * U_EXPORT2 |
michael@0 | 191 | ucsdet_getAllDetectableCharsets(const UCharsetDetector * /*ucsd*/, UErrorCode *status) |
michael@0 | 192 | { |
michael@0 | 193 | return CharsetDetector::getAllDetectableCharsets(*status); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | U_DRAFT UEnumeration * U_EXPORT2 |
michael@0 | 197 | ucsdet_getDetectableCharsets(const UCharsetDetector *ucsd, UErrorCode *status) |
michael@0 | 198 | { |
michael@0 | 199 | return ((CharsetDetector *)ucsd)->getDetectableCharsets(*status); |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | U_CDECL_END |
michael@0 | 203 | |
michael@0 | 204 | |
michael@0 | 205 | #endif |