/src/mozilla-central/intl/icu/source/i18n/csmatch.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // © 2016 and later: Unicode, Inc. and others. |
2 | | // License & terms of use: http://www.unicode.org/copyright.html |
3 | | /* |
4 | | ********************************************************************** |
5 | | * Copyright (C) 2005-2012, International Business Machines |
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 | | |
21 | | U_NAMESPACE_BEGIN |
22 | | |
23 | | CharsetMatch::CharsetMatch() |
24 | | : textIn(NULL), confidence(0), fCharsetName(NULL), fLang(NULL) |
25 | 0 | { |
26 | 0 | // nothing else to do. |
27 | 0 | } |
28 | | |
29 | | void CharsetMatch::set(InputText *input, const CharsetRecognizer *cr, int32_t conf, |
30 | | const char *csName, const char *lang) |
31 | 0 | { |
32 | 0 | textIn = input; |
33 | 0 | confidence = conf; |
34 | 0 | fCharsetName = csName; |
35 | 0 | fLang = lang; |
36 | 0 | if (cr != NULL) { |
37 | 0 | if (fCharsetName == NULL) { |
38 | 0 | fCharsetName = cr->getName(); |
39 | 0 | } |
40 | 0 | if (fLang == NULL) { |
41 | 0 | fLang = cr->getLanguage(); |
42 | 0 | } |
43 | 0 | } |
44 | 0 | } |
45 | | |
46 | | const char* CharsetMatch::getName()const |
47 | 0 | { |
48 | 0 | return fCharsetName; |
49 | 0 | } |
50 | | |
51 | | const char* CharsetMatch::getLanguage()const |
52 | 0 | { |
53 | 0 | return fLang; |
54 | 0 | } |
55 | | |
56 | | int32_t CharsetMatch::getConfidence()const |
57 | 0 | { |
58 | 0 | return confidence; |
59 | 0 | } |
60 | | |
61 | | int32_t CharsetMatch::getUChars(UChar *buf, int32_t cap, UErrorCode *status) const |
62 | 0 | { |
63 | 0 | UConverter *conv = ucnv_open(getName(), status); |
64 | 0 | int32_t result = ucnv_toUChars(conv, buf, cap, (const char *) textIn->fRawInput, textIn->fRawLength, status); |
65 | 0 |
|
66 | 0 | ucnv_close(conv); |
67 | 0 |
|
68 | 0 | return result; |
69 | 0 | } |
70 | | |
71 | | U_NAMESPACE_END |
72 | | |
73 | | #endif |