PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/extensions/universalchardet/src/xpcom/nsUdetXPCOMWrapper.h

http://github.com/zpao/v8monkey
C Header | 243 lines | 153 code | 37 blank | 53 comment | 0 complexity | e40422d2c8c3765e1fce0b717ddbd408 MD5 | raw file
  1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2/* ***** BEGIN LICENSE BLOCK *****
  3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4 *
  5 * The contents of this file are subject to the Mozilla Public License Version
  6 * 1.1 (the "License"); you may not use this file except in compliance with
  7 * the License. You may obtain a copy of the License at
  8 * http://www.mozilla.org/MPL/
  9 *
 10 * Software distributed under the License is distributed on an "AS IS" basis,
 11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 12 * for the specific language governing rights and limitations under the
 13 * License.
 14 *
 15 * The Original Code is mozilla.org code.
 16 *
 17 * The Initial Developer of the Original Code is
 18 * Netscape Communications Corporation.
 19 * Portions created by the Initial Developer are Copyright (C) 1998
 20 * the Initial Developer. All Rights Reserved.
 21 *
 22 * Contributor(s):
 23 *
 24 * Alternatively, the contents of this file may be used under the terms of
 25 * either the GNU General Public License Version 2 or later (the "GPL"), or
 26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 27 * in which case the provisions of the GPL or the LGPL are applicable instead
 28 * of those above. If you wish to allow use of your version of this file only
 29 * under the terms of either the GPL or the LGPL, and not to allow others to
 30 * use your version of this file under the terms of the MPL, indicate your
 31 * decision by deleting the provisions above and replace them with the notice
 32 * and other provisions required by the GPL or the LGPL. If you do not delete
 33 * the provisions above, a recipient may use your version of this file under
 34 * the terms of any one of the MPL, the GPL or the LGPL.
 35 *
 36 * ***** END LICENSE BLOCK ***** */
 37
 38#ifndef _nsUdetXPCOMWrapper_h__
 39#define _nsUdetXPCOMWrapper_h__
 40#include "nsISupports.h"
 41#include "nsICharsetDetector.h"
 42#include "nsIStringCharsetDetector.h"
 43#include "nsICharsetDetectionObserver.h"
 44#include "nsCOMPtr.h"
 45
 46#include "nsIFactory.h"
 47
 48// {374E0CDE-F605-4259-8C92-E639C6C2EEEF}
 49#define NS_UNIVERSAL_DETECTOR_CID \
 50{ 0x374e0cde, 0xf605, 0x4259, { 0x8c, 0x92, 0xe6, 0x39, 0xc6, 0xc2, 0xee, 0xef } }
 51
 52// {6EE5301A-3981-49bd-85F8-1A2CC228CF3E}
 53#define NS_UNIVERSAL_STRING_DETECTOR_CID \
 54{ 0x6ee5301a, 0x3981, 0x49bd, { 0x85, 0xf8, 0x1a, 0x2c, 0xc2, 0x28, 0xcf, 0x3e } }
 55
 56// {12BB8F1B-2389-11d3-B3BF-00805F8A6670}
 57#define NS_JA_PSMDETECTOR_CID \
 58{ 0x12bb8f1b, 0x2389, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 59
 60// {12BB8F1C-2389-11d3-B3BF-00805F8A6670}
 61#define NS_JA_STRING_PSMDETECTOR_CID \
 62{ 0x12bb8f1c, 0x2389, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 63
 64// {EA06D4E1-2B3D-11d3-B3BF-00805F8A6670}
 65#define NS_KO_PSMDETECTOR_CID \
 66{ 0xea06d4e1, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 67
 68// {EA06D4E2-2B3D-11d3-B3BF-00805F8A6670}
 69#define NS_ZHCN_PSMDETECTOR_CID \
 70{ 0xea06d4e2, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 71
 72// {EA06D4E3-2B3D-11d3-B3BF-00805F8A6670}
 73#define NS_ZHTW_PSMDETECTOR_CID \
 74{ 0xea06d4e3, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 75
 76
 77// {EA06D4E4-2B3D-11d3-B3BF-00805F8A6670}
 78#define NS_KO_STRING_PSMDETECTOR_CID \
 79{ 0xea06d4e4, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 80
 81// {EA06D4E5-2B3D-11d3-B3BF-00805F8A6670}
 82#define NS_ZHCN_STRING_PSMDETECTOR_CID \
 83{ 0xea06d4e5, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 84
 85// {EA06D4E6-2B3D-11d3-B3BF-00805F8A6670}
 86#define NS_ZHTW_STRING_PSMDETECTOR_CID \
 87{ 0xea06d4e6, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 88
 89
 90// {FCACEF21-2B40-11d3-B3BF-00805F8A6670}
 91#define NS_ZH_STRING_PSMDETECTOR_CID \
 92{ 0xfcacef21, 0x2b40, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 93
 94// {FCACEF22-2B40-11d3-B3BF-00805F8A6670}
 95#define NS_CJK_STRING_PSMDETECTOR_CID \
 96{ 0xfcacef22, 0x2b40, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 97
 98
 99// {FCACEF23-2B40-11d3-B3BF-00805F8A6670}
100#define NS_ZH_PSMDETECTOR_CID \
101{ 0xfcacef23, 0x2b40, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
102
103// {FCACEF24-2B40-11d3-B3BF-00805F8A6670}
104#define NS_CJK_PSMDETECTOR_CID \
105{ 0xfcacef24, 0x2b40, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
106
107//=====================================================================
108class nsXPCOMDetector :  
109      public nsUniversalDetector,
110      public nsICharsetDetector
111{
112  NS_DECL_ISUPPORTS
113  public:
114    nsXPCOMDetector(PRUint32 aLanguageFilter);
115    virtual ~nsXPCOMDetector();
116    NS_IMETHOD Init(nsICharsetDetectionObserver* aObserver);
117    NS_IMETHOD DoIt(const char* aBuf, PRUint32 aLen, bool *oDontFeedMe);
118    NS_IMETHOD Done();
119  protected:
120    virtual void Report(const char* aCharset);
121  private:
122    nsCOMPtr<nsICharsetDetectionObserver> mObserver;
123};
124
125
126//=====================================================================
127class nsXPCOMStringDetector :  
128      public nsUniversalDetector,
129      public nsIStringCharsetDetector
130{
131  NS_DECL_ISUPPORTS
132  public:
133    nsXPCOMStringDetector(PRUint32 aLanguageFilter);
134    virtual ~nsXPCOMStringDetector();
135    NS_IMETHOD DoIt(const char* aBuf, PRUint32 aLen, 
136                    const char** oCharset, nsDetectionConfident &oConf);
137  protected:
138    virtual void Report(const char* aCharset);
139  private:
140    nsCOMPtr<nsICharsetDetectionObserver> mObserver;
141    const char* mResult;
142};
143
144//=====================================================================
145class nsUniversalXPCOMDetector : public nsXPCOMDetector
146{
147public:
148  nsUniversalXPCOMDetector() 
149    : nsXPCOMDetector(NS_FILTER_ALL) {}
150};
151
152class nsUniversalXPCOMStringDetector : public nsXPCOMStringDetector
153{
154public:
155  nsUniversalXPCOMStringDetector() 
156    : nsXPCOMStringDetector(NS_FILTER_ALL) {}
157};
158
159class nsJAPSMDetector : public nsXPCOMDetector
160{
161public:
162  nsJAPSMDetector() 
163    : nsXPCOMDetector(NS_FILTER_JAPANESE) {}
164};
165
166class nsJAStringPSMDetector : public nsXPCOMStringDetector
167{
168public:
169  nsJAStringPSMDetector() 
170    : nsXPCOMStringDetector(NS_FILTER_JAPANESE) {}
171};
172
173class nsKOPSMDetector : public nsXPCOMDetector
174{
175public:
176  nsKOPSMDetector() 
177    : nsXPCOMDetector(NS_FILTER_KOREAN) {}
178};
179
180class nsKOStringPSMDetector : public nsXPCOMStringDetector
181{
182public:
183  nsKOStringPSMDetector() 
184    : nsXPCOMStringDetector(NS_FILTER_KOREAN) {}
185};
186
187class nsZHTWPSMDetector : public nsXPCOMDetector
188{
189public:
190  nsZHTWPSMDetector() 
191    : nsXPCOMDetector(NS_FILTER_CHINESE_TRADITIONAL) {}
192};
193
194class nsZHTWStringPSMDetector : public nsXPCOMStringDetector
195{
196public:
197  nsZHTWStringPSMDetector() 
198    : nsXPCOMStringDetector(NS_FILTER_CHINESE_TRADITIONAL) {}
199};
200
201class nsZHCNPSMDetector : public nsXPCOMDetector
202{
203public:
204  nsZHCNPSMDetector() 
205    : nsXPCOMDetector(NS_FILTER_CHINESE_SIMPLIFIED) {}
206};
207
208class nsZHCNStringPSMDetector : public nsXPCOMStringDetector
209{
210public:
211  nsZHCNStringPSMDetector() 
212    : nsXPCOMStringDetector(NS_FILTER_CHINESE_SIMPLIFIED) {}
213};
214
215class nsZHPSMDetector : public nsXPCOMDetector
216{
217public:
218  nsZHPSMDetector() 
219    : nsXPCOMDetector(NS_FILTER_CHINESE) {}
220};
221
222class nsZHStringPSMDetector : public nsXPCOMStringDetector
223{
224public:
225  nsZHStringPSMDetector() 
226    : nsXPCOMStringDetector(NS_FILTER_CHINESE) {}
227};
228
229class nsCJKPSMDetector : public nsXPCOMDetector
230{
231public:
232  nsCJKPSMDetector() 
233    : nsXPCOMDetector(NS_FILTER_CJK) {}
234};
235
236class nsCJKStringPSMDetector : public nsXPCOMStringDetector
237{
238public:
239  nsCJKStringPSMDetector() 
240    : nsXPCOMStringDetector(NS_FILTER_CJK) {}
241};
242
243#endif //_nsUdetXPCOMWrapper_h__