On Sun, 14 Oct 2012, Igor Stasenko wrote:
A total number of lines in string should be:
one + number of line separators found.
Explanation: a 'String cr/ crlf' stands for 'line separator'.
By definition, a separator, is thing which separates two others.. i
mean, there is no way how you can use 'separator' term
without having TWO things which it separates.
The problem is that #lines does not follows common sense:
(String empty, String cr, String empty) lines size 1
so, our line separator "separates" one thing :)
It means that we overload the definition:
- a line separator separates two lines unless it is at the end of text.
But think , how dearly this 'unless' will costs in terms of implementation!
Everywhere where you may need to handle text, you should put this
extra rule, and if you forget it,
you will be punished..
Here what various #lines produces:
( 'A' ) lines size 1
( 'A', String cr ) lines size 1 !!oops!!.
( String cr, 'A' ) lines size 2
( 'A', String cr, 'A' ) lines size 2
( 'A', String cr, 'A', String cr ) lines size 2
( 'A', String cr, 'A', String cr ) lines size 2 !!oops!!
The above two examples are the same. ;)
You may think this is fine, but lets look at the problem from another angle:
self assert: (string1, String cr, string2) lineCount >= 2
The 'string1, String cr, string2' above is an insertion operation.
We inserting a line separator between two arbitrary strings.
Now, in what universe the total number of lines may not get increased
after such insertion?
So, it is simply inconsistent. Or maybe you happy to put extra code
everywhere where you handling text, to do a special handling if last
character is line separator?
But we can avoid all that mess it in a first place, if we obey to common sense.
Read this before you do anything (wrong):
"There is also some confusion whether newlines terminate or separate
lines. If a newline is considered a separator, there will be no newline
after the last line of a file. The general convention on most systems is
to add a newline even after the last line, i.e. to treat newline as a
line terminator.[citation needed] Some programs have problems processing
the last line of a file if it is not newline terminated. Conversely,
programs that expect newline to be used as a separator will interpret a
final newline as starting a new (empty) line."
From: http://en.wikipedia.org/wiki/Newline
Levente
--
Best regards,
Igor Stasenko.