Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #979 (closed defect: fixed)

Opened 12 years ago

Last modified 11 years ago

Style and Flags from tango.text.convert.Integer can't be specified in format strings

Reported by: Deewiant Assigned to: kris
Priority: normal Milestone: 1.0
Component: IO Version: trunk
Keywords: triage Cc:


With printf, one can do things like printf("%#X", i), which formats i as a hexadecimal number with uppercase letters and prepends "0X" to it, or printf("%+o", i), which formats i as an octal number and prepends a + to it if it is positive.

Tango's format strings lack this kind of capability, forcing one to make a temporary buffer and using the functions in tango.text.convert.Integer to do the conversion manually.

Change History

03/14/08 01:58:43 changed by kris

  • milestone set to 0.99.6.

why the temporary buffer? Isn't it possible to do format("0x{:x}", i); instead?

03/14/08 09:11:34 changed by Deewiant

For that particular case, yes. And I suppose toString and friends have their own buffers, so it's not an issue. But the main point is that format string capability doesn't exist.

Using '0x' instead of a #-style modifier has the very minor issue that if you ever need to change it to capitalize, you have two 'x's to change.

03/14/08 17:14:58 changed by kris


04/18/08 05:02:03 changed by kris

  • status changed from new to assigned.
  • milestone changed from 0.99.6 to 1.0.

05/24/08 19:26:35 changed by larsivi

  • keywords set to triage.

06/09/08 02:58:26 changed by kris

  • status changed from assigned to closed.
  • resolution set to fixed.

see #787 - format specs for integers is being revised to support what you're asking for, such as {:d8#}

Note that Layout now supports left and right truncation also. For example, {.10} truncates the output to a maximum of 10 characters, and adds a "..." to indicate this occurred. A {.-10} truncates on the left instead.