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@list.inf.unibe.ch
https://www.list.inf.unibe.ch/listinfo/moose-dev