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__
8 #include "nsCyrillicClass.h"
13 // {2002F781-3960-11d3-B3C3-00805F8A6670}
14 #define NS_RU_PROBDETECTOR_CID \
15 { 0x2002f781, 0x3960, 0x11d3, { 0xb3, 0xc3, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
18 // {2002F782-3960-11d3-B3C3-00805F8A6670}
19 #define NS_UK_PROBDETECTOR_CID \
20 { 0x2002f782, 0x3960, 0x11d3, { 0xb3, 0xc3, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
22 // {2002F783-3960-11d3-B3C3-00805F8A6670}
23 #define NS_RU_STRING_PROBDETECTOR_CID \
24 { 0x2002f783, 0x3960, 0x11d3, { 0xb3, 0xc3, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
26 // {2002F784-3960-11d3-B3C3-00805F8A6670}
27 #define NS_UK_STRING_PROBDETECTOR_CID \
28 { 0x2002f784, 0x3960, 0x11d3, { 0xb3, 0xc3, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
30 static const uint8_t *gCyrillicCls
[5] =
39 static const char * gRussian
[5] = {
47 static const char * gUkrainian
[5] = {
55 #define NUM_CYR_CHARSET 5
57 class nsCyrillicDetector
60 nsCyrillicDetector(uint8_t aItems
,
61 const uint8_t ** aCyrillicClass
,
62 const char **aCharsets
) {
64 mCyrillicClass
= aCyrillicClass
;
65 mCharsets
= aCharsets
;
66 for(unsigned i
=0;i
<mItems
;i
++)
67 mProb
[i
] = mLastCls
[i
] =0;
70 virtual ~nsCyrillicDetector() {}
71 virtual void HandleData(const char* aBuf
, uint32_t aLen
);
72 virtual void DataEnd();
74 virtual void Report(const char* aCharset
) = 0;
79 const uint8_t ** mCyrillicClass
;
80 const char** mCharsets
;
81 uint32_t mProb
[NUM_CYR_CHARSET
];
82 uint8_t mLastCls
[NUM_CYR_CHARSET
];
85 class nsCyrXPCOMDetector
:
86 public nsCyrillicDetector
,
87 public nsICharsetDetector
90 // nsISupports interface
92 nsCyrXPCOMDetector(uint8_t aItems
,
93 const uint8_t ** aCyrillicClass
,
94 const char **aCharsets
);
95 NS_IMETHOD
Init(nsICharsetDetectionObserver
* aObserver
);
96 NS_IMETHOD
DoIt(const char* aBuf
, uint32_t aLen
, bool *oDontFeedMe
);
99 virtual ~nsCyrXPCOMDetector();
100 virtual void Report(const char* aCharset
);
102 nsCOMPtr
<nsICharsetDetectionObserver
> mObserver
;
105 class nsCyrXPCOMStringDetector
:
106 public nsCyrillicDetector
,
107 public nsIStringCharsetDetector
110 // nsISupports interface
112 nsCyrXPCOMStringDetector(uint8_t aItems
,
113 const uint8_t ** aCyrillicClass
,
114 const char **aCharsets
);
115 NS_IMETHOD
DoIt(const char* aBuf
, uint32_t aLen
,
116 const char** oCharset
, nsDetectionConfident
&oConf
);
118 virtual ~nsCyrXPCOMStringDetector();
119 virtual void Report(const char* aCharset
);
121 nsCOMPtr
<nsICharsetDetectionObserver
> mObserver
;
125 class nsRUProbDetector
: public nsCyrXPCOMDetector
129 : nsCyrXPCOMDetector(5, gCyrillicCls
, gRussian
) {}
132 class nsRUStringProbDetector
: public nsCyrXPCOMStringDetector
135 nsRUStringProbDetector()
136 : nsCyrXPCOMStringDetector(5, gCyrillicCls
, gRussian
) {}
139 class nsUKProbDetector
: public nsCyrXPCOMDetector
143 : nsCyrXPCOMDetector(5, gCyrillicCls
, gUkrainian
) {}
146 class nsUKStringProbDetector
: public nsCyrXPCOMStringDetector
149 nsUKStringProbDetector()
150 : nsCyrXPCOMStringDetector(5, gCyrillicCls
, gUkrainian
) {}