Platform Line Termination?

R. A. Harmon harmonra at webname.com
Sun Feb 6 22:48:33 UTC 2000


At 07:40 PM 2/6/00 +0100, Bert Freudenberg wrote:
>On Sun, 6 Feb 2000, R. A. Harmon wrote:
>
>> I'm re-visiting the problem I am having with reading and writing SIF files
>> in a platform independent way.
>> 
>> I think the root of the problem is that when editing in browser window or a
>> file's contents in a FileList (?), pasting text terminated with cr into a
>> text terminated with crlf, or crlf into cr, will leave the resulting text
>> with "mixed" line termination.
>
>If it displays correctly, it has CRs in it.

Can it also have lfs?  The "mixed" line termination of both crs and crlfs
used is the problem I have.

 
>
>> This is a bigger problem that I want to tackle now, but I think I can
>> greatly mitigate it in my SIF files by manually terminating out going lines
>> with the platform convention and incoming with cr.
>
>Why don't you use CrLfFileStream?
>
>When writing to a new file it creates it in the correct platform dependend
>way. When writing to an old file, it tries to detect and preserve the
>convention used. When reading, it converts all cr/lf stuff to cr.

I've discussed this extensively with folks on the list before.  I think
CrLfFileStream tries to preserve the convention used but this does not
address the situation were two or more conventions are used.  One can end up
with "mixed" line termination were some lines have cr, some lf, and the rest
crlf.  CrLfFileStream will not, as far as I can tell, write a file with the
desired convention.  Once you get "mixed" line termination there isn't any
way I know of to programatically sort out where lines terminate.   

This problem (allowing "mixed" line termination) is too big a task for me to
solve at this time.  I'm trying to get around it by changing all incoming
lines to be terminated with cr (trivial), and outgoing with the appropriate
platform line termination.  I can then at least correct by hand those cases
where I got "mixed".


>If you still want to detect the platform, check
>CrLfFileStream>>guessDefaultLineEndConvention.

Again I think that a "mixed" will defeat it.


>Or look which FileDirectory subclass is active.

Thanks, I didn't spot this when poking around.  I think it would be a much
easier test.

And thanks to all the folks for the help.  I appreciate it.

--
Richard A. Harmon          "The only good zombie is a dead zombie"
harmonra at webname.com           E. G. McCarthy
Spencer, Iowa





More information about the Squeak-dev mailing list