virtual size_t GetMBNulLen() const { return m_conv->GetMBNulLen(); }
+ virtual wxMBConv *Clone() const { return new wxConvAuto(*this); }
+
private:
// all currently recognized BOM values
enum BOMType
#else
wxDataInputStream(wxInputStream& s);
#endif
- ~wxDataInputStream(){}
+ ~wxDataInputStream();
bool IsOk() { return m_input->IsOk(); }
wxInputStream *m_input;
bool m_be_order;
#if wxUSE_UNICODE
- wxMBConv m_conv;
+ wxMBConv *m_conv;
#endif
DECLARE_NO_COPY_CLASS(wxDataInputStream)
#else
wxDataOutputStream(wxOutputStream& s);
#endif
- ~wxDataOutputStream(){}
+ ~wxDataOutputStream();
bool IsOk() { return m_output->IsOk(); }
wxOutputStream *m_output;
bool m_be_order;
#if wxUSE_UNICODE
- wxMBConv m_conv;
+ wxMBConv *m_conv;
#endif
DECLARE_NO_COPY_CLASS(wxDataOutputStream)
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
-#ifndef _WX_WXSTRCONVH__
-#define _WX_WXSTRCONVH__
+#ifndef _WX_STRCONV_H_
+#define _WX_STRCONV_H_
#include "wx/defs.h"
#include "wx/wxchar.h"
// don't let the fact that the existing classes implement MB2WC/WC2MB() instead
// confuse you.
//
+// You also have to implement Clone() to allow copying the conversions
+// polymorphically.
+//
// And you might need to override GetMBNulLen() as well.
class WXDLLIMPEXP_BASE wxMBConv
{
virtual size_t WC2MB(char *out, const wchar_t *in, size_t outLen) const;
+ // make a heap-allocated copy of this object
+ virtual wxMBConv *Clone() const = 0;
+
// virtual dtor for any base class
virtual ~wxMBConv();
};
public:
virtual size_t MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const;
virtual size_t WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const;
+
+ virtual wxMBConv *Clone() const { return new wxMBConvLibc; }
};
#ifdef __UNIX__
{
public:
wxConvBrokenFileNames(const wxChar *charset);
+ wxConvBrokenFileNames(const wxConvBrokenFileNames& conv)
+ : m_conv(conv.m_conv ? conv.m_conv->Clone() : NULL)
+ {
+ }
virtual ~wxConvBrokenFileNames() { delete m_conv; }
virtual size_t MB2WC(wchar_t *out, const char *in, size_t outLen) const
return m_conv->GetMBNulLen();
}
+ virtual wxMBConv *Clone() const { return new wxConvBrokenFileNames(*this); }
+
private:
// the conversion object we forward to
wxMBConv *m_conv;
+
+ DECLARE_NO_ASSIGN_CLASS(wxConvBrokenFileNames)
};
#endif // __UNIX__
public:
virtual size_t MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const;
virtual size_t WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const;
+
+ virtual wxMBConv *Clone() const { return new wxMBConvUTF7; }
};
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxMBConvUTF8 : public wxMBConv
{
public:
- enum {
+ enum
+ {
MAP_INVALID_UTF8_NOT = 0,
MAP_INVALID_UTF8_TO_PUA = 1,
MAP_INVALID_UTF8_TO_OCTAL = 2
virtual size_t MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const;
virtual size_t WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const;
+ virtual wxMBConv *Clone() const { return new wxMBConvUTF8(m_options); }
+
private:
int m_options;
};
public:
virtual size_t MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const;
virtual size_t WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const;
+ virtual wxMBConv *Clone() const { return new wxMBConvUTF16LE; }
};
// ----------------------------------------------------------------------------
public:
virtual size_t MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const;
virtual size_t WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const;
+ virtual wxMBConv *Clone() const { return new wxMBConvUTF16BE; }
};
// ----------------------------------------------------------------------------
public:
virtual size_t MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const;
virtual size_t WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const;
+ virtual wxMBConv *Clone() const { return new wxMBConvUTF32LE; }
};
// ----------------------------------------------------------------------------
public:
virtual size_t MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const;
virtual size_t WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const;
+ virtual wxMBConv *Clone() const { return new wxMBConvUTF32BE; }
};
// ----------------------------------------------------------------------------
virtual size_t MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const;
virtual size_t WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const;
virtual size_t GetMBNulLen() const;
+ virtual wxMBConv *Clone() const { return new wxCSConv(*this); }
- void Clear() ;
+ void Clear();
private:
// common part of all ctors
#define wxConvertMB2WX(s) (s)
#endif // Unicode/ANSI
-#endif
- // _WX_WXSTRCONVH__
+#endif // _WX_STRCONV_H_
char m_lastBytes[10]; // stores the bytes that were read for the last character
#if wxUSE_UNICODE
- wxMBConv m_conv;
+ wxMBConv *m_conv;
#endif
bool EatEOL(const wxChar &c);
wxEOL m_mode;
#if wxUSE_UNICODE
- wxMBConv m_conv;
+ wxMBConv *m_conv;
#endif
DECLARE_NO_COPY_CLASS(wxTextOutputStream)
#if wxUSE_UNICODE
wxDataInputStream::wxDataInputStream(wxInputStream& s, const wxMBConv& conv)
- : m_input(&s), m_be_order(false), m_conv(conv)
+ : m_input(&s), m_be_order(false), m_conv(conv.Clone())
#else
wxDataInputStream::wxDataInputStream(wxInputStream& s)
: m_input(&s), m_be_order(false)
{
}
+wxDataInputStream::~wxDataInputStream()
+{
+#if wxUSE_UNICODE
+ delete m_conv;
+#endif // wxUSE_UNICODE
+}
+
#if wxHAS_INT64
wxUint64 wxDataInputStream::Read64()
{
wxCharBuffer tmp(len + 1);
m_input->Read(tmp.data(), len);
tmp.data()[len] = '\0';
- wxString ret(m_conv.cMB2WX(tmp.data()));
+ wxString ret(m_conv->cMB2WX(tmp.data()));
#else
wxString ret;
m_input->Read( wxStringBuffer(ret, len), len);
#if wxUSE_UNICODE
wxDataOutputStream::wxDataOutputStream(wxOutputStream& s, const wxMBConv& conv)
- : m_output(&s), m_be_order(false), m_conv(conv)
+ : m_output(&s), m_be_order(false), m_conv(conv.Clone())
#else
wxDataOutputStream::wxDataOutputStream(wxOutputStream& s)
: m_output(&s), m_be_order(false)
{
}
+wxDataOutputStream::~wxDataOutputStream()
+{
+#if wxUSE_UNICODE
+ delete m_conv;
+#endif // wxUSE_UNICODE
+}
+
#if wxHAS_INT64
void wxDataOutputStream::Write64(wxUint64 i)
{
void wxDataOutputStream::WriteString(const wxString& string)
{
#if wxUSE_UNICODE
- const wxWX2MBbuf buf = string.mb_str(m_conv);
+ const wxWX2MBbuf buf = string.mb_str(*m_conv);
#else
const wxWX2MBbuf buf = string.mb_str();
#endif
virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
- // classify this encoding as explained in wxMBConv::GetMBNulLen()
- // comment
+ // classify this encoding as explained in wxMBConv::GetMBNulLen() comment
virtual size_t GetMBNulLen() const;
+ virtual wxMBConv *Clone() const
+ {
+ wxMBConv_iconv *p = new wxMBConv_iconv(m_name);
+ p->m_minMBCharWidth = m_minMBCharWidth;
+ return p;
+ }
+
bool IsOk() const
{ return (m2w != ICONV_T_INVALID) && (w2m != ICONV_T_INVALID); }
// different endian-ness than the native one
static bool ms_wcNeedsSwap;
+
+ // name of the encoding handled by this conversion
+ wxString m_name;
+
// cached result of GetMBNulLen(); set to 0 meaning "unknown"
// initially
size_t m_minMBCharWidth;
bool wxMBConv_iconv::ms_wcNeedsSwap = false;
wxMBConv_iconv::wxMBConv_iconv(const wxChar *name)
+ : m_name(name)
{
m_minMBCharWidth = 0;
m_minMBCharWidth = 0;
}
+ wxMBConv_win32(const wxMBConv_win32& conv)
+ {
+ m_CodePage = conv.m_CodePage;
+ m_minMBCharWidth = conv.m_minMBCharWidth;
+ }
+
#if wxUSE_FONTMAP
wxMBConv_win32(const wxChar* name)
{
}
#endif // wxUSE_FONTMAP
- size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const
+ virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const
{
// note that we have to use MB_ERR_INVALID_CHARS flag as it without it
// the behaviour is not compatible with the Unix version (using iconv)
return len - 1;
}
- size_t WC2MB(char *buf, const wchar_t *pwz, size_t n) const
+ virtual size_t WC2MB(char *buf, const wchar_t *pwz, size_t n) const
{
/*
we have a problem here: by default, WideCharToMultiByte() may
return m_minMBCharWidth;
}
+ virtual wxMBConv *Clone() const { return new wxMBConv_win32(*this); }
+
bool IsOk() const { return m_CodePage != -1; }
private:
Init(CFStringGetSystemEncoding()) ;
}
+ wxMBConv_cocoa(const wxMBConv_cocoa& conv)
+ {
+ m_encoding = conv.m_encoding;
+ }
+
#if wxUSE_FONTMAP
wxMBConv_cocoa(const wxChar* name)
{
return nRealOutSize - 1;
}
+ virtual wxMBConv *Clone() const { return new wxMBConv_cocoa(*this); }
+
+ bool IsOk() const
+
bool IsOk() const
{
return m_encoding != kCFStringEncodingInvalidId &&
Init(CFStringGetSystemEncoding()) ;
}
+ wxMBConv_mac(const wxMBConv_mac& conv)
+ {
+ Init(conv.m_char_encoding);
+ }
+
#if wxUSE_FONTMAP
wxMBConv_mac(const wxChar* name)
{
return res ;
}
+ virtual wxMBConv *Clone() const { return wxMBConv_mac(*this); }
+
+ bool IsOk() const
bool IsOk() const
{ return m_MB2WC_converter != NULL && m_WC2MB_converter != NULL ; }
}
}
+ virtual wxMBConv *Clone() const { return new wxMBConv_wxwin(m_enc); }
+
bool IsOk() const { return m_ok; }
public:
wxTextInputStream::wxTextInputStream(wxInputStream &s,
const wxString &sep,
const wxMBConv& conv)
- : m_input(s), m_separators(sep), m_conv(conv)
+ : m_input(s), m_separators(sep), m_conv(conv.Clone())
{
memset((void*)m_lastBytes, 0, 10);
}
wxTextInputStream::~wxTextInputStream()
{
+#if wxUSE_UNICODE
+ delete m_conv;
+#endif // wxUSE_UNICODE
}
void wxTextInputStream::UngetLast()
if(m_input.LastRead() <= 0)
return wxEOT;
- int retlen = (int) m_conv.MB2WC(wbuf, m_lastBytes, 2); // returns -1 for failure
+ int retlen = (int) m_conv->MB2WC(wbuf, m_lastBytes, 2); // returns -1 for failure
if(retlen >= 0) // res == 0 could happen for '\0' char
return wbuf[0];
}
wxTextOutputStream::wxTextOutputStream(wxOutputStream& s,
wxEOL mode,
const wxMBConv& conv)
- : m_output(s), m_conv(conv)
+ : m_output(s), m_conv(conv.Clone())
#else
wxTextOutputStream::wxTextOutputStream(wxOutputStream& s, wxEOL mode)
: m_output(s)
wxTextOutputStream::~wxTextOutputStream()
{
+#if wxUSE_UNICODE
+ delete m_conv;
+#endif // wxUSE_UNICODE
}
void wxTextOutputStream::SetMode(wxEOL mode)
// We must not write the trailing NULL here
#if wxUSE_UNICODE
- wxCharBuffer buffer = m_conv.cWC2MB( out );
+ wxCharBuffer buffer = m_conv->cWC2MB( out );
m_output.Write( (const char*) buffer, strlen( (const char*) buffer ) );
#else
m_output.Write(out.c_str(), out.length() );
wxTextOutputStream& wxTextOutputStream::PutChar(wxChar c)
{
#if wxUSE_UNICODE
- WriteString( wxString(&c, m_conv, 1) );
+ WriteString( wxString(&c, *m_conv, 1) );
#else
WriteString( wxString(&c, wxConvLocal, 1) );
#endif
wxTextOutputStream& wxTextOutputStream::operator<<(wchar_t wc)
{
- WriteString( wxString(&wc, m_conv, 1) );
+ WriteString( wxString(&wc, *m_conv, 1) );
return *this;
}