On 15/03/11 10:01, Peter Cowburn wrote:
For countBytes() how is that different from SplFileInfo's getSize() ?
As for countWords() and the others, I think this crosses the line (in
my view) over what a "File Object" should provide.

Hi Peter & Sebastian,

Bah. It isn't. Obviously that was going to exist already, but was thinking about methods looking like countXXXXX() too much :)

Perhaps you are right, Peter, on your opinions about what a "file object" should provide. I would think, in that case, that a getLineCount() shouldn't exist on the "file object" either.

Currently we have:

    SplFileInfo  -- information/metadata about a file.
         |
         V
   SplFileObject -- modify/access contents of a file.

It could make sense to subclass this to provide methods for accessing information about the contents of a file. As for a name, I'm not sure what would be best, but perhaps something like "SplFileData". Maybe someone else can come up with a better name?

Then you could have the following methods:

getByteCount() -- the same as getSize(), but for here for consistency.
getCharCount()
getLineCount()
getWordCount()
getLongestLine()

Another consideration is how these should behave if we have a binary file - am not sure what GNU wc does, but perhaps that is a starting point for deciding what should happen.

Also thought might be given to what other useful methods could be provided for getting information about the contents of a file. Some ideas (sensible or otherwise!):

getShortestLine()
getEolFormat()
setEolFormat() -- allow switching between LF, CR and CRLF.
getLineIndent() -- Could return '\t', '  ', '    ', etc.
setLineIndent()
hasEmptyLines()
hasTrailingWhiteSpace()
...

It may also make sense to cache the result while the file is not modified as some of these operations could be expensive.

Anyway - I'll stop rambling. I think this would be better than just hacking in a method for the sake of it.

Cheers,

Nick

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to