- default:
- if ( chLast == '\r' ) {
- // Mac line termination
- m_aLines.Add(str);
- m_aTypes.Add(wxTextFileType_Mac);
- chLast = ch;
- str = ch;
- }
- else {
- // add to the current line
- str += ch;
- }
- }
+ // the beginning of the current line, changes inside the loop
+ wxString::const_iterator lineStart = str.begin();
+ const wxString::const_iterator end = str.end();
+ for ( wxString::const_iterator p = lineStart; p != end; p++ )
+ {
+ const wxChar ch = *p;
+ switch ( ch )
+ {
+ case '\n':
+ // could be a DOS or Unix EOL
+ if ( chLast == '\r' )
+ {
+ if ( p - 1 >= lineStart )
+ {
+ AddLine(wxString(lineStart, p - 1), wxTextFileType_Dos);
+ }
+ else
+ {
+ // there were two line endings, so add an empty line:
+ AddLine(wxEmptyString, wxTextFileType_Dos);
+ }
+ }
+ else // bare '\n', Unix style
+ {
+ AddLine(wxString(lineStart, p), wxTextFileType_Unix);
+ }
+
+ lineStart = p + 1;
+ break;
+
+ case '\r':
+ if ( chLast == '\r' )
+ {
+ // Mac empty line
+ AddLine(wxEmptyString, wxTextFileType_Mac);
+ lineStart = p + 1;
+ }
+ //else: we don't know what this is yet -- could be a Mac EOL or
+ // start of DOS EOL so wait for next char
+ break;
+
+ default:
+ if ( chLast == '\r' )
+ {
+ // Mac line termination
+ if ( p - 1 >= lineStart )
+ {
+ AddLine(wxString(lineStart, p - 1), wxTextFileType_Mac);
+ }
+ else
+ {
+ // there were two line endings, so add an empty line:
+ AddLine(wxEmptyString, wxTextFileType_Mac);
+ }
+ lineStart = p;
+ }
+ }
+
+ chLast = ch;