X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e767076e80df6db956bb44482594fea014e685c1..5778dedc92f6d31435aa1cda6846979a0e9ad35b:/src/xml/xml.cpp?ds=sidebyside diff --git a/src/xml/xml.cpp b/src/xml/xml.cpp index 6872113502..6c3a9e5d40 100644 --- a/src/xml/xml.cpp +++ b/src/xml/xml.cpp @@ -29,7 +29,7 @@ #include "wx/datstrm.h" #include "wx/zstream.h" #include "wx/strconv.h" -#include "wx/ptr_scpd.h" +#include "wx/scopedptr.h" #include "expat.h" // from Expat @@ -618,6 +618,17 @@ static void StartCdataHnd(void *userData) ctx->lastChild= ctx->lastAsText = textnode; } +static void EndCdataHnd(void *userData) +{ + wxXmlParsingContext *ctx = (wxXmlParsingContext*)userData; + + // we need to reset this pointer so that subsequent text nodes don't append + // their contents to this one but create new wxXML_TEXT_NODE objects (or + // not create anything at all if only white space follows the CDATA section + // and wxXMLDOC_KEEP_WHITESPACE_NODES is not used as is commonly the case) + ctx->lastAsText = NULL; +} + static void CommentHnd(void *userData, const char *data) { wxXmlParsingContext *ctx = (wxXmlParsingContext*)userData; @@ -717,7 +728,7 @@ bool wxXmlDocument::Load(wxInputStream& stream, const wxString& encoding, int fl XML_SetUserData(parser, (void*)&ctx); XML_SetElementHandler(parser, StartElementHnd, EndElementHnd); XML_SetCharacterDataHandler(parser, TextHnd); - XML_SetStartCdataSectionHandler(parser, StartCdataHnd); + XML_SetCdataSectionHandler(parser, StartCdataHnd, EndCdataHnd);; XML_SetCommentHandler(parser, CommentHnd); XML_SetDefaultHandler(parser, DefaultHnd); XML_SetUnknownEncodingHandler(parser, UnknownEncodingHnd, NULL); @@ -733,7 +744,7 @@ bool wxXmlDocument::Load(wxInputStream& stream, const wxString& encoding, int fl *wxConvCurrent); wxLogError(_("XML parsing error: '%s' at line %d"), error.c_str(), - XML_GetCurrentLineNumber(parser)); + (int)XML_GetCurrentLineNumber(parser)); ok = false; break; } @@ -783,12 +794,18 @@ bool OutputString(wxOutputStream& stream, #if wxUSE_UNICODE wxUnusedVar(convMem); + if ( !convFile ) + convFile = &wxConvUTF8; - const wxWX2MBbuf buf(str.mb_str(convFile ? *convFile : wxConvUTF8)); - if ( !buf ) + const wxScopedCharBuffer buf(str.mb_str(*convFile)); + if ( !buf.length() ) + { + // conversion failed, can't write this string in an XML file in this + // (presumably non-UTF-8) encoding return false; + } - stream.Write(buf, strlen(buf)); + stream.Write(buf, buf.length()); #else // !wxUSE_UNICODE if ( convFile && convMem ) { @@ -825,10 +842,11 @@ bool OutputStringEnt(wxOutputStream& stream, { wxChar c = str.GetChar(i); if (c == wxS('<') || c == wxS('>') || - (c == wxS('&') && str.Mid(i+1, 4) != wxS("amp;")) || + (c == wxS('&') && str.substr(i+1, 4) != wxS("amp;")) || ((flags & XML_ESCAPE_QUOTES) && c == wxS('"'))) { - if ( !OutputString(stream, str.substr(last, i), convMem, convFile) ) + if ( !OutputString(stream, str.substr(last, i - last), + convMem, convFile) ) return false; const char *escaped; @@ -858,7 +876,7 @@ bool OutputStringEnt(wxOutputStream& stream, } } - return OutputString(stream, str.substr(last, i), convMem, convFile); + return OutputString(stream, str.substr(last, i - last), convMem, convFile); } bool OutputIndentation(wxOutputStream& stream, @@ -867,7 +885,7 @@ bool OutputIndentation(wxOutputStream& stream, wxMBConv *convFile) { wxString str(wxS("\n")); - str += wxString(2*indent, wxS(' ')); + str += wxString(indent, wxS(' ')); return OutputString(stream, str, convMem, convFile); }