intl/icu/source/i18n/csmatch.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/csmatch.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,71 @@
     1.4 +/*
     1.5 + **********************************************************************
     1.6 + *   Copyright (C) 2005-2012, 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/unistr.h"
    1.15 +#include "unicode/ucnv.h"
    1.16 +
    1.17 +#include "csmatch.h"
    1.18 +
    1.19 +#include "csrecog.h"
    1.20 +#include "inputext.h"
    1.21 +
    1.22 +U_NAMESPACE_BEGIN
    1.23 +
    1.24 +CharsetMatch::CharsetMatch()
    1.25 +  : textIn(NULL), confidence(0), fCharsetName(NULL), fLang(NULL)
    1.26 +{
    1.27 +    // nothing else to do.
    1.28 +}
    1.29 +
    1.30 +void CharsetMatch::set(InputText *input, const CharsetRecognizer *cr, int32_t conf,
    1.31 +                       const char *csName, const char *lang)
    1.32 +{
    1.33 +    textIn = input;
    1.34 +    confidence = conf; 
    1.35 +    fCharsetName = csName;
    1.36 +    fLang = lang;
    1.37 +    if (cr != NULL) {
    1.38 +        if (fCharsetName == NULL) {
    1.39 +            fCharsetName = cr->getName();
    1.40 +        }
    1.41 +        if (fLang == NULL) {
    1.42 +            fLang = cr->getLanguage();
    1.43 +        }
    1.44 +    }
    1.45 +}
    1.46 +
    1.47 +const char* CharsetMatch::getName()const
    1.48 +{
    1.49 +    return fCharsetName; 
    1.50 +}
    1.51 +
    1.52 +const char* CharsetMatch::getLanguage()const
    1.53 +{
    1.54 +    return fLang; 
    1.55 +}
    1.56 +
    1.57 +int32_t CharsetMatch::getConfidence()const
    1.58 +{
    1.59 +    return confidence;
    1.60 +}
    1.61 +
    1.62 +int32_t CharsetMatch::getUChars(UChar *buf, int32_t cap, UErrorCode *status) const
    1.63 +{
    1.64 +    UConverter *conv = ucnv_open(getName(), status);
    1.65 +    int32_t result = ucnv_toUChars(conv, buf, cap, (const char *) textIn->fRawInput, textIn->fRawLength, status);
    1.66 +
    1.67 +    ucnv_close(conv);
    1.68 +
    1.69 +    return result;
    1.70 +}
    1.71 +
    1.72 +U_NAMESPACE_END
    1.73 +
    1.74 +#endif

mercurial