Thread overview | ||||||
---|---|---|---|---|---|---|
|
November 09, 2016 Difference between dstring and string format specifiers support. Bug? | ||||
---|---|---|---|---|
| ||||
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 Re: Difference between dstring and string format specifiers support. Bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vadim Lopatin | 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 Re: Difference between dstring and string format specifiers support. Bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vadim Lopatin | 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 Re: Difference between dstring and string format specifiers support. Bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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 |
Copyright © 1999-2021 by the D Language Foundation