1/* 2 ********************************************************************** 3 * Copyright (C) 2005-2012, International Business Machines 4 * Corporation and others. All Rights Reserved. 5 ********************************************************************** 6 */ 7 8#include "unicode/utypes.h" 9 10#if !UCONFIG_NO_CONVERSION 11#include "unicode/unistr.h" 12#include "unicode/ucnv.h" 13 14#include "csmatch.h" 15 16#include "csrecog.h" 17#include "inputext.h" 18 19U_NAMESPACE_BEGIN 20 21CharsetMatch::CharsetMatch() 22 : textIn(NULL), confidence(0), fCharsetName(NULL), fLang(NULL) 23{ 24 // nothing else to do. 25} 26 27void 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} 43 44const char* CharsetMatch::getName()const 45{ 46 return fCharsetName; 47} 48 49const char* CharsetMatch::getLanguage()const 50{ 51 return fLang; 52} 53 54int32_t CharsetMatch::getConfidence()const 55{ 56 return confidence; 57} 58 59int32_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); 63 64 ucnv_close(conv); 65 66 return result; 67} 68 69U_NAMESPACE_END 70 71#endif 72