Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | ********************************************************************** |
michael@0 | 3 | * Copyright (C) 2005-2012, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ********************************************************************** |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "unicode/utypes.h" |
michael@0 | 9 | |
michael@0 | 10 | #if !UCONFIG_NO_CONVERSION |
michael@0 | 11 | #include "unicode/unistr.h" |
michael@0 | 12 | #include "unicode/ucnv.h" |
michael@0 | 13 | |
michael@0 | 14 | #include "csmatch.h" |
michael@0 | 15 | |
michael@0 | 16 | #include "csrecog.h" |
michael@0 | 17 | #include "inputext.h" |
michael@0 | 18 | |
michael@0 | 19 | U_NAMESPACE_BEGIN |
michael@0 | 20 | |
michael@0 | 21 | CharsetMatch::CharsetMatch() |
michael@0 | 22 | : textIn(NULL), confidence(0), fCharsetName(NULL), fLang(NULL) |
michael@0 | 23 | { |
michael@0 | 24 | // nothing else to do. |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | void CharsetMatch::set(InputText *input, const CharsetRecognizer *cr, int32_t conf, |
michael@0 | 28 | const char *csName, const char *lang) |
michael@0 | 29 | { |
michael@0 | 30 | textIn = input; |
michael@0 | 31 | confidence = conf; |
michael@0 | 32 | fCharsetName = csName; |
michael@0 | 33 | fLang = lang; |
michael@0 | 34 | if (cr != NULL) { |
michael@0 | 35 | if (fCharsetName == NULL) { |
michael@0 | 36 | fCharsetName = cr->getName(); |
michael@0 | 37 | } |
michael@0 | 38 | if (fLang == NULL) { |
michael@0 | 39 | fLang = cr->getLanguage(); |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | const char* CharsetMatch::getName()const |
michael@0 | 45 | { |
michael@0 | 46 | return fCharsetName; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | const char* CharsetMatch::getLanguage()const |
michael@0 | 50 | { |
michael@0 | 51 | return fLang; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | int32_t CharsetMatch::getConfidence()const |
michael@0 | 55 | { |
michael@0 | 56 | return confidence; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | int32_t CharsetMatch::getUChars(UChar *buf, int32_t cap, UErrorCode *status) const |
michael@0 | 60 | { |
michael@0 | 61 | UConverter *conv = ucnv_open(getName(), status); |
michael@0 | 62 | int32_t result = ucnv_toUChars(conv, buf, cap, (const char *) textIn->fRawInput, textIn->fRawLength, status); |
michael@0 | 63 | |
michael@0 | 64 | ucnv_close(conv); |
michael@0 | 65 | |
michael@0 | 66 | return result; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | U_NAMESPACE_END |
michael@0 | 70 | |
michael@0 | 71 | #endif |