X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6a603a10e77f719458939d117e46f7d8ed0b372b..4b5e178a4c22caac92952131632641c63821fc0c:/src/html/m_pre.cpp diff --git a/src/html/m_pre.cpp b/src/html/m_pre.cpp index b2a5cb89e5..1a0ef36813 100644 --- a/src/html/m_pre.cpp +++ b/src/html/m_pre.cpp @@ -33,26 +33,42 @@ static wxString LINKAGEMODE HtmlizeLinebreaks(const wxString& str) wxString out; out.reserve(str.length()); // we'll certainly need at least that - size_t len = str.Len(); - for (size_t i = 0; i < len; i++) + const wxString::const_iterator end = str.end(); + for ( wxString::const_iterator i = str.begin(); i != end; ++i ) { - switch ( str[i].GetValue() ) + switch ( (*i).GetValue() ) { case '<': - while (i < len && str[i] != '>') + while ( i != end && *i != '>' ) { - out << str[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 << str[i]; + out << *i; break; } } + return out; }