Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51690 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87438 invoked from network); 15 Mar 2011 09:35:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2011 09:35:12 -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:17153] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 54/6B-10215-BC23F7D4 for ; Tue, 15 Mar 2011 04:35:09 -0500 Message-ID: <54.6B.10215.BC23F7D4@pb1.pair.com> To: internals@lists.php.net Date: Tue, 15 Mar 2011 09:35:03 +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> In-Reply-To: Content-Type: text/plain; charset=UTF-8; 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) Hi Sebastian, Since Etienne brought it up, would it not also make sense for you to implement countWords() and countBytes()? Also, unicode issues aside, it might still be nice to implement countChars(). And finally, so that it provides all most of the functionality of the GNU wc program, there could also be getMaxLineLength(). This would need a different name however as this method would be to count the longest line of the file rather than indicate the maximum length of a line to read as the current SplFileObject::getMaxLineLen() method does. Just my thoughts, Nick On 14/03/11 22:24, Sebastian Marek wrote: > Hello, > > That makes perfect sense. I have raised a feature request and have attached > a patch containing both countLines() method implementation and phpt tests. > > thx > > On Sun, Mar 13, 2011 at 9:39 PM, Etienne Kneuss wrote: > >> On Mar 11 23:22:04, Sebastian Marek wrote: >>> Hi, >>> >>> I have recently used SplFileObject to work with files. I was lacking a >> bit >>> of functionality in there regarding counting number of lines in a given >>> file. Although I could just load contents of the file to an array and >> check >>> it size, I thought it would be nice to have SplFileObject Countable. >>> >>> Here is an example implementation I made tonight that seems to work well >> - >>> https://gist.github.com/866767 . Is it something you think would be >> worth >>> adding to the existing SplFileObject? Is the implementation any good? I >>> reused some of the existing logic to avoid breaking >> 'spl_filesystem_object' >>> internal integrity, but maybe it would make sense to make it work with >> the >>> stream itself. >> >> In my oppinion, it does not make sense to implement countable for this >> use. Countable should be implemented on classes where calling count() on >> them is not ambiguous, i.e. the size of a collection. >> >> There is no reason why count() on a file should be the number of lines, >> why not words, or bytes? >> >> I'd however be happy with a new countLines() method. >> >> Best, >> >>> >>> If it's fine I can write some unit tests to cover this and then submit a >>> complete patch. >>> >>> Regards >>> -- >>> Sebastian Marek >>> proofek@gmail.com >>> >>> Follow me online at: >>> Blog: http://criticallog.thornet.net/ >>> Twitter: http://twitter.com/proofek >>> Linkedin: http://uk.linkedin.com/in/sebastianmarek >>> Ohloh: http://www.ohloh.net/accounts/proofek >>> >> > > >