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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php