Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51692 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93688 invoked from network); 15 Mar 2011 10:03:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2011 10:03:00 -0000 Authentication-Results: pb1.pair.com header.from=petercowburn@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=petercowburn@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: petercowburn@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-iw0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:51439] helo=mail-iw0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AD/8C-10215-0593F7D4 for ; Tue, 15 Mar 2011 05:02:58 -0500 Received: by iwn3 with SMTP id 3so445216iwn.29 for ; Tue, 15 Mar 2011 03:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=qsfFGDMc1uuWiihlZz2iZH+L3cuRJJi4rQI0H43ISmw=; b=PHibTxmOd9wpdc+RKOIIic3UKVlOLQl+YHF1S2WMm5X1WaWeyoRFAoJ5u2IL7JhDm0 bpPPrmgA1EOw/gBH2OZnMFmKv212/lwWR7O9DRLbBxexN5R2i1Gq9em3+bcTIvNdNYYX jZq3rAWTcouH3/SBguPPtvGzUdR3C+vyGguQE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=EfS8lWMOP5osGn3bu/HK4D3A1DDnHtwxayw4EXMSxMvbt6fEE7e9g+b/fsWnDbkTb0 /UsQN5OvG7kK26AebAW7LZBU5tUm149901EJf/z/CXv9JLQKe/L6EiGugQ1hsCJqDk8Z db408di+Hzcr5MCBlqrVbBoyqzOnofNLefTOk= Received: by 10.231.116.92 with SMTP id l28mr10677040ibq.20.1300183326096; Tue, 15 Mar 2011 03:02:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.160.67 with HTTP; Tue, 15 Mar 2011 03:01:26 -0700 (PDT) In-Reply-To: <54.6B.10215.BC23F7D4@pb1.pair.com> References: <20110313213928.GD4446@crousti> <54.6B.10215.BC23F7D4@pb1.pair.com> Date: Tue, 15 Mar 2011 10:01:26 +0000 Message-ID: To: Nick Pope Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] SplFileObject Countable From: petercowburn@gmail.com (Peter Cowburn) Hi all, On 15 March 2011 09:35, Nick Pope wrote: > Hi Sebastian, > > Since Etienne brought it up, would it not also make sense for you to > implement countWords() and countBytes()? 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. > > 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(). =A0This 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 test= s. Having not looked at the implementation yet, I have no comments on the patch itself. However, I would prefer a "get" prefixed method name, getLineCount() or similar. >> >> thx >> >> On Sun, Mar 13, 2011 at 9:39 PM, Etienne Kneuss =A0wrote= : >> >>> 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 give= n >>>> 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 we= ll >>> >>> - >>>> >>>> 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() o= n >>> 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 >>>> >>> >> >> >> > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >