Fixed an XML parsing error for complex URLs

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51836 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2008-02-16 12:09:48 +00:00
parent 65db6e118e
commit 9dda10ae72

View File

@ -491,6 +491,59 @@ static void OutputStringEnt(wxOutputStream& stream, const wxString& str,
OutputString(stream, str.Mid(last, i - last), convMem, convFile);
}
static wxString AttributeToXML(const wxString& str)
{
wxString str1;
size_t i, last, len;
wxChar c;
len = str.Len();
last = 0;
for (i = 0; i < len; i++)
{
c = str.GetChar(i);
// Original code excluded "&amp;" but we _do_ want to convert
// the ampersand beginning &amp; because otherwise when read in,
// the original "&amp;" becomes "&".
if (c == wxT('<') || c == wxT('>') || c == wxT('"') ||
(c == wxT('&') /* && (str.Mid(i+1, 4) != wxT("amp;")) */ ))
{
str1 += str.Mid(last, i - last);
switch (c)
{
case wxT('<'):
str1 += wxT("&lt;");
break;
case wxT('>'):
str1 += wxT("&gt;");
break;
case wxT('&'):
str1 += wxT("&amp;");
break;
case wxT('"'):
str1 += wxT("&quot;");
break;
default: break;
}
last = i + 1;
}
else if (wxUChar(c) > 127)
{
str1 += str.Mid(last, i - last);
wxString s(wxT("&#"));
s << (int) c;
s << wxT(";");
str1 += s;
last = i + 1;
}
}
str1 += str.Mid(last, i - last);
return str1;
}
inline static void OutputIndentation(wxOutputStream& stream, int indent)
{
wxString str = wxT("\n");
@ -930,7 +983,7 @@ wxString wxRichTextXMLHandler::CreateStyle(const wxTextAttr& attr, bool isPara)
str << wxT(" characterstyle=\"") << wxString(attr.GetCharacterStyleName()) << wxT("\"");
if (attr.HasURL())
str << wxT(" url=\"") << attr.GetURL() << wxT("\"");
str << wxT(" url=\"") << AttributeToXML(attr.GetURL()) << wxT("\"");
if (isPara)
{