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
19 U_NAMESPACE_BEGIN
20
CharsetMatch()21 CharsetMatch::CharsetMatch()
22 : textIn(NULL), confidence(0), fCharsetName(NULL), fLang(NULL)
23 {
24 // nothing else to do.
25 }
26
set(InputText * input,const CharsetRecognizer * cr,int32_t conf,const char * csName,const char * lang)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 }
43
getName() const44 const char* CharsetMatch::getName()const
45 {
46 return fCharsetName;
47 }
48
getLanguage() const49 const char* CharsetMatch::getLanguage()const
50 {
51 return fLang;
52 }
53
getConfidence() const54 int32_t CharsetMatch::getConfidence()const
55 {
56 return confidence;
57 }
58
getUChars(UChar * buf,int32_t cap,UErrorCode * status) const59 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);
63
64 ucnv_close(conv);
65
66 return result;
67 }
68
69 U_NAMESPACE_END
70
71 #endif
72