Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51695 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3719 invoked from network); 15 Mar 2011 10:54:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2011 10:54:22 -0000 X-Host-Fingerprint: 93.97.160.27 93-97-160-27.zone5.bethere.co.uk Received: from [93.97.160.27] ([93.97.160.27:26673] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 46/00-03183-D554F7D4 for ; Tue, 15 Mar 2011 05:54:21 -0500 Message-ID: <46.00.03183.D554F7D4@pb1.pair.com> To: internals@lists.php.net Date: Tue, 15 Mar 2011 10:54:14 +0000 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.0 MIME-Version: 1.0 References: <20110313213928.GD4446@crousti> <54.6B.10215.BC23F7D4@pb1.pair.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 93.97.160.27 Subject: Re: [PHP-DEV] SplFileObject Countable From: php@nickpope.me.uk (Nick Pope) 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