intl/icu/source/i18n/ucsdet.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial