[Bf-committers] unixNewLine and winNewLine
Alexander Ewering
bf-committers@blender.org
Thu, 20 Nov 2003 19:59:39 +0100 (CET)
Hi theeth and the rest,
uhm, just stumbled over the unixNewLine and winNewLine
functions accidentally, and figured they could need some
cleanup... Here are my versions (they are quite a bit
faster, too):
char *unixNewLine(char *buffer)
{
char *p, *p2, *output;
/* we can afford the few extra bytes */
output= MEM_callocN(strlen(buffer)+1, "unixnewline");
for (p= buffer, p2= output; *p; p++)
if (*p != '\r') *(p2++)= *p;
*p2= 0;
return(output);
}
char *winNewLine(char *buffer)
{
char *p, *p2, *output;
int add= 0;
for (p= buffer; *p; p++)
if (*p == '\n') add++;
bufferlength= p-buffer+add+1;
output= MEM_callocN(bufferlength, "winnewline");
for (p= buffer, p2= output; *p; p++, p2++) {
if (*p == '\n') {
*(p2++)= '\r'; *p2= '\n';
} else *p2= *p;
}
*p2= 0;
return(output);
}
| alexander ewering instinctive new media
| ae[@]instinctive[.]de http://www[.]instinctive[.]de