| 1 |
unit CustomDetector; |
| 2 |
|
| 3 |
interface |
| 4 |
uses |
| 5 |
{$I dbg.inc} |
| 6 |
nscore; |
| 7 |
|
| 8 |
|
| 9 |
type |
| 10 |
TCustomDetector = class(TObject) |
| 11 |
protected |
| 12 |
mState: eProbingState; |
| 13 |
mEnabled: Boolean; |
| 14 |
|
| 15 |
// procedure Init; virtual; abstract; |
| 16 |
procedure SetEnabled(NewValue: Boolean); virtual; |
| 17 |
function GetEnabled: Boolean; virtual; |
| 18 |
public |
| 19 |
constructor Create; virtual; |
| 20 |
function GetDetectedCharset: eInternalCharsetID; virtual; abstract; |
| 21 |
function HandleData(aBuf: pAnsiChar; aLen: integer): eProbingState; virtual; |
| 22 |
function GetState: eProbingState; virtual; |
| 23 |
function GetConfidence: float; virtual; abstract; |
| 24 |
procedure Reset; virtual; |
| 25 |
{$ifdef DEBUG_chardet} |
| 26 |
procedure DumpStatus(Dump: string); virtual; |
| 27 |
{$endif} |
| 28 |
|
| 29 |
property Enabled: Boolean read GetEnabled write SetEnabled; |
| 30 |
end; |
| 31 |
|
| 32 |
implementation |
| 33 |
{ TCustomDetector } |
| 34 |
|
| 35 |
constructor TCustomDetector.Create; |
| 36 |
begin |
| 37 |
mEnabled := true; |
| 38 |
end; |
| 39 |
|
| 40 |
function TCustomDetector.GetEnabled: Boolean; |
| 41 |
begin |
| 42 |
Result := mEnabled; |
| 43 |
end; |
| 44 |
|
| 45 |
procedure TCustomDetector.SetEnabled(NewValue: Boolean); |
| 46 |
begin |
| 47 |
mEnabled := NewValue; |
| 48 |
end; |
| 49 |
|
| 50 |
function TCustomDetector.GetState: eProbingState; |
| 51 |
begin |
| 52 |
Result := mState; |
| 53 |
end; |
| 54 |
|
| 55 |
function TCustomDetector.HandleData(aBuf: pAnsiChar; aLen: integer): eProbingState; |
| 56 |
begin |
| 57 |
if not mEnabled then |
| 58 |
begin |
| 59 |
mState := psNotMe; |
| 60 |
end; |
| 61 |
Result := mState; |
| 62 |
end; |
| 63 |
|
| 64 |
procedure TCustomDetector.Reset; |
| 65 |
begin |
| 66 |
mState := psDetecting; |
| 67 |
end; |
| 68 |
|
| 69 |
{$ifdef DEBUG_chardet} |
| 70 |
procedure TCustomDetector.DumpStatus(Dump: string); |
| 71 |
begin |
| 72 |
addDump(Dump); |
| 73 |
end; |
| 74 |
{$endif} |
| 75 |
|
| 76 |
end. |
| 77 |
|
| 78 |
|
| 79 |
|