X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f7b64fde9be7403bbae90ed6d141bfe2ba245c87..0826c4d39a53f8691b9430207420e9d9e175a73f:/src/html/m_pre.cpp
diff --git a/src/html/m_pre.cpp b/src/html/m_pre.cpp
index c69db2129d..1a0ef36813 100644
--- a/src/html/m_pre.cpp
+++ b/src/html/m_pre.cpp
@@ -33,25 +33,42 @@ static wxString LINKAGEMODE HtmlizeLinebreaks(const wxString& str)
wxString out;
out.reserve(str.length()); // we'll certainly need at least that
- for ( wxString::const_iterator i = str.begin(); i != str.end(); ++i )
+ const wxString::const_iterator end = str.end();
+ for ( wxString::const_iterator i = str.begin(); i != end; ++i )
{
switch ( (*i).GetValue() )
{
case '<':
- while ( i != str.end() && *i != '>')
+ while ( i != end && *i != '>' )
{
out << *i++;
}
out << '>';
+ if ( i == end )
+ return out;
break;
+
+ // We need to translate any line break into exactly one
.
+ // Quoting HTML spec: "A line break is defined to be a carriage
+ // return (
), a line feed (
), or a carriage
+ // return/line feed pair."
+ case '\r':
+ {
+ wxString::const_iterator j(i + 1);
+ if ( j != end && *j == '\n' )
+ i = j;
+ }
+ // fall through
case '\n':
out << "
";
break;
+
default:
out << *i;
break;
}
}
+
return out;
}