1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxConvAuto class declaration
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2006 Vadim Zeitlin
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_CONVAUTO_H_
12 #define _WX_CONVAUTO_H_
14 #include "wx/strconv.h"
18 // ----------------------------------------------------------------------------
19 // wxConvAuto: uses BOM to automatically detect input encoding
20 // ----------------------------------------------------------------------------
22 class WXDLLIMPEXP_BASE wxConvAuto
: public wxMBConv
25 // default ctor, the real conversion will be created on demand
26 wxConvAuto() { m_conv
= NULL
; /* the rest will be initialized later */ }
28 // copy ctor doesn't initialize anything neither as conversion can only be
29 // deduced on first use
30 wxConvAuto(const wxConvAuto
& WXUNUSED(other
)) : wxMBConv() { m_conv
= NULL
; }
32 virtual ~wxConvAuto() { if ( m_conv
&& m_ownsConv
) delete m_conv
; }
34 // override the base class virtual function(s) to use our m_conv
35 virtual size_t ToWChar(wchar_t *dst
, size_t dstLen
,
36 const char *src
, size_t srcLen
= wxNO_LEN
) const;
38 virtual size_t FromWChar(char *dst
, size_t dstLen
,
39 const wchar_t *src
, size_t srcLen
= wxNO_LEN
) const;
41 virtual size_t GetMBNulLen() const { return m_conv
->GetMBNulLen(); }
43 virtual wxMBConv
*Clone() const { return new wxConvAuto(*this); }
46 // all currently recognized BOM values
57 // return the BOM type of this buffer
58 static BOMType
DetectBOM(const char *src
, size_t srcLen
);
60 // initialize m_conv with the conversion to use by default (UTF-8)
61 void InitWithDefault()
67 // create the correct conversion object for the given BOM type
68 void InitFromBOM(BOMType bomType
);
70 // create the correct conversion object for the BOM present in the
71 // beginning of the buffer; adjust the buffer to skip the BOM if found
72 void InitFromInput(const char **src
, size_t *len
);
74 // adjust src and len to skip over the BOM (identified by m_bomType) at the
75 // start of the buffer
76 void SkipBOM(const char **src
, size_t *len
) const;
79 // conversion object which we really use, NULL until the first call to
80 // either ToWChar() or FromWChar()
86 // true if we allocated m_conv ourselves, false if we just use an existing
90 // true if we already skipped BOM when converting (and not just calculating
95 DECLARE_NO_ASSIGN_CLASS(wxConvAuto
)
98 #endif // wxUSE_WCHAR_T
100 #endif // _WX_CONVAUTO_H_