/src/mozilla-central/intl/chardet/nsCyrillicDetector.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | #ifndef nsCyrillicDetector_h__ |
6 | | #define nsCyrillicDetector_h__ |
7 | | |
8 | | #include "nsCyrillicClass.h" |
9 | | #include "nsIStringCharsetDetector.h" |
10 | | |
11 | | static const uint8_t *gCyrillicCls[5] = |
12 | | { |
13 | | CP1251Map, |
14 | | KOI8Map, |
15 | | ISO88595Map, |
16 | | MacCyrillicMap, |
17 | | IBM866Map |
18 | | }; |
19 | | |
20 | | static const char * gRussian[5] = { |
21 | | "windows-1251", |
22 | | "KOI8-R", |
23 | | "ISO-8859-5", |
24 | | "x-mac-cyrillic", |
25 | | "IBM866" |
26 | | }; |
27 | | |
28 | | static const char * gUkrainian[5] = { |
29 | | "windows-1251", |
30 | | "KOI8-U", |
31 | | "ISO-8859-5", |
32 | | "x-mac-cyrillic", |
33 | | "IBM866" |
34 | | }; |
35 | | |
36 | | #define NUM_CYR_CHARSET 5 |
37 | | |
38 | | class nsCyrillicDetector |
39 | | { |
40 | | public: |
41 | | nsCyrillicDetector(uint8_t aItems, |
42 | | const uint8_t ** aCyrillicClass, |
43 | 0 | const char **aCharsets) { |
44 | 0 | mItems = aItems; |
45 | 0 | mCyrillicClass = aCyrillicClass; |
46 | 0 | mCharsets = aCharsets; |
47 | 0 | for(unsigned i=0;i<mItems;i++) |
48 | 0 | mProb[i] = mLastCls[i] =0; |
49 | 0 | mDone = false; |
50 | 0 | } |
51 | 0 | virtual ~nsCyrillicDetector() {} |
52 | | virtual void HandleData(const char* aBuf, uint32_t aLen); |
53 | | virtual void DataEnd(); |
54 | | protected: |
55 | | virtual void Report(const char* aCharset) = 0; |
56 | | bool mDone; |
57 | | |
58 | | private: |
59 | | uint8_t mItems; |
60 | | const uint8_t ** mCyrillicClass; |
61 | | const char** mCharsets; |
62 | | uint32_t mProb[NUM_CYR_CHARSET]; |
63 | | uint8_t mLastCls[NUM_CYR_CHARSET]; |
64 | | }; |
65 | | |
66 | | class nsCyrXPCOMDetector : |
67 | | public nsCyrillicDetector, |
68 | | public nsICharsetDetector |
69 | | { |
70 | | public: |
71 | | // nsISupports interface |
72 | | NS_DECL_ISUPPORTS |
73 | | nsCyrXPCOMDetector(uint8_t aItems, |
74 | | const uint8_t ** aCyrillicClass, |
75 | | const char **aCharsets); |
76 | | NS_IMETHOD Init(nsICharsetDetectionObserver* aObserver) override; |
77 | | NS_IMETHOD DoIt(const char* aBuf, uint32_t aLen, bool *oDontFeedMe) override; |
78 | | NS_IMETHOD Done() override; |
79 | | protected: |
80 | | virtual ~nsCyrXPCOMDetector(); |
81 | | virtual void Report(const char* aCharset) override; |
82 | | private: |
83 | | nsCOMPtr<nsICharsetDetectionObserver> mObserver; |
84 | | }; |
85 | | |
86 | | class nsRUProbDetector final : public nsCyrXPCOMDetector |
87 | | { |
88 | | public: |
89 | | nsRUProbDetector() |
90 | 0 | : nsCyrXPCOMDetector(5, gCyrillicCls, gRussian) {} |
91 | | }; |
92 | | |
93 | | class nsUKProbDetector final : public nsCyrXPCOMDetector |
94 | | { |
95 | | public: |
96 | | nsUKProbDetector() |
97 | 0 | : nsCyrXPCOMDetector(5, gCyrillicCls, gUkrainian) {} |
98 | | }; |
99 | | |
100 | | #endif |