wxTextFile: don't loose data with CRCRLF line endings.
Previously, when reading files with completely nonstandard - but occurring in the wild thanks to broken Notepad - files with CRCRLF, all content would be replaced with empty lines. Fix the code to do what many editors do with such files: treat this as data line followed by an empty one. This is not ideal, but it is better than discarding data - and arguably, silently cleaning up the endings wouldn't be great either (and would add extra complications for what is an obscure and broken case). See http://stackoverflow.com/questions/6998506/text-file-with-0d-0d-0a-line-breaks git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75387 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -49,6 +49,7 @@ private:
|
||||
CPPUNIT_TEST( ReadMac );
|
||||
CPPUNIT_TEST( ReadMacLast );
|
||||
CPPUNIT_TEST( ReadMixed );
|
||||
CPPUNIT_TEST( ReadCRCRLF );
|
||||
#if wxUSE_UNICODE
|
||||
CPPUNIT_TEST( ReadUTF8 );
|
||||
CPPUNIT_TEST( ReadUTF16 );
|
||||
@@ -64,6 +65,7 @@ private:
|
||||
void ReadMac();
|
||||
void ReadMacLast();
|
||||
void ReadMixed();
|
||||
void ReadCRCRLF();
|
||||
#if wxUSE_UNICODE
|
||||
void ReadUTF8();
|
||||
void ReadUTF16();
|
||||
@@ -206,6 +208,25 @@ void TextFileTestCase::ReadMixed()
|
||||
CPPUNIT_ASSERT_EQUAL( wxString(wxT("baz")), f.GetLastLine() );
|
||||
}
|
||||
|
||||
void TextFileTestCase::ReadCRCRLF()
|
||||
{
|
||||
// Notepad may create files with CRCRLF line endings (see
|
||||
// http://stackoverflow.com/questions/6998506/text-file-with-0d-0d-0a-line-breaks).
|
||||
// Older versions of wx would loose all data when reading such files.
|
||||
// Test that the data are read, but don't worry about empty lines in between or
|
||||
// line endings.
|
||||
CreateTestFile("foo\r\r\nbar\r\r\nbaz\r\r\n");
|
||||
|
||||
wxTextFile f;
|
||||
CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );
|
||||
|
||||
wxString all;
|
||||
for ( wxString str = f.GetFirstLine(); !f.Eof(); str = f.GetNextLine() )
|
||||
all += str;
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( "foobarbaz", all );
|
||||
}
|
||||
|
||||
#if wxUSE_UNICODE
|
||||
|
||||
void TextFileTestCase::ReadUTF8()
|
||||
|
Reference in New Issue
Block a user