Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:24915 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52823 invoked by uid 1010); 24 Jul 2006 01:20:48 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 52808 invoked from network); 24 Jul 2006 01:20:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jul 2006 01:20:48 -0000 X-PHP-List-Original-Sender: gwynne@skytag.com X-Host-Fingerprint: 208.97.132.62 sd-green-bigip-62.dreamhost.com Linux 2.4/2.6 Received: from ([208.97.132.62:39099] helo=spunkymail-a17.dreamhost.com) by pb1.pair.com (ecelerity 2.1.1.3 r(11751M)) with ESMTP id E8/9E-04178-EBB14C44 for ; Sun, 23 Jul 2006 21:00:48 -0400 Received: from [192.168.0.101] (c-66-31-91-125.hsd1.ma.comcast.net [66.31.91.125]) by spunkymail-a17.dreamhost.com (Postfix) with ESMTP id 0F3FA74722; Sun, 23 Jul 2006 18:00:22 -0700 (PDT) In-Reply-To: <00a301c6ae3b$d23e2770$0201a8c0@pc1> References: <018101c6abf6$ee273810$0201a8c0@pc1> <105846538.20060720212112@marcus-boerger.de> <532686B2-88F2-4FCE-BAE1-31AE208FFE12@skytag.com> <00a301c6ae3b$d23e2770$0201a8c0@pc1> Mime-Version: 1.0 (Apple Message framework v752.2) X-Priority: 3 Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-ID: Cc: Content-Transfer-Encoding: 7bit Date: Sun, 23 Jul 2006 21:00:06 -0400 To: Matt W X-Mailer: Apple Mail (2.752.2) Subject: Re: [PHP-DEV] [v][sf]printf additions (#, E, g, G) From: gwynne@skytag.com (Gwynne) On Jul 23, 2006, at 5:38 AM, Matt W wrote: >> While we're on the subject, one of my favorite personal patches to >> PHP is one that adds the %n specifier. The parameter to %n is a >> reference which recieves the total length of the string with all >> replacements so far. %n itself is replaced by nothing at all. You >> could do this with $n = strlen( $s = sprintf( blah blah blah ) ) + >> strlen( $s .= sprintf( the rest of the blah ) );, but it's a very >> nice shortcut if you need the replaced length in the middle of the >> conversion or for a situation like this (and the above doesn't work >> too well if you have positional params!): >> >> printf( "Some processing message with %s replacements...%n", >> 'some', & >> $n ); >> // do some stuff here >> print str_repeat( ' ', $n ) . "\rSome status text here that doesn't >> worry about whether the replaced text was longer."; >> >> Here's the printf(3) manpage description for %n (MacOS X system, BSD >> manpage): >> >> n The number of characters written so far is stored into >> the inte- >> ger indicated by the int * (or variant) pointer >> argument. No >> argument is converted. >> >> Any chance of getting this into PHP? I can provide a patch. > I had thought about adding %n too, but didn't know what the > reaction would > be or if it'd be used. (And the length thing would have to be changed > [later] for Unicode length or such, I assume?) Also, wasn't sure > about the > internals code for the reference and writing to it, etc. :-) I'm completely unversed in the current Unicode stuff; I can only provide a patch against 5.2. Someone who knows the Unicode crud would have to update it for HEAD, and given the recent loud argument about HEAD vs branch commits, I don't know how well a 5.2-only patch would go over. Any advice on that point? -- Gwynne, Daughter of the Code "This whole world is an asylum for the incurable."