Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:25276 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77484 invoked by uid 1010); 10 Aug 2006 09:55:07 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 77468 invoked from network); 10 Aug 2006 09:55:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Aug 2006 09:55:06 -0000 X-PHP-List-Original-Sender: php_lists@realplain.com X-Host-Fingerprint: 69.179.208.43 msa3-mx.centurytel.net Linux 2.4/2.6 Received: from ([69.179.208.43:41790] helo=msa3-mx.centurytel.net) by pb1.pair.com (ecelerity 2.1.1.3 r(11751M)) with ESMTP id 8D/53-08715-9720BD44 for ; Thu, 10 Aug 2006 05:55:06 -0400 Received: from pc1 (d19-198.rt-bras.wnvl.centurytel.net [69.179.146.198]) by msa3-mx.centurytel.net (8.13.6/8.13.6) with SMTP id k7A9t1lo028920 for ; Thu, 10 Aug 2006 04:55:02 -0500 Message-ID: <009e01c6bc63$0cdde250$0201a8c0@pc1> To: Date: Thu, 10 Aug 2006 04:55:02 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1807 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 Subject: [PATCH] *printf additions (#, g, G), updates, etc. From: php_lists@realplain.com ("Matt W") Hi all, Here are patches to add the things to *printf() I asked about a few weeks ago. If people can look over it, test it more, commit it, whatever, that'd be great. :-) Sorry for the long message, but want to cover everything. *) Precision now works for integer type specifiers (inc. x/o/b), meaning, like in C, minimum digits (left-pad with 0s if needed). This allows the minimum "width" modifier to be used with non-zero padding at the same time. Previously, specifying precision for x/o/b resulted in *nothing*. *) Missing %E added; e/E fixes: 1) the precision for e/E was 1 less than it should be (%.4e only gave 3 decimal places), and 2) %.0e was broken because of that. *) %g and %G added, which work like in C. *) "#" modifier for alternate output form: for [eEfF] trailing zeros and decimal point are removed; this differs from C, where it includes the decimal point even if precision is 0 (easy to do in PHP already for f/F :-)). I was going keep that behavior for e/E, but thought users may also want 0 removal for %e, and this makes things more consistent. For [gG], trailing zeros are not removed (opposite of default), which is *mostly* like in C (where it always includes a decimal point). For %o, the first digit will be zero. And for [xX], 0x/0X is prefixed to a non-zero result. *) "!" modifier to always include a decimal point with float types if there otherwise wouldn't be one (because of 0 precision or trailing 0 removal): "123." or "1.e+5" for example. Probably not much interest in this, but it covers everything. :-) Is "!" an OK choice? (It has a dot at the bottom!) Besides the end-user additions, I removed unnecessary TSRMLS params from php_sprintf_append[char|double]. Removed expprec param from _appendstring (I didn't get the name...), and use negative max_width instead of expprec=0. Seems logical. And I combined the mostly duplicated _appendint/_appenduint functions. Other small changes should be obvious I think. BTW, I was also going to add %n (number of characters written is assigned to arg, suggested by list member Gwynne) and really complete *printf(), but stopped since I wasn't sure how to handle the reference part. &$var param is deprecated... How should it be done? Use ZEND_SEND_PREFER_REF in ZEND_BEGIN_ARG_INFO_EX()...? I didn't try. Not sure if that's OK with mostly "by value" args. Anyway, the patches: http://realplain.com/php/printf_additions.diff http://realplain.com/php/printf_additions_5_2.diff I will add tests for the new features to an existing .phpt file soon and update the patches. Until then, any feedback is appreciated. Let me know if you want me to change anything. Thanks! Matt