muconvauto.h
gehe zur Dokumentation dieser Datei
00001 
00023 
00024 // Name:        wx/convauto.h
00025 // Purpose:     wxConvAuto class declaration
00026 // Author:      Vadim Zeitlin
00027 // Created:     2006-04-03
00028 // RCS-ID:      $Id: muconvauto.h,v 1.4 2011-02-20 22:35:59 keinstein Exp $
00029 // Copyright:   (c) 2006 Vadim Zeitlin
00030 // Licence:     wxWindows licence
00032 
00033 #ifndef _MYWX_CONVAUTO_H_
00034 #define _MYWX_CONVAUTO_H_
00035 
00036 #include "wx/convauto.h"
00037 #include "wx/strconv.h"
00038 
00039 extern wxMBConv * muConvAutoFallback;
00040 
00041 #if wxUSE_WCHAR_T
00042 
00043 // ----------------------------------------------------------------------------
00044 // wxConvAuto: uses BOM to automatically detect input encoding
00045 // ----------------------------------------------------------------------------
00046 
00047 class muConvAuto : public wxMBConv
00048 {
00049 
00050 public:
00051         // default ctor, the real conversion will be created on demand
00052         muConvAuto() : wxMBConv()
00053         {
00054                 DEBUGLOG(other,_T(""));
00055                 m_conv = NULL;
00056                 m_fallback = muConvAutoFallback;
00057                 m_ownsFallback = false;
00058                 /* the rest will be initialized later */
00059         }
00060 
00061         // copy ctor doesn't initialize anything neither as conversion can only be
00062         // deduced on first use
00063 
00064         muConvAuto(const muConvAuto& other) : wxMBConv()
00065         {
00066                 DEBUGLOG(other,_T(""));
00067                 m_conv = NULL;
00068                 m_fallback = other.m_fallback->Clone();
00069                 m_ownsFallback = true;
00070         }
00071 
00072         virtual ~muConvAuto()
00073 
00074         {
00075                 DEBUGLOG(other,_T(""));
00076                 if ( m_conv && m_ownsConv ) delete m_conv;
00077                 if ( m_fallback && m_ownsFallback ) delete m_fallback;
00078         }
00079 
00080         // override the base class virtual function(s) to use our m_conv
00081         virtual size_t ToWChar(wchar_t *dst, size_t dstLen,
00082                                const char *src, size_t srcLen = wxNO_LEN) const;
00083 
00084         virtual size_t FromWChar(char *dst, size_t dstLen,
00085                                  const wchar_t *src, size_t srcLen = wxNO_LEN) const;
00086 
00087         virtual size_t GetMBNulLen() const
00088         {
00089                 DEBUGLOG(other,_T(""));
00090                 return m_conv->GetMBNulLen();
00091         }
00092 
00093         virtual wxMBConv *Clone() const
00094         {
00095                 DEBUGLOG(other,_T(""));
00096                 return new muConvAuto(*this);
00097         }
00098 
00099 private:
00100 
00101         // all currently recognized BOM values
00102         enum BOMType
00103         {
00104                 BOM_None,
00105                 BOM_UTF32BE,
00106                 BOM_UTF32LE,
00107                 BOM_UTF16BE,
00108                 BOM_UTF16LE,
00109                 BOM_UTF8
00110         };
00111 
00112         // return the BOM type of this buffer
00113 
00114         static BOMType DetectBOM(const char *src, size_t srcLen);
00115 
00116         // initialize m_conv with the conversion to use by default (UTF-8)
00117         void InitWithDefault()
00118         {
00119                 DEBUGLOG(other,_T(""));
00120                 m_conv = &wxConvUTF8;
00121                 m_ownsConv = false;
00122         }
00123 
00124         // create the correct conversion object for the given BOM type
00125         void InitFromBOM(BOMType bomType);
00126 
00127         // create the correct conversion object for the BOM present in the
00128         // beginning of the buffer; adjust the buffer to skip the BOM if found
00129         void InitFromInput(const char **src, size_t *len);
00130 
00131         // adjust src and len to skip over the BOM (identified by m_bomType) at the
00132         // start of the buffer
00133         void SkipBOM(const char **src, size_t *len) const;
00134 
00135 
00136         // conversion object which we really use, NULL until the first call to
00137         // either ToWChar() or FromWChar()
00138         wxMBConv *m_conv;
00139 
00140         // true if we allocated m_conv ourselves, false if we just use an existing
00141         // global conversion
00142         bool m_ownsConv;
00143 
00144         // fallback conversion object
00145         wxMBConv *m_fallback;
00146 
00147         // true if we allocated m_conv ourselves, false if we just use an existing
00148         // global conversion
00149         bool m_ownsFallback;
00150 
00151         // our BOM type
00152         BOMType m_bomType;
00153 
00154         // true if we already skipped BOM when converting (and not just calculating
00155         // the size)
00156         bool m_consumedBOM;
00157 
00158 
00159         DECLARE_NO_ASSIGN_CLASS(muConvAuto)
00160 };
00161 
00162 #else // !wxUSE_WCHAR_T
00163 
00164 // it doesn't matter how we define it in this case as it's unused anyhow, but
00165 // do define it to allow the code using wxConvAuto() as default argument (this
00166 // is done in many places) to compile
00167 typedef wxMBConv muConvAuto;
00168 
00169 #endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T
00170 
00171 
00172 
00173 #endif // _MYWX_CONVAUTO_H_
00174 
00175 
00176 

Erzeugt am Sun Aug 21 2011 10:51:56 für Mutabor von doxygen 1.7.4