intl/icu/source/i18n/csmatch.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-2012, 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/unistr.h"
    12 #include "unicode/ucnv.h"
    14 #include "csmatch.h"
    16 #include "csrecog.h"
    17 #include "inputext.h"
    19 U_NAMESPACE_BEGIN
    21 CharsetMatch::CharsetMatch()
    22   : textIn(NULL), confidence(0), fCharsetName(NULL), fLang(NULL)
    23 {
    24     // nothing else to do.
    25 }
    27 void CharsetMatch::set(InputText *input, const CharsetRecognizer *cr, int32_t conf,
    28                        const char *csName, const char *lang)
    29 {
    30     textIn = input;
    31     confidence = conf; 
    32     fCharsetName = csName;
    33     fLang = lang;
    34     if (cr != NULL) {
    35         if (fCharsetName == NULL) {
    36             fCharsetName = cr->getName();
    37         }
    38         if (fLang == NULL) {
    39             fLang = cr->getLanguage();
    40         }
    41     }
    42 }
    44 const char* CharsetMatch::getName()const
    45 {
    46     return fCharsetName; 
    47 }
    49 const char* CharsetMatch::getLanguage()const
    50 {
    51     return fLang; 
    52 }
    54 int32_t CharsetMatch::getConfidence()const
    55 {
    56     return confidence;
    57 }
    59 int32_t CharsetMatch::getUChars(UChar *buf, int32_t cap, UErrorCode *status) const
    60 {
    61     UConverter *conv = ucnv_open(getName(), status);
    62     int32_t result = ucnv_toUChars(conv, buf, cap, (const char *) textIn->fRawInput, textIn->fRawLength, status);
    64     ucnv_close(conv);
    66     return result;
    67 }
    69 U_NAMESPACE_END
    71 #endif

mercurial