Internationalization support and format strings

Bruno Haible bruno at clisp.org
Tue Mar 25 11:42:47 UTC 2025


Richard (Rikki) Andrew Cattermole wrote:
>> https://github.com/dlang/phobos/issues/10711
>
> I think its more that docs are wrong here, rather than 
> implementation.

Another reason why it's better to keep a fixed order of
     Position Flags Width Precision Separator
is the runtime execution (implemented in std/format/write.d, 
function formattedWrite). This function currently processes 
width, precision, separators in that order.

Now, think of a format string such as
     "%,*.**d"
The programmer would expect that argument 1 are the separator 
digits, argument 2 is the precision, argument 3 is the width, and 
argument 4 is the value to be formatted.

If you don't change formattedWrite, it will actually use argument 
1 for the width, argument 2 for the precision, argument 3 for the 
separator digits — which doesn't match programmer expectations.

Whereas if you change formattedWrite to use the arguments in the 
order in which they were referenced in the format string, you are 
slowing down the formatting at runtime.


More information about the Digitalmars-d mailing list