I think that is dangerous. You will not have the same results if you change the platform
(Windows or Mac). I think you should always consider that a line return is one char long
even if it is a CRLF.
Vincent
-----Original Message-----
From: Moose-dev [mailto:moose-dev-bounces@list.inf.unibe.ch] On Behalf Of Cyril Ferlicot
Sent: vendredi 22 septembre 2017 15:13
To: Moose-related development
Subject: [Moose-dev] FAMIXFile>>numberOfCharacters
Hi,
Here is the implémentation of FAMIXFile>>numberOfCharacters
numberOfCharacters
<MSEProperty: #numberOfCharacters type: #Number>
<MSEComment: 'Number of characters in a file.'> <derived> ^ self
lookUpPropertyNamed: #numberOfCharacters
computedAs: [
| result |
result := self fileExists
ifTrue: [ self sourceText size - self totalNumberOfLinesOfText + 1 ]
ifFalse: [ 0 ].
result max: 0 ]
I see some problems on this implémentation.
IIUC, we take the size of the source text and we remove 1 for each line return. This is
wrong because in case of CRLF the lines returns are two characters long.
I think that it would be better to have:
self sourceText lines ifEmpty: [ 0 ] ifNotEmpty: [ :lines | lines sum: #size ]
But, I do not agree with the fact that we should remove the lines returns to the number of
characters. They are characters, why should we remove them?
I propose this implémentation:
numberOfCharacters
<MSEProperty: #numberOfCharacters type: #Number>
<MSEComment: 'Number of characters in a file.'> <derived> ^ self
lookUpPropertyNamed: #numberOfCharacters computedAs: [ self sourceText size ]
This is because #sourceText already manage the case where the file exist or not.
If I have no complain, I'll do this change.
--
Cyril Ferlicot
https://ferlicot.fr
http://www.synectique.eu
2 rue Jacques Prévert 01,
59650 Villeneuve d'ascq France
_______________________________________________
Moose-dev mailing list
Moose-dev(a)list.inf.unibe.ch
https://www.list.inf.unibe.ch/listinfo/moose-dev