Replacement for snprintf

Andre Pany andre at s-e-a-p.de
Wed Nov 6 16:54:25 UTC 2019


On Wednesday, 6 November 2019 at 13:25:38 UTC, berni44 wrote:
> On Thursday, 31 October 2019 at 10:14:59 UTC, Guillaume Piolat 
> wrote:
>> Moreover, actual printf implementations seems to depend upon 
>> the locale. This creates bugs (say "1,4" instead of "1.4") so 
>> this behaviour depends if you want to be bug-compatible. We've 
>> been hit by that in `printed` when used with a Russian locale.
>
> Meanwhile, my implementation for the f (and F) qualifier is 
> (almost) finished. Yet, the locale-stuff is missing and I do 
> not manage to implement it. Maybe someone can help me:
>
> a) I need to create some test. As far as I know, I've to 
> execute "export LANG=de_DE.UTF-8" (in bash, debian) to make it 
> use the german locale, which should replace the dot by a comma. 
> Unfortunately writefln!"%.10f"(0.1) still writes a dot instead 
> of the expected ",". Instead of "LANG" I tried several other 
> stuff, like LC_ALL or LC_NUMERIC. Any idea what I do wrong here?
>
> b) How to query the current locale from D? Actually I only need 
> the number-separator in the current locale as a dchar. I found 
> core.stdc.locale but do not know how to use it.

This question comes late, but did you considered to just do an 1 
to 1 translation of snprintf from C to D? Of course the second 
step would be to provide an idiomatic D version with the 
mentioned suggestions.
But having a translation would already be fantastic.

Kind regards
Andre


More information about the Digitalmars-d mailing list