-
Notifications
You must be signed in to change notification settings - Fork 6
/
Detector.cs
61 lines (51 loc) · 1.17 KB
/
Detector.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Created by SharpDevelop.
* User: Administrator
* Date: 2006-12-16
* Time: 3:08
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
namespace NChardet
{
/// <summary>
/// Description of Detector.
/// </summary>
public class Detector : PSMDetector,ICharsetDetector
{
ICharsetDetectionObserver mObserver = null ;
public Detector():base()
{
}
public Detector(int langFlag):base(langFlag)
{
}
public void Init(ICharsetDetectionObserver aObserver) {
mObserver = aObserver ;
return ;
}
public bool DoIt(byte[] aBuf, int aLen, bool oDontFeedMe) {
if (aBuf == null || oDontFeedMe )
return false ;
this.HandleData(aBuf, aLen) ;
return mDone ;
}
public void Done() {
this.DataEnd() ;
return ;
}
public override void Report(string charset) {
if (mObserver != null)
mObserver.Notify(charset) ;
}
public bool isAscii(byte[] aBuf, int aLen) {
for(int i=0; i<aLen; i++) {
if ((0x0080 & aBuf[i]) != 0) {
return false ;
}
}
return true ;
}
}
}