Author: cwittich
Date: Mon Jan 19 05:13:31 2009
New Revision: 38934
URL:
http://svn.reactos.org/svn/reactos?rev=38934&view=rev
Log:
Use WriteEncodedText() for line endings
patch by <zooba at aanet dot com dot au>
tested by amine48rz
See issue #3989 for more details.
Modified:
trunk/reactos/base/applications/notepad/text.c
Modified: trunk/reactos/base/applications/notepad/text.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/notepad/…
==============================================================================
--- trunk/reactos/base/applications/notepad/text.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/notepad/text.c [iso-8859-1] Mon Jan 19 05:13:31 2009
@@ -313,9 +313,8 @@
BOOL WriteText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, int iEncoding, int iEoln)
{
WCHAR wcBom;
- BYTE bEoln[2];
- LPBYTE pbEoln = NULL;
- DWORD dwDummy, dwPos, dwNext, dwEolnSize = 0;
+ LPCWSTR pszLF = L"\n";
+ DWORD dwPos, dwNext;
/* Write the proper byte order marks if not ANSI */
if (iEncoding != ENCODING_ANSI)
@@ -323,29 +322,6 @@
wcBom = 0xFEFF;
if (!WriteEncodedText(hFile, &wcBom, 1, iEncoding))
return FALSE;
- }
-
- /* Identify the proper eoln to use */
- switch(iEoln)
- {
- case EOLN_LF:
- bEoln[0] = '\n';
- pbEoln = (LPBYTE) &bEoln;
- dwEolnSize = 1;
- break;
- case EOLN_CR:
- bEoln[0] = '\r';
- pbEoln = (LPBYTE) &bEoln;
- dwEolnSize = 1;
- break;
- case EOLN_CRLF:
- bEoln[0] = '\r';
- bEoln[1] = '\n';
- pbEoln = (LPBYTE) &bEoln;
- dwEolnSize = 2;
- break;
- default:
- return FALSE;
}
dwPos = 0;
@@ -363,14 +339,36 @@
dwNext++;
}
- /* Write text (without eoln) */
- if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, iEncoding))
- return FALSE;
-
- /* Write eoln */
if (dwNext != dwTextLen)
{
- if (!WriteFile(hFile, pbEoln, dwEolnSize, &dwDummy, NULL))
+ switch (iEoln)
+ {
+ case EOLN_LF:
+ /* Write text (without eoln) */
+ if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, iEncoding))
+ return FALSE;
+ /* Write eoln */
+ if (!WriteEncodedText(hFile, pszLF, 1, iEncoding))
+ return FALSE;
+ break;
+ case EOLN_CR:
+ /* Write text (including \r as eoln) */
+ if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos + 1,
iEncoding))
+ return FALSE;
+ break;
+ case EOLN_CRLF:
+ /* Write text (including \r\n as eoln) */
+ if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos + 2,
iEncoding))
+ return FALSE;
+ break;
+ default:
+ return FALSE;
+ }
+ }
+ else
+ {
+ /* Write text (without eoln, since this is the end of the file) */
+ if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, iEncoding))
return FALSE;
}