[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: LF/CR conversion
Jeff Blakeney <jeff.blakeney@a2central.com.remove-1ev-this> wrote:
> This is why I didn't finish my Applesoft program. I was trying to
> avoid using GET as it is slow. I was BLOADing the input file in
> chunks into memory but then I ran into a few problems like having to
> load the next chunk if the last character is a CR to see if the next
> character is a LF.
Instead of probing ahead, output your EOL (End-Of-Line) of choice
immediately and set an "I just read a CR" flag. The next time through
the loop, if the current character is "LF" and the "I just read a CR"
flag is set, don't output anything.
Trying some pseudo-code:
foundCR = false;
until data done
read a block of data
until block done
get char
if (char == CR)
output CR/LF/CRLF as desired
foundCR = true
else if (char == LF)
if (foundCR)
foundCR = false;
else
output CR/LF/CRLF as desired
else
foundCR = false;
output char
This should convert any type of input (CR, LF, CRLF) to any other type of
input, and avoid any hairiness from CRLF straddling buffers.
--
Send mail to fadden@fadden.com (Andy McFadden) - http://www.fadden.com/
Fight Internet Spam - http://spam.abuse.net/spam/ & http://spamcop.net/