|
From: Greg C <gm...@ya...> - 2001-08-09 22:34:52
|
Here are my thoughts.
The OS-specific EOL convention can be placed in a constant string, which
is then used to match the actual EOL. Runtime interfaces can then be used
to select a specific convention.
for example (warning untested code follows):
.
.
.
feature {ANY}
eol : STRING
unix_eol : STRING is "%N"
ms_eol : STRING is "%R%N"
mac_eol : STRING is "%R"
feature make is do eol := ms_eol end -- set a default
set_unix_conventions is do eol := unix_eol end
-- and so forth.
The line reading code could even be adaptive, setting the EOL type the
first time it encounters one.
Note that you don't want to do this "once" since a program could easily
have to process files with different conventions at the same time.
If you can seek on a file, you don't necessarily have to do a manual
ungetc.
Alternatively, if you follow the read_line convention (in SE) of not
placing the EOL characters at the end of the string, you may not need to
do an ungetc or a seek to handle %R%N vs %R. Just stop processing whenever
you see the %R, remember what you saw on the last call, and then skip the
%N on the next call if it happens to be there. (The risk here is incorrect
behavior if the data expected the %R%N to actually denote two different
lines, but I think it's acceptable.)
Some programs are stupid enough to get it backwards, so it helps if the
algorithm works both ways.
On the other hand, files are generally consistent with how they use EOL
delimiters, once you figure out what it thinks an EOL is.
As for the %R being a "soft return" I'd say that this is a convention that
does not have to be immediately addressed. It would be far better to get
something that works correctly on the major platforms in a native mode,
and that has a good chance of working with files across the majaor
platforms. Anyone working with files that are too anomolous will have to
consign themselves to writing cleanup filters.
Greg
=====
http://www.geocities.com/gmc444/gregs.html
Apologies for the stupid Yahoo ad below.
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/
|