Fix wrong EOL mode for big files
Closes #1054, Fixes #1002 The problem is if fread() is called multiple times, then UnicodeConvertor->convert() is called multiple times, which causes m_pNewBuf to point to the last read in chunk. Then after the entire file was loaded, getEOLFormatForm(UnicodeConvertor.getNewBuf(), ...) was being used which was only trying to detect the EOL mode from the last read in chunk. If this last chunk started with \n then the file was detected as Unix line endings. The file linked from issue #1002 happened to have just the right situation where this occurred.
This commit is contained in:
parent
14edff6892
commit
2fd963d932
@ -627,15 +627,6 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc, int encodin
|
||||
|
||||
if (encoding == -1)
|
||||
{
|
||||
// 3 formats : WIN_FORMAT, UNIX_FORMAT and MAC_FORMAT
|
||||
if (nullptr != UnicodeConvertor.getNewBuf())
|
||||
{
|
||||
FormatType format = getEOLFormatForm(UnicodeConvertor.getNewBuf(), UnicodeConvertor.getNewSize(),ndds._format);
|
||||
buf->setFormat(format);
|
||||
}
|
||||
else
|
||||
buf->setFormat(ndds._format);
|
||||
|
||||
UniMode um = UnicodeConvertor.getEncoding();
|
||||
if (um == uni7Bit)
|
||||
um = (ndds._openAnsiAsUtf8) ? uniCookie : uni8Bit;
|
||||
@ -647,9 +638,10 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc, int encodin
|
||||
// Test if encoding is set to UTF8 w/o BOM (usually for utf8 indicator of xml or html)
|
||||
buf->setEncoding((encoding == SC_CP_UTF8)?-1:encoding);
|
||||
buf->setUnicodeMode(uniCookie);
|
||||
buf->setFormat(bkformat);
|
||||
}
|
||||
|
||||
buf->setFormat(bkformat);
|
||||
|
||||
//determine buffer properties
|
||||
++_nextBufferID;
|
||||
return id;
|
||||
@ -1467,6 +1459,8 @@ inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char
|
||||
{
|
||||
lenConvert = UnicodeConvertor->convert(data, lenFile);
|
||||
_pscratchTilla->execute(SCI_APPENDTEXT, lenConvert, (LPARAM)(UnicodeConvertor->getNewBuf()));
|
||||
if (format == FormatType::unknown)
|
||||
format = getEOLFormatForm(UnicodeConvertor->getNewBuf(), UnicodeConvertor->getNewSize(), FormatType::unknown);
|
||||
}
|
||||
|
||||
if (_pscratchTilla->execute(SCI_GETSTATUS) != SC_STATUS_OK)
|
||||
|
Loading…
Reference in New Issue
Block a user