mirror of
https://github.com/reactos/reactos.git
synced 2024-11-20 06:15:26 +00:00
Changes by Hervé Poussineau:
- Simplified code for WriteText which avoids infinite loops and fixes EOLN conversion. This fixes bug 3551 Changes by Pierre Schweitzer - Removed some non-understandable unicode code in WriteText - Added a check to prevent crash when trying to create an empty file - Fixed formatting for WriteText See issue #3551 for more details. svn path=/trunk/; revision=35018
This commit is contained in:
parent
f81b3e63d2
commit
160a7614dd
2 changed files with 67 additions and 70 deletions
|
@ -235,10 +235,13 @@ static VOID DoSaveFile(VOID)
|
|||
}
|
||||
#endif
|
||||
|
||||
if (size)
|
||||
{
|
||||
if (!WriteText(hFile, (LPWSTR)pTemp, size, Globals.iEncoding, Globals.iEoln))
|
||||
ShowLastError();
|
||||
else
|
||||
SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
|
||||
}
|
||||
|
||||
CloseHandle(hFile);
|
||||
HeapFree(GetProcessHeap(), 0, pTemp);
|
||||
|
|
|
@ -317,8 +317,7 @@ done:
|
|||
BOOL WriteText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, int iEncoding, int iEoln)
|
||||
{
|
||||
WCHAR wcBom;
|
||||
WCHAR wcEoln;
|
||||
BYTE bEoln;
|
||||
BYTE bEoln[1];
|
||||
LPBYTE pbEoln = NULL;
|
||||
DWORD dwDummy, dwPos, dwNext, dwEolnSize = 0;
|
||||
|
||||
|
@ -334,58 +333,53 @@ BOOL WriteText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, int iEncoding, in
|
|||
switch(iEoln)
|
||||
{
|
||||
case EOLN_LF:
|
||||
bEoln = '\n';
|
||||
pbEoln = &bEoln;
|
||||
dwEolnSize = sizeof(bEoln);
|
||||
bEoln[0] = '\n';
|
||||
pbEoln = (LPBYTE) &bEoln;
|
||||
dwEolnSize = 1;
|
||||
break;
|
||||
case EOLN_CR:
|
||||
bEoln = '\r';
|
||||
pbEoln = &bEoln;
|
||||
dwEolnSize = sizeof(bEoln);
|
||||
bEoln[0] = '\r';
|
||||
pbEoln = (LPBYTE) &bEoln;
|
||||
dwEolnSize = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* If we have an eoln, make sure it is of the proper encoding */
|
||||
if (pbEoln && ((iEncoding == ENCODING_UNICODE) || (iEncoding == ENCODING_UNICODE_BE)))
|
||||
{
|
||||
wcEoln = bEoln;
|
||||
pbEoln = (LPBYTE) &wcEoln;
|
||||
dwEolnSize = sizeof(wcEoln);
|
||||
case EOLN_CRLF:
|
||||
bEoln[0] = '\r';
|
||||
bEoln[1] = '\n';
|
||||
pbEoln = (LPBYTE) &bEoln;
|
||||
dwEolnSize = 2;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dwPos = 0;
|
||||
|
||||
while(dwPos < dwTextLen)
|
||||
{
|
||||
if (pbEoln)
|
||||
/* pszText eoln are always \r\n */
|
||||
|
||||
do
|
||||
{
|
||||
/* Find the next eoln */
|
||||
dwNext = dwPos;
|
||||
while(dwNext < dwTextLen-1)
|
||||
while(dwNext < dwTextLen)
|
||||
{
|
||||
if ((pszText[dwNext] == '\r') && (pszText[dwNext+1] == '\n'))
|
||||
if (pszText[dwNext] == '\r' && pszText[dwNext + 1] == '\n')
|
||||
break;
|
||||
dwNext++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No eoln conversion is necessary */
|
||||
dwNext = dwTextLen;
|
||||
}
|
||||
|
||||
/* Write text (without eoln) */
|
||||
if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, iEncoding))
|
||||
return FALSE;
|
||||
dwPos = dwNext;
|
||||
|
||||
/* are we at an eoln? */
|
||||
while ((dwPos < dwTextLen-1) &&
|
||||
((pszText[dwPos] == '\r') && (pszText[dwPos+1] == '\n')))
|
||||
/* Write eoln */
|
||||
if (dwNext != dwTextLen)
|
||||
{
|
||||
if (!WriteFile(hFile, pbEoln, dwEolnSize, &dwDummy, NULL))
|
||||
return FALSE;
|
||||
dwPos += 2;
|
||||
}
|
||||
|
||||
/* Skip \r\n */
|
||||
dwPos = dwNext + 2;
|
||||
}
|
||||
while (dwPos < dwTextLen);
|
||||
|
||||
|
|
Loading…
Reference in a new issue