Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / extensions / universalchardet / src / base / JpCntx.h
blobe864459323041ed6a902bf01529450e682fb10ba
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
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/
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.
15 * The Original Code is Mozilla Communicator client code.
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.
22 * Contributor(s):
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.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef __JPCNTX_H__
39 #define __JPCNTX_H__
41 #define NUM_OF_CATEGORY 6
43 #include "nscore.h"
45 #define ENOUGH_REL_THRESHOLD 100
46 #define MAX_REL_THRESHOLD 1000
48 //hiragana frequency category table
49 extern char jp2CharContext[83][83];
51 class JapaneseContextAnalysis
53 public:
54 JapaneseContextAnalysis() {Reset();}
56 void HandleData(const char* aBuf, PRUint32 aLen);
58 void HandleOneChar(const char* aStr, PRUint32 aCharLen)
60 PRInt32 order;
62 //if we received enough data, stop here
63 if (mTotalRel > MAX_REL_THRESHOLD) mDone = PR_TRUE;
64 if (mDone) return;
66 //Only 2-bytes characters are of our interest
67 order = (aCharLen == 2) ? GetOrder(aStr) : -1;
68 if (order != -1 && mLastCharOrder != -1)
70 mTotalRel++;
71 //count this sequence to its category counter
72 mRelSample[jp2CharContext[mLastCharOrder][order]]++;
74 mLastCharOrder = order;
77 float GetConfidence(PRBool aIsPreferredLanguage);
78 void Reset(void);
79 void SetOpion(){}
80 PRBool GotEnoughData() {return mTotalRel > ENOUGH_REL_THRESHOLD;}
82 protected:
83 virtual PRInt32 GetOrder(const char* str, PRUint32 *charLen) = 0;
84 virtual PRInt32 GetOrder(const char* str) = 0;
86 //category counters, each integer counts sequences in its category
87 PRUint32 mRelSample[NUM_OF_CATEGORY];
89 //total sequence received
90 PRUint32 mTotalRel;
92 //The order of previous char
93 PRInt32 mLastCharOrder;
95 //if last byte in current buffer is not the last byte of a character, we
96 //need to know how many byte to skip in next buffer.
97 PRUint32 mNeedToSkipCharNum;
99 //If this flag is set to PR_TRUE, detection is done and conclusion has been made
100 PRBool mDone;
104 class SJISContextAnalysis : public JapaneseContextAnalysis
106 //SJISContextAnalysis(){};
107 protected:
108 PRInt32 GetOrder(const char* str, PRUint32 *charLen);
110 PRInt32 GetOrder(const char* str)
112 //We only interested in Hiragana, so first byte is '\202'
113 if (*str == '\202' &&
114 (unsigned char)*(str+1) >= (unsigned char)0x9f &&
115 (unsigned char)*(str+1) <= (unsigned char)0xf1)
116 return (unsigned char)*(str+1) - (unsigned char)0x9f;
117 return -1;
121 class EUCJPContextAnalysis : public JapaneseContextAnalysis
123 protected:
124 PRInt32 GetOrder(const char* str, PRUint32 *charLen);
125 PRInt32 GetOrder(const char* str)
126 //We only interested in Hiragana, so first byte is '\244'
128 if (*str == '\244' &&
129 (unsigned char)*(str+1) >= (unsigned char)0xa1 &&
130 (unsigned char)*(str+1) <= (unsigned char)0xf3)
131 return (unsigned char)*(str+1) - (unsigned char)0xa1;
132 return -1;
136 #endif /* __JPCNTX_H__ */