From: Nicholas Clark Date: Mon, 23 Oct 2006 18:19:51 +0000 (+0100) Subject: Add a %B sprintf format X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7ff06cc7c932ea693a5ea6b94f95570a9d4548b5;p=p5sagit%2Fp5-mst-13.2.git Add a %B sprintf format Subject: Re: [perl #40583] sprintf "%#04X" also uppercases the 0x-prefix Message-ID: <20061023171951.GA3262@plum.flirble.org> (plus docs) p4raw-id: //depot/perl@29104 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 3920153..ab3b0e1 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -5516,6 +5516,7 @@ In addition, Perl permits the following widely-supported conversions: %E like %e, but using an upper-case "E" %G like %g, but with an upper-case "E" (if applicable) %b an unsigned integer, in binary + %B like %x, but using an upper-case "B" with the # flag %p a pointer (outputs the Perl value's address in hexadecimal) %n special: *stores* the number of characters output so far into the next variable in the parameter list @@ -5558,7 +5559,7 @@ one or more of: - left-justify within the field 0 use zeros, not spaces, to right-justify # prefix non-zero octal with "0", non-zero hex with "0x" - or "0X", non-zero binary with "0b" + or "0X", non-zero binary with "0b" or "OB" For example: diff --git a/sv.c b/sv.c index f5d9cb6..e38d4b7 100644 --- a/sv.c +++ b/sv.c @@ -9039,6 +9039,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV base = 10; goto uns_integer; + case 'B': case 'b': base = 2; goto uns_integer; @@ -9132,7 +9133,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV } while (uv >>= 1); if (tempalt) { esignbuf[esignlen++] = '0'; - esignbuf[esignlen++] = 'b'; + esignbuf[esignlen++] = c; } break; default: /* it had better be ten or less */ diff --git a/t/op/sprintf.t b/t/op/sprintf.t index 11eeee4..6751a86 100755 --- a/t/op/sprintf.t +++ b/t/op/sprintf.t @@ -171,7 +171,9 @@ __END__ >%6 .6s< >''< >%6 .6s INVALID< >%6.6 s< >''< >%6.6 s INVALID< >%A< >''< >%A INVALID< ->%B< >''< >%B INVALID< +>%B< >2**32-1< >11111111111111111111111111111111< +>%+B< >2**32-1< >11111111111111111111111111111111< +>%#B< >2**32-1< >0B11111111111111111111111111111111< >%C< >''< >%C INVALID< >%D< >0x7fffffff< >2147483647< >Synonym for %ld< >%E< >123456.789< >1.234568E+05< >Like %e, but using upper-case "E"<