Thread overview
Difference between dstring and string format specifiers support. Bug?
Nov 09, 2016
Vadim Lopatin
Nov 09, 2016
Vadim Lopatin
Nov 09, 2016
Ali Çehreli
Nov 09, 2016
Ali Çehreli
November 09, 2016
Looks like bug.
dchar[] and wchar[] format strings support less specifiers than char[]

        import std.format;
        string test1 = "%02d".format(1); // works
        assert(test1 == "01");
        dstring test2 = "%d"d.format(1); // works
        assert(test2 == "1"d);
        wstring test3 = "%02d"w.format(1); // fails
        assert(test3 == "01"w);
        dstring test4 = "%02d"d.format(1); // fails
        assert(test4 == "01"d);

November 09, 2016
On Wednesday, 9 November 2016 at 08:21:53 UTC, Vadim Lopatin wrote:
> Looks like bug.
> dchar[] and wchar[] format strings support less specifiers than char[]
>
>         import std.format;
>         string test1 = "%02d".format(1); // works
>         assert(test1 == "01");
>         dstring test2 = "%d"d.format(1); // works
>         assert(test2 == "1"d);
>         wstring test3 = "%02d"w.format(1); // fails
>         assert(test3 == "01"w);
>         dstring test4 = "%02d"d.format(1); // fails
>         assert(test4 == "01"d);

dmd 2.072.0

November 09, 2016
On 11/09/2016 12:21 AM, Vadim Lopatin wrote:
> Looks like bug.
> dchar[] and wchar[] format strings support less specifiers than char[]
>
>         import std.format;
>         string test1 = "%02d".format(1); // works
>         assert(test1 == "01");
>         dstring test2 = "%d"d.format(1); // works
>         assert(test2 == "1"d);
>         wstring test3 = "%02d"w.format(1); // fails
>         assert(test3 == "01"w);
>         dstring test4 = "%02d"d.format(1); // fails
>         assert(test4 == "01"d);
>

It's a bug that std.format uses arrayPtrDiff() here:

  https://github.com/dlang/phobos/blob/master/std/format.d#L993

arrayPtrDiff() is at the bottom of the same file but works correctly only for char strings:

  https://github.com/dlang/phobos/blob/master/std/format.d#L6573

Please report it.

Ali

November 09, 2016
On 11/09/2016 01:20 AM, Ali Çehreli wrote:

> arrayPtrDiff() is at the bottom of the same file but works correctly
> only for char strings:
>
>   https://github.com/dlang/phobos/blob/master/std/format.d#L6573

What I meant is, using arrayPtrDiff() is correct only for char strings. Otherwise, arrayPtrDiff() is working properly.

Ali