Skip to content
Snippets Groups Projects
Commit d641a185 authored by rswindell's avatar rswindell
Browse files

Fix truncsp_lines() and it's comment block: retains line-ending format

(i.e. \r\n or \n) of original text, rather than converting to \n-terminated.
parent 53f3a2fb
No related branches found
No related tags found
No related merge requests found
......@@ -486,7 +486,8 @@ char* DLLCALL truncsp(char* str)
}
/****************************************************************************/
/* Truncates all white-space chars off end of \n-terminated lines in 'str' */
/* Truncates common white-space chars off end of \n-terminated lines in */
/* 'dst' and retains original line break format (e.g. \r\n or \n) */
/****************************************************************************/
char* DLLCALL truncsp_lines(char* dst)
{
......@@ -498,10 +499,13 @@ char* DLLCALL truncsp_lines(char* dst)
return(dst);
for(sp=src, dp=dst; *sp!=0; sp++) {
if(*sp=='\n')
if(*sp=='\n') {
while(dp!=dst
&& (*(dp-1)==' ' || *(dp-1)=='\t' || *(dp-1)=='\r') && *(dp-1)!='\n')
&& (*(dp-1)==' ' || *(dp-1)=='\t' || *(dp-1)=='\r'))
dp--;
if(sp!=src && *(sp-1)=='\r')
*(dp++)='\r';
}
*(dp++)=*sp;
}
*dp=0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment