Use WriteEncodedText() for line endings

patch by <zooba at aanet dot com dot au>
tested by amine48rz
See issue #3989 for more details.

svn path=/trunk/; revision=38934
This commit is contained in:
Christoph von Wittich 2009-01-19 11:13:31 +00:00
parent fb62d9e954
commit a4ecb02e06

View file

@ -313,9 +313,8 @@ done:
BOOL WriteText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, int iEncoding, int iEoln) BOOL WriteText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, int iEncoding, int iEoln)
{ {
WCHAR wcBom; WCHAR wcBom;
BYTE bEoln[2]; LPCWSTR pszLF = L"\n";
LPBYTE pbEoln = NULL; DWORD dwPos, dwNext;
DWORD dwDummy, dwPos, dwNext, dwEolnSize = 0;
/* Write the proper byte order marks if not ANSI */ /* Write the proper byte order marks if not ANSI */
if (iEncoding != ENCODING_ANSI) if (iEncoding != ENCODING_ANSI)
@ -325,29 +324,6 @@ BOOL WriteText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, int iEncoding, in
return FALSE; 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; dwPos = 0;
/* pszText eoln are always \r\n */ /* pszText eoln are always \r\n */
@ -363,14 +339,36 @@ BOOL WriteText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, int iEncoding, in
dwNext++; dwNext++;
} }
/* Write text (without eoln) */
if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, iEncoding))
return FALSE;
/* Write eoln */
if (dwNext != dwTextLen) 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; return FALSE;
} }