//转换 0A -> 0D 0A
int Lf_To_CrLf(char * sSrc, char * sDst)
{
WORD aword;
char abyte;
DWORD length = 0;
while (1)
{
aword = *(WORD *)sSrc;
abyte = aword & 0xFF;
if (abyte==0) break;
//跳过 0D 0A
if (aword==0x0A0D)
{
*(WORD *)sDst = aword;
sDst += 2;
sSrc += 2;
length += 2;
}
else
{
if (abyte==0x0A)
{
*(WORD *)sDst = 0x0A0D;
sDst += 2;
length += 2;
}
else
{
*sDst = abyte;
sDst++;
length++;
}
sSrc++;
}
}
*(WORD *)sDst = 0;
return length;
}
//转换 0D 0A -> 0A,返回新的长度
int CrLf_To_Lf(char * sSrc, char * sDst)
{
WORD aword;
char abyte;
DWORD length = 0;
while (1)
{
aword = *(WORD *)sSrc;
abyte = aword & 0xFF;
if (abyte==0) break;
if (aword==0x0A0D)
{
*sDst = 0x0A;
sSrc += 2;
}
else
{
*sDst = abyte;
sSrc++;
}
sDst++;
length++;
}
*(WORD *)sDst = 0;
return length;
}