]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/csmatch.cpp
ICU-64243.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / csmatch.cpp
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
73c04bcf
A
3/*
4 **********************************************************************
51004dcb 5 * Copyright (C) 2005-2012, International Business Machines
73c04bcf
A
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
8 */
9
10#include "unicode/utypes.h"
11
12#if !UCONFIG_NO_CONVERSION
13#include "unicode/unistr.h"
14#include "unicode/ucnv.h"
15
16#include "csmatch.h"
17
18#include "csrecog.h"
19#include "inputext.h"
20
21U_NAMESPACE_BEGIN
22
23CharsetMatch::CharsetMatch()
51004dcb 24 : textIn(NULL), confidence(0), fCharsetName(NULL), fLang(NULL)
73c04bcf
A
25{
26 // nothing else to do.
27}
28
51004dcb
A
29void CharsetMatch::set(InputText *input, const CharsetRecognizer *cr, int32_t conf,
30 const char *csName, const char *lang)
73c04bcf
A
31{
32 textIn = input;
73c04bcf 33 confidence = conf;
51004dcb
A
34 fCharsetName = csName;
35 fLang = lang;
36 if (cr != NULL) {
37 if (fCharsetName == NULL) {
38 fCharsetName = cr->getName();
39 }
40 if (fLang == NULL) {
41 fLang = cr->getLanguage();
42 }
43 }
73c04bcf
A
44}
45
46const char* CharsetMatch::getName()const
47{
51004dcb 48 return fCharsetName;
73c04bcf
A
49}
50
51const char* CharsetMatch::getLanguage()const
52{
51004dcb 53 return fLang;
73c04bcf
A
54}
55
56int32_t CharsetMatch::getConfidence()const
57{
58 return confidence;
59}
60
61int32_t CharsetMatch::getUChars(UChar *buf, int32_t cap, UErrorCode *status) const
62{
63 UConverter *conv = ucnv_open(getName(), status);
64 int32_t result = ucnv_toUChars(conv, buf, cap, (const char *) textIn->fRawInput, textIn->fRawLength, status);
65
66 ucnv_close(conv);
67
68 return result;
69}
70
71U_NAMESPACE_END
72
73#endif