]> git.saurik.com Git - wxWidgets.git/blobdiff - src/html/m_pre.cpp
Call Dismiss rather than Show(false) on the infobar to correct the layout.
[wxWidgets.git] / src / html / m_pre.cpp
index c69db2129d5c362a15ef0ef07b44edf03945a860..1a0ef36813be6f8df7a8f25c64c5aa332cc04cb9 100644 (file)
@@ -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 <br>.
+            // Quoting HTML spec: "A line break is defined to be a carriage
+            // return (&#x000D;), a line feed (&#x000A;), 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 << "<br>";
                 break;
+
             default:
                 out << *i;
                 break;
         }
     }
+
     return out;
 }