Re: [v][sf]printf additions (#, E, g, G)
| From: | Gwynne | Date: | Mon, 24 Jul 2006 01:00:06 +0000 |
| Subject: | Re: [v][sf]printf additions (#, E, g, G) | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-24915@lists.php.net to get a copy of this message | ||
On Jul 23, 2006, at 5:38 AM, Matt W wrote:
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."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):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. :-)n The number of characters written so far is stored intothe inte-ger indicated by the int * (or variant) pointerargument. Noargument is converted.Any chance of getting this into PHP? I can provide a patch.