X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/574c939ef1c1b835a8bc65c0fe724548fa04ec49..b63fce942f8d195c42863f28ad41af750273fb47:/contrib/src/xrc/xml.cpp diff --git a/contrib/src/xrc/xml.cpp b/contrib/src/xrc/xml.cpp index 32ee02a04b..b8b8aabec8 100644 --- a/contrib/src/xrc/xml.cpp +++ b/contrib/src/xrc/xml.cpp @@ -10,7 +10,6 @@ #ifdef __GNUG__ #pragma implementation "xml.h" -#pragma implementation "xmlio.h" #endif // For compilers that support precompilation, includes "wx.h". @@ -274,6 +273,14 @@ bool wxXmlNode::DeleteProperty(const wxString& name) // 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) : wxObject(), m_root(NULL) { @@ -353,8 +360,9 @@ inline static wxString CharToString(wxMBConv *conv, wchar_t *buf = new wchar_t[nLen+1]; wxConvUTF8.MB2WC(buf, s, nLen); buf[nLen] = 0; + wxString str(buf, *conv, len); delete[] buf; - return wxString(buf, *conv, len); + return str; } else return wxString(s, len); @@ -464,26 +472,29 @@ static void DefaultHnd(void *userData, const char *s, int len) } 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 // is to let wxCSConv convert as string containing all characters to // wide character representation: wxCSConv conv(wxString(name, wxConvLibc)); - char mbBuf[255]; - wchar_t wcBuf[255]; + char mbBuf[2]; + wchar_t wcBuf[10]; size_t i; - for (i = 0; i < 255; i++) - mbBuf[i] = (char) (i+1); - mbBuf[255] = 0; - conv.MB2WC(wcBuf, mbBuf, 255); - wcBuf[255] = 0; - + mbBuf[1] = 0; info->map[0] = 0; 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->convert = NULL; info->release = NULL; @@ -520,6 +531,7 @@ bool wxXmlDocument::Load(wxInputStream& stream, const wxString& encoding) XML_SetDefaultHandler(parser, DefaultHnd); XML_SetUnknownEncodingHandler(parser, UnknownEncodingHnd, NULL); + bool ok = true; do { size_t len = stream.Read(buf, BUFSIZE).LastRead(); @@ -529,13 +541,17 @@ bool wxXmlDocument::Load(wxInputStream& stream, const wxString& encoding) wxLogError(_("XML parsing error: '%s' at line %d"), XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); - return FALSE; + ok = false; + break; } } while (!done); - SetVersion(ctx.version); - SetFileEncoding(ctx.encoding); - SetRoot(ctx.root); + if (ok) + { + SetVersion(ctx.version); + SetFileEncoding(ctx.encoding); + SetRoot(ctx.root); + } XML_ParserFree(parser); #if !wxUSE_UNICODE @@ -543,7 +559,7 @@ bool wxXmlDocument::Load(wxInputStream& stream, const wxString& encoding) delete ctx.conv; #endif - return TRUE; + return ok; }