[Issue 9045] Feature request for std.asscii => function isNewline

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Nov 18 23:28:18 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9045



--- Comment #5 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-11-18 23:28:15 PST ---
Technically speaking, if you don't know which type of line endings a file uses,
you can't possibly correctly determine when you've reached the end of a line.
Best case, you have to assume that '\r\n' and '\n' both designate the end of
the line, whereas it's perfectly legal to have a '\r' be the last character on
a line (i.e. the one before the characters indicating the end of the line) in
Linux, and it's perfectly valid to have '\n' be in the middle of line on
Windows. So, parsing with the assumption that both '\r\n' and '\n' indicate the
end of the line is actually incorrect no matter what OS you're on.

That doesn't mean that it's not entirely unreasonable to have such a function,
but it does mean that it can't possibly be 100% correct.

On an unrelated note, I'd point out that

return ( c == 0x0A || c == 0x0D )? true : false;

is redundant. The ternary operator is completely unnecessary. It would be
better if it were

return c == 0x0A || c == 0x0D;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list