File indexing completed on 2024-04-28 03:53:03

0001 /*  -*- C++ -*-
0002     SPDX-FileCopyrightText: 1998 Netscape Communications Corporation <developer@mozilla.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #ifndef nsCharSetProber_h__
0008 #define nsCharSetProber_h__
0009 
0010 #include "kencodingprober.h"
0011 
0012 namespace kencodingprober
0013 {
0014 typedef enum {
0015     eDetecting = 0, // We are still detecting, no sure answer yet, but caller can ask for confidence.
0016     eFoundIt = 1, // That's a positive answer
0017     eNotMe = 2, // Negative answer
0018 } nsProbingState;
0019 
0020 #define SHORTCUT_THRESHOLD (float)0.95
0021 
0022 class KCODECS_NO_EXPORT nsCharSetProber
0023 {
0024 public:
0025     virtual ~nsCharSetProber()
0026     {
0027     }
0028     virtual const char *GetCharSetName() = 0;
0029     virtual nsProbingState HandleData(const char *aBuf, unsigned int aLen) = 0;
0030     virtual nsProbingState GetState(void) = 0;
0031     virtual void Reset(void) = 0;
0032     virtual float GetConfidence(void) = 0;
0033     virtual void SetOpion() = 0;
0034 
0035 #ifdef DEBUG_PROBE
0036     void DumpStatus() override
0037     {
0038     }
0039 #endif
0040 
0041     // Helper functions used in the Latin1 and Group probers.
0042     // both functions Allocate a new buffer for newBuf. This buffer should be
0043     // freed by the caller using PR_FREEIF.
0044     // Both functions return false in case of memory allocation failure.
0045     static bool FilterWithoutEnglishLetters(const char *aBuf, unsigned int aLen, char **newBuf, unsigned int &newLen);
0046     static bool FilterWithEnglishLetters(const char *aBuf, unsigned int aLen, char **newBuf, unsigned int &newLen);
0047 };
0048 }
0049 #endif /* nsCharSetProber_h__ */