www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Difference between dstring and string format specifiers support. Bug?

reply Vadim Lopatin <coolreader.org gmail.com> writes:
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);
Nov 09 2016
next sibling parent Vadim Lopatin <coolreader.org gmail.com> writes:
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
Nov 09 2016
prev sibling parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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
Nov 09 2016
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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
Nov 09 2016