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

Ticket #978 (closed defect: wontfix)

Opened 12 years ago

Last modified 11 years ago

No way to specify variable width or precision in format strings

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

Description

With good old printf, you can do something like the following:

printf("%*d", width, i);

Which is like Tango's {0:d4}, except that the width specifier, here 4, is a variable, width in the above. I can't find a way of doing this currently in Tango, without jumping through hoops and doing it manually.

The same should be supported for precision, with floating-point arguments.

Change History

03/14/08 01:56:37 changed by kris

  • milestone set to 0.99.6.

It becomes tricky (for the user) to do this properly, given the support for argument indexing (e.g. "{1} {0}"). For floating point you can always call Float.format() directly, though I agree that's not quite as convenient

04/18/08 05:01:13 changed by kris

  • status changed from new to closed.
  • resolution set to wontfix.

We'll have to find a different way to handle this

04/18/08 18:07:32 changed by larsivi

If we want to find a solution for this, shouldn't it be kept open?

04/27/08 07:55:51 changed by larsivi

  • status changed from closed to reopened.
  • resolution deleted.
  • milestone changed from 0.99.6 to 1.0.

05/24/08 19:25:22 changed by larsivi

  • keywords set to triage.

One possibility would be to disallow indexing in format strings where variable spec is used.

Another is to just keep the var width specification parameter out of the counting for the index, or count it as other parameters, the user still needs to know the index of the parameters to use the indexing feature, and so if he also use the var width feature he must know the index of that.

05/25/08 18:29:50 changed by kris

What you described (above) seems overly complex, larsivi. I feel that the benefit of this feature is not worth the complexity trade-off, especially when there's a reasonable (if not quite as convenient) workaround. I suppose one might ask how C# and/or ICU support this notion?

06/09/08 03:49:18 changed by kris

  • status changed from reopened to closed.
  • resolution set to wontfix.

I can't see a robust means of doing this, so it'll have to fall by the wayside. Sorry :(