michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (C) 2005-2012, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_CONVERSION michael@0: #include "unicode/unistr.h" michael@0: #include "unicode/ucnv.h" michael@0: michael@0: #include "csmatch.h" michael@0: michael@0: #include "csrecog.h" michael@0: #include "inputext.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: CharsetMatch::CharsetMatch() michael@0: : textIn(NULL), confidence(0), fCharsetName(NULL), fLang(NULL) michael@0: { michael@0: // nothing else to do. michael@0: } michael@0: michael@0: void CharsetMatch::set(InputText *input, const CharsetRecognizer *cr, int32_t conf, michael@0: const char *csName, const char *lang) michael@0: { michael@0: textIn = input; michael@0: confidence = conf; michael@0: fCharsetName = csName; michael@0: fLang = lang; michael@0: if (cr != NULL) { michael@0: if (fCharsetName == NULL) { michael@0: fCharsetName = cr->getName(); michael@0: } michael@0: if (fLang == NULL) { michael@0: fLang = cr->getLanguage(); michael@0: } michael@0: } michael@0: } michael@0: michael@0: const char* CharsetMatch::getName()const michael@0: { michael@0: return fCharsetName; michael@0: } michael@0: michael@0: const char* CharsetMatch::getLanguage()const michael@0: { michael@0: return fLang; michael@0: } michael@0: michael@0: int32_t CharsetMatch::getConfidence()const michael@0: { michael@0: return confidence; michael@0: } michael@0: michael@0: int32_t CharsetMatch::getUChars(UChar *buf, int32_t cap, UErrorCode *status) const michael@0: { michael@0: UConverter *conv = ucnv_open(getName(), status); michael@0: int32_t result = ucnv_toUChars(conv, buf, cap, (const char *) textIn->fRawInput, textIn->fRawLength, status); michael@0: michael@0: ucnv_close(conv); michael@0: michael@0: return result; michael@0: } michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif