X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4c43dd9078b2f9f8bb280020a878932272d0163e..dfd468aafd8c2b0c6db2c8d56ddca04e26c45715:/src/xml/xml.cpp diff --git a/src/xml/xml.cpp b/src/xml/xml.cpp index 619f93ab51..25ffc91ea9 100644 --- a/src/xml/xml.cpp +++ b/src/xml/xml.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: xml.cpp +// Name: src/xml/xml.cpp // Purpose: wxXmlDocument - XML parser & data holder class // Author: Vaclav Slavik // Created: 2000/03/05 @@ -15,21 +15,24 @@ #pragma hdrstop #endif +#if wxUSE_XML + #include "wx/xml/xml.h" -#if wxUSE_XML +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/log.h" + #include "wx/app.h" +#endif #include "wx/wfstream.h" #include "wx/datstrm.h" #include "wx/zstream.h" -#include "wx/log.h" -#include "wx/intl.h" #include "wx/strconv.h" #include "expat.h" // from Expat // DLL options compatibility check: -#include "wx/app.h" WX_CHECK_BUILD_OPTIONS("wxXML") @@ -365,29 +368,30 @@ bool wxXmlDocument::Save(const wxString& filename) const - process all elements, including CDATA */ -// converts Expat-produced string in UTF-8 into wxString. -inline static wxString CharToString(wxMBConv *conv, +// converts Expat-produced string in UTF-8 into wxString using the specified +// conv or keep in UTF-8 if conv is NULL +static wxString CharToString(wxMBConv *conv, const char *s, size_t len = wxSTRING_MAXLEN) { #if wxUSE_UNICODE - (void)conv; + wxUnusedVar(conv); + return wxString(s, wxConvUTF8, len); -#else +#else // !wxUSE_UNICODE if ( conv ) { - size_t nLen = (len != wxSTRING_MAXLEN) ? len : - wxConvUTF8.MB2WC((wchar_t*) NULL, s, 0); + // there can be no embedded NULs in this string so we don't need the + // output length, it will be NUL-terminated + const wxWCharBuffer wbuf( + wxConvUTF8.cMB2WC(s, len == wxSTRING_MAXLEN ? wxNO_LEN : len, NULL)); - wchar_t *buf = new wchar_t[nLen+1]; - wxConvUTF8.MB2WC(buf, s, nLen); - buf[nLen] = 0; - wxString str(buf, *conv, len); - delete[] buf; - return str; + return wxString(wbuf, *conv); } - else + else // already in UTF-8, no conversion needed + { return wxString(s, len != wxSTRING_MAXLEN ? len : strlen(s)); -#endif + } +#endif // wxUSE_UNICODE/!wxUSE_UNICODE } struct wxXmlParsingContext