9
9
#include "settings.h"
10
10
#include "filemanager.h"
11
11
#include <wx/fontmap.h>
12
#include "nsUniversalDetector.h"
15
16
/** Try to detect the encoding of a file on disk. */
16
class DLLIMPORT EncodingDetector
17
class DLLIMPORT EncodingDetector :
18
public nsUniversalDetector
19
EncodingDetector(const wxString& filename);
20
EncodingDetector(LoaderBase* fileLdr);
21
EncodingDetector(const wxByte* buffer, size_t size);
22
EncodingDetector(const EncodingDetector& rhs);
21
EncodingDetector(const wxString& filename, bool useLog=true);
22
EncodingDetector(LoaderBase* fileLdr, bool useLog=true);
23
EncodingDetector(const wxByte* buffer, size_t size, bool useLog=true);
24
EncodingDetector(const EncodingDetector& rhs, bool useLog=true);
23
25
~EncodingDetector();
27
const wxString& DoIt(const char* aBuf, PRUint32 aLen);
25
28
/** @return True if file was read, false if not. */
27
30
/** @return True if the file contains a BOM (Byte Order Mark), false if not. */
33
36
wxString GetWxStr() const;
35
38
/** @return True if succeeded, false if not (e.g. file didn't exist). */
36
bool DetectEncoding(const wxString& filename, bool ConvertToWxString = true);
37
bool DetectEncoding(const wxByte* buffer, size_t size, bool ConvertToWxString = true);
39
bool DetectEncoding(const wxString& filename, bool ConvertToWxString = true);
40
bool DetectEncoding(const wxByte* buffer, size_t size, bool ConvertToWxString = true);
41
void Report(const char* aCharset);
42
wxFontEncoding m_Encoding;
47
wxFontEncoding m_Encoding;
44
50
wxString m_ConvStr;
45
51
bool ConvertToWxStr(const wxByte* buffer, size_t size);
46
inline bool IsUTF8Tail(wxByte b) { return ((b & 0xC0) == 0x80); };
47
bool DetectUTF8(wxByte* byt, size_t size);
48
bool IsTextUTF16BE(wxByte *text, size_t size);
49
bool IsTextUTF16LE(wxByte *text, size_t size);
50
bool DetectUTF16(wxByte* byt, size_t size);
51
bool IsTextUTF32BE(wxByte *text, size_t size);
52
bool IsTextUTF32LE(wxByte *text, size_t size);
53
bool DetectUTF32(wxByte* byt, size_t size);
52
// static inline bool IsUTF8Tail(wxByte b) { return ((b & 0xC0) == 0x80); };
53
// bool DetectUTF8(const wxByte* byt, size_t size);
54
bool IsTextUTF16BE(const wxByte *text, size_t size);
55
bool IsTextUTF16LE(const wxByte *text, size_t size);
56
bool DetectUTF16(const wxByte* byt, size_t size);
57
bool IsTextUTF32BE(const wxByte *text, size_t size);
58
bool IsTextUTF32LE(const wxByte *text, size_t size);
59
bool DetectUTF32(const wxByte* byt, size_t size);
56
62
#endif // ENCODINGDETECTOR_H