X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/467e04791c0d5914dc8ed8e535af607f7fc1dfe1..f2b099261f9e46d65f1fbcfd2a35aa816d5a2818:/include/wx/convauto.h?ds=inline diff --git a/include/wx/convauto.h b/include/wx/convauto.h index 1e32c72c07..bc514cea3b 100644 --- a/include/wx/convauto.h +++ b/include/wx/convauto.h @@ -12,8 +12,7 @@ #define _WX_CONVAUTO_H_ #include "wx/strconv.h" - -#if wxUSE_WCHAR_T +#include "wx/fontenc.h" // ---------------------------------------------------------------------------- // wxConvAuto: uses BOM to automatically detect input encoding @@ -23,13 +22,41 @@ class WXDLLIMPEXP_BASE wxConvAuto : public wxMBConv { public: // default ctor, the real conversion will be created on demand - wxConvAuto() { m_conv = NULL; /* the rest will be initialized later */ } + wxConvAuto(wxFontEncoding enc = wxFONTENCODING_DEFAULT) + { + Init(); + + m_encDefault = enc; + } // copy ctor doesn't initialize anything neither as conversion can only be // deduced on first use - wxConvAuto(const wxConvAuto& WXUNUSED(other)) { m_conv = NULL; } + wxConvAuto(const wxConvAuto& other) : wxMBConv() + { + Init(); + + m_encDefault = other.m_encDefault; + } + + virtual ~wxConvAuto() + { + if ( m_ownsConv ) + delete m_conv; + } + + // get/set the fall-back encoding used when the input text doesn't have BOM + // and isn't UTF-8 + // + // special values are wxFONTENCODING_MAX meaning not to use any fall back + // at all (but just fail to convert in this case) and wxFONTENCODING_SYSTEM + // meaning to use the encoding of the system locale + static wxFontEncoding GetFallbackEncoding() { return ms_defaultMBEncoding; } + static void SetFallbackEncoding(wxFontEncoding enc); + static void DisableFallbackEncoding() + { + SetFallbackEncoding(wxFONTENCODING_MAX); + } - virtual ~wxConvAuto() { if ( m_conv && m_ownsConv ) delete m_conv; } // override the base class virtual function(s) to use our m_conv virtual size_t ToWChar(wchar_t *dst, size_t dstLen, @@ -46,6 +73,7 @@ private: // all currently recognized BOM values enum BOMType { + BOM_Unknown = -1, BOM_None, BOM_UTF32BE, BOM_UTF32LE, @@ -57,8 +85,17 @@ private: // return the BOM type of this buffer static BOMType DetectBOM(const char *src, size_t srcLen); - // initialize m_conv with the conversion to use by default (UTF-8) - void InitWithDefault() + // common part of all ctors + void Init() + { + // no need to initialize m_bomType and m_consumedBOM here, this will be + // done when m_conv is created + m_conv = NULL; + m_ownsConv = false; + } + + // initialize m_conv with the UTF-8 conversion + void InitWithUTF8() { m_conv = &wxConvUTF8; m_ownsConv = false; @@ -68,18 +105,28 @@ private: void InitFromBOM(BOMType bomType); // create the correct conversion object for the BOM present in the - // beginning of the buffer; adjust the buffer to skip the BOM if found - void InitFromInput(const char **src, size_t *len); + // beginning of the buffer + // + // return false if the buffer is too short to allow us to determine if we + // have BOM or not + bool InitFromInput(const char *src, size_t len); // adjust src and len to skip over the BOM (identified by m_bomType) at the // start of the buffer void SkipBOM(const char **src, size_t *len) const; + // fall-back multibyte encoding to use, may be wxFONTENCODING_SYSTEM or + // wxFONTENCODING_MAX but not wxFONTENCODING_DEFAULT + static wxFontEncoding ms_defaultMBEncoding; + // conversion object which we really use, NULL until the first call to // either ToWChar() or FromWChar() wxMBConv *m_conv; + // the multibyte encoding to use by default if input isn't Unicode + wxFontEncoding m_encDefault; + // our BOM type BOMType m_bomType; @@ -92,10 +139,8 @@ private: bool m_consumedBOM; - DECLARE_NO_ASSIGN_CLASS(wxConvAuto); + wxDECLARE_NO_ASSIGN_CLASS(wxConvAuto); }; -#endif // wxUSE_WCHAR_T - #endif // _WX_CONVAUTO_H_