Replacement for snprintf

Jacob Carlborg doob at
Fri Nov 1 13:01:21 UTC 2019

On Thursday, 31 October 2019 at 15:58:08 UTC, H. S. Teoh wrote:

> Which leads me to think that these two should be separate 
> format specifiers.

I would put the localization in a completely different function.

> Unfortunately, I can see how this would force format() to be 
> impure, because to support checking the current locale implies 
> accessing global state, which is impure.

You could pass in the locale to the function, then it can be 
pure. Even more reason to have it as a separate function. I would 
say that should be best practice because you might want to run a 
program in a different locale than the global configured one.

I'm not sure if it's enough to look at the locale. On my computer 
(a Mac) I have configured it to have the language in English but 
the date, time, number and currency format to Swedish.

/Jacob Carlborg

More information about the Digitalmars-d mailing list