fixed 2 encoding handling bugs in XRC/wxrcedit (backported to 2.4)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18385 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -164,7 +164,7 @@ private:
|
|||||||
class WXXMLDLLEXPORT wxXmlDocument : public wxObject
|
class WXXMLDLLEXPORT wxXmlDocument : public wxObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxXmlDocument() : wxObject(), m_version(wxT("1.0")), m_root(NULL) {}
|
wxXmlDocument();
|
||||||
wxXmlDocument(const wxString& filename,
|
wxXmlDocument(const wxString& filename,
|
||||||
const wxString& encoding = wxT("UTF-8"));
|
const wxString& encoding = wxT("UTF-8"));
|
||||||
wxXmlDocument(wxInputStream& stream,
|
wxXmlDocument(wxInputStream& stream,
|
||||||
@@ -193,7 +193,7 @@ public:
|
|||||||
// Returns version of document (may be empty).
|
// Returns version of document (may be empty).
|
||||||
wxString GetVersion() const { return m_version; }
|
wxString GetVersion() const { return m_version; }
|
||||||
// Returns encoding of document (may be empty).
|
// Returns encoding of document (may be empty).
|
||||||
// Note: this is the encoding original fail was saved in, *not* the
|
// Note: this is the encoding original file was saved in, *not* the
|
||||||
// encoding of in-memory representation!
|
// encoding of in-memory representation!
|
||||||
wxString GetFileEncoding() const { return m_fileEncoding; }
|
wxString GetFileEncoding() const { return m_fileEncoding; }
|
||||||
|
|
||||||
@@ -207,6 +207,7 @@ public:
|
|||||||
// (same as passed to Load or ctor, defaults to UTF-8).
|
// (same as passed to Load or ctor, defaults to UTF-8).
|
||||||
// NB: this is meaningless in Unicode build where data are stored as wchar_t*
|
// NB: this is meaningless in Unicode build where data are stored as wchar_t*
|
||||||
wxString GetEncoding() const { return m_encoding; }
|
wxString GetEncoding() const { return m_encoding; }
|
||||||
|
void SetEncoding(const wxString& enc) { m_encoding = enc; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma implementation "xml.h"
|
#pragma implementation "xml.h"
|
||||||
#pragma implementation "xmlio.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// For compilers that support precompilation, includes "wx.h".
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
@@ -274,6 +273,14 @@ bool wxXmlNode::DeleteProperty(const wxString& name)
|
|||||||
// wxXmlDocument
|
// wxXmlDocument
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxXmlDocument::wxXmlDocument()
|
||||||
|
: m_version(wxT("1.0")), m_fileEncoding(wxT("utf-8")), m_root(NULL)
|
||||||
|
{
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
m_encoding = wxT("UTF-8");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
wxXmlDocument::wxXmlDocument(const wxString& filename, const wxString& encoding)
|
wxXmlDocument::wxXmlDocument(const wxString& filename, const wxString& encoding)
|
||||||
: wxObject(), m_root(NULL)
|
: wxObject(), m_root(NULL)
|
||||||
{
|
{
|
||||||
@@ -353,9 +360,9 @@ inline static wxString CharToString(wxMBConv *conv,
|
|||||||
wchar_t *buf = new wchar_t[nLen+1];
|
wchar_t *buf = new wchar_t[nLen+1];
|
||||||
wxConvUTF8.MB2WC(buf, s, nLen);
|
wxConvUTF8.MB2WC(buf, s, nLen);
|
||||||
buf[nLen] = 0;
|
buf[nLen] = 0;
|
||||||
wxString s(buf, *conv, len);
|
wxString str(buf, *conv, len);
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
return s;
|
return str;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return wxString(s, len);
|
return wxString(s, len);
|
||||||
@@ -465,25 +472,28 @@ static void DefaultHnd(void *userData, const char *s, int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int UnknownEncodingHnd(void * WXUNUSED(encodingHandlerData),
|
static int UnknownEncodingHnd(void * WXUNUSED(encodingHandlerData),
|
||||||
const XML_Char *name, XML_Encoding *info)
|
const XML_Char *name, XML_Encoding *info)
|
||||||
{
|
{
|
||||||
// We must build conversion table for expat. The easiest way to do so
|
// We must build conversion table for expat. The easiest way to do so
|
||||||
// is to let wxCSConv convert as string containing all characters to
|
// is to let wxCSConv convert as string containing all characters to
|
||||||
// wide character representation:
|
// wide character representation:
|
||||||
wxCSConv conv(wxString(name, wxConvLibc));
|
wxCSConv conv(wxString(name, wxConvLibc));
|
||||||
char mbBuf[255];
|
char mbBuf[2];
|
||||||
wchar_t wcBuf[255];
|
wchar_t wcBuf[10];
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < 255; i++)
|
mbBuf[1] = 0;
|
||||||
mbBuf[i] = (char) (i+1);
|
|
||||||
mbBuf[255] = 0;
|
|
||||||
conv.MB2WC(wcBuf, mbBuf, 255);
|
|
||||||
wcBuf[255] = 0;
|
|
||||||
|
|
||||||
info->map[0] = 0;
|
info->map[0] = 0;
|
||||||
for (i = 0; i < 255; i++)
|
for (i = 0; i < 255; i++)
|
||||||
info->map[i+1] = (int)wcBuf[i];
|
{
|
||||||
|
mbBuf[0] = (char)(i+1);
|
||||||
|
if (conv.MB2WC(wcBuf, mbBuf, 2) == (size_t)-1)
|
||||||
|
{
|
||||||
|
// invalid/undefined byte in the encoding:
|
||||||
|
info->map[i+1] = -1;
|
||||||
|
}
|
||||||
|
info->map[i+1] = (int)wcBuf[0];
|
||||||
|
}
|
||||||
|
|
||||||
info->data = NULL;
|
info->data = NULL;
|
||||||
info->convert = NULL;
|
info->convert = NULL;
|
||||||
|
@@ -164,7 +164,7 @@ private:
|
|||||||
class WXXMLDLLEXPORT wxXmlDocument : public wxObject
|
class WXXMLDLLEXPORT wxXmlDocument : public wxObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxXmlDocument() : wxObject(), m_version(wxT("1.0")), m_root(NULL) {}
|
wxXmlDocument();
|
||||||
wxXmlDocument(const wxString& filename,
|
wxXmlDocument(const wxString& filename,
|
||||||
const wxString& encoding = wxT("UTF-8"));
|
const wxString& encoding = wxT("UTF-8"));
|
||||||
wxXmlDocument(wxInputStream& stream,
|
wxXmlDocument(wxInputStream& stream,
|
||||||
@@ -193,7 +193,7 @@ public:
|
|||||||
// Returns version of document (may be empty).
|
// Returns version of document (may be empty).
|
||||||
wxString GetVersion() const { return m_version; }
|
wxString GetVersion() const { return m_version; }
|
||||||
// Returns encoding of document (may be empty).
|
// Returns encoding of document (may be empty).
|
||||||
// Note: this is the encoding original fail was saved in, *not* the
|
// Note: this is the encoding original file was saved in, *not* the
|
||||||
// encoding of in-memory representation!
|
// encoding of in-memory representation!
|
||||||
wxString GetFileEncoding() const { return m_fileEncoding; }
|
wxString GetFileEncoding() const { return m_fileEncoding; }
|
||||||
|
|
||||||
@@ -207,6 +207,7 @@ public:
|
|||||||
// (same as passed to Load or ctor, defaults to UTF-8).
|
// (same as passed to Load or ctor, defaults to UTF-8).
|
||||||
// NB: this is meaningless in Unicode build where data are stored as wchar_t*
|
// NB: this is meaningless in Unicode build where data are stored as wchar_t*
|
||||||
wxString GetEncoding() const { return m_encoding; }
|
wxString GetEncoding() const { return m_encoding; }
|
||||||
|
void SetEncoding(const wxString& enc) { m_encoding = enc; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma implementation "xml.h"
|
#pragma implementation "xml.h"
|
||||||
#pragma implementation "xmlio.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// For compilers that support precompilation, includes "wx.h".
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
@@ -274,6 +273,14 @@ bool wxXmlNode::DeleteProperty(const wxString& name)
|
|||||||
// wxXmlDocument
|
// wxXmlDocument
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxXmlDocument::wxXmlDocument()
|
||||||
|
: m_version(wxT("1.0")), m_fileEncoding(wxT("utf-8")), m_root(NULL)
|
||||||
|
{
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
m_encoding = wxT("UTF-8");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
wxXmlDocument::wxXmlDocument(const wxString& filename, const wxString& encoding)
|
wxXmlDocument::wxXmlDocument(const wxString& filename, const wxString& encoding)
|
||||||
: wxObject(), m_root(NULL)
|
: wxObject(), m_root(NULL)
|
||||||
{
|
{
|
||||||
@@ -353,9 +360,9 @@ inline static wxString CharToString(wxMBConv *conv,
|
|||||||
wchar_t *buf = new wchar_t[nLen+1];
|
wchar_t *buf = new wchar_t[nLen+1];
|
||||||
wxConvUTF8.MB2WC(buf, s, nLen);
|
wxConvUTF8.MB2WC(buf, s, nLen);
|
||||||
buf[nLen] = 0;
|
buf[nLen] = 0;
|
||||||
wxString s(buf, *conv, len);
|
wxString str(buf, *conv, len);
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
return s;
|
return str;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return wxString(s, len);
|
return wxString(s, len);
|
||||||
@@ -465,25 +472,28 @@ static void DefaultHnd(void *userData, const char *s, int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int UnknownEncodingHnd(void * WXUNUSED(encodingHandlerData),
|
static int UnknownEncodingHnd(void * WXUNUSED(encodingHandlerData),
|
||||||
const XML_Char *name, XML_Encoding *info)
|
const XML_Char *name, XML_Encoding *info)
|
||||||
{
|
{
|
||||||
// We must build conversion table for expat. The easiest way to do so
|
// We must build conversion table for expat. The easiest way to do so
|
||||||
// is to let wxCSConv convert as string containing all characters to
|
// is to let wxCSConv convert as string containing all characters to
|
||||||
// wide character representation:
|
// wide character representation:
|
||||||
wxCSConv conv(wxString(name, wxConvLibc));
|
wxCSConv conv(wxString(name, wxConvLibc));
|
||||||
char mbBuf[255];
|
char mbBuf[2];
|
||||||
wchar_t wcBuf[255];
|
wchar_t wcBuf[10];
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < 255; i++)
|
mbBuf[1] = 0;
|
||||||
mbBuf[i] = (char) (i+1);
|
|
||||||
mbBuf[255] = 0;
|
|
||||||
conv.MB2WC(wcBuf, mbBuf, 255);
|
|
||||||
wcBuf[255] = 0;
|
|
||||||
|
|
||||||
info->map[0] = 0;
|
info->map[0] = 0;
|
||||||
for (i = 0; i < 255; i++)
|
for (i = 0; i < 255; i++)
|
||||||
info->map[i+1] = (int)wcBuf[i];
|
{
|
||||||
|
mbBuf[0] = (char)(i+1);
|
||||||
|
if (conv.MB2WC(wcBuf, mbBuf, 2) == (size_t)-1)
|
||||||
|
{
|
||||||
|
// invalid/undefined byte in the encoding:
|
||||||
|
info->map[i+1] = -1;
|
||||||
|
}
|
||||||
|
info->map[i+1] = (int)wcBuf[0];
|
||||||
|
}
|
||||||
|
|
||||||
info->data = NULL;
|
info->data = NULL;
|
||||||
info->convert = NULL;
|
info->convert = NULL;
|
||||||
|
Reference in New Issue
Block a user