www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4532] New: Position specifiers don't work in format

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532

           Summary: Position specifiers don't work in format
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: cbkbbejeap mailinator.com



11:18:09 PDT ---
writefln("%1$s", "A");  // Prints "A"
format("%1$s", "A");  // Throws FormatError

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 29 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com



This is most peculiar.  Why has it been added directly into writef, rather than
being put in doFormat where it belongs?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 30 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532




I've just looked at the code and seem to have figured out what's going on. 
Traditionally, std.format.doFormat is the function that underlies all the
writef* functions and std.string.format.  However, a new templated function has
been written to replace it, std.format.formattedWrite.  The problem is that
std.string.format still uses doFormat, as do the writef* functions in
std.stream and others.

We need to get this fixed, and then deprecate doFormat.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 18 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532


Nick Sabalausky <cbkbbejeap mailinator.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simendsjo gmail.com



12:42:22 PDT ---
*** Issue 6455 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 16 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla kyllingen.net



*** Issue 5687 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |k.hara.pg gmail.com



*** Issue 6595 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tomeksowi gmail.com



*** Issue 5444 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



*** Issue 7571 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



*** Issue 7620 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532




*** Issue 7877 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532




---
*** Issue 7881 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532




---
Issue 6595 was a bug report only about std.string.format/sformat functions.


 This enhancement issue is nearly a bug report.
 
 format() and sformat() use std.format.doFormat as their implementations, but it
 is old feature, and its features are fewer than formatValue family.
 
 And it is causing not a few issues:
 bug 3715 - std.string.format can't use const/immutable toString functions
 bug 4266 - add support for structs in std.format.doFormat
 bug 4532 - Position specifiers don't work in format
 bug 5444 - std.string.format: arguments without format specifier appended to
 result
 bug 5970 - fix BigInt.toString
 
 I think format() should be implemented just appender and formattedWrite like
 follows:
 
 string format(Char, Args...)(in Char[] fmt, Args args)
 {
     auto w = appender!string();
     formattedWrite(w, fmt, args);
     return w.data;
 }
 
 This 'format()' provides just the same features as writef(ln) functions about
 formatting.
 
 And sformat() also could replace like follows:
 
 char[] sformat(Char, Args...)(char[] buf, in Char[] fmt, Args args)
 {
     size_t i;
     void sink(const(char)[] s) {
         if (buf.length < i + s.length)
             onRangeError("std.string.sformat", 0);
         buf[i .. i + s.length] = s[];
         i += s.length;
     }
     formattedWrite(&sink, fmt, args);
     return buf[0 .. i];
 }
And I proposed a pull and it is discussed in here: https://github.com/D-Programming-Language/phobos/pull/231 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



*** Issue 4754 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 10 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532




This seems another example of the same problem:


import std.stdio: writeln;
import std.conv: text;
struct Foo {}
void main() {
    Foo* f = new Foo;
    writeln(f);
    writeln(text(f));
}


Output:

15D2FD0
22884304

Expected output:

15D2FD0
15D2FD0

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532




I've taken a look here:
https://github.com/D-Programming-Language/phobos/pull/231

Kenji Hara sasy:

The same name with core.stdc.sprintf is very confusing. And std.string.format
returns new string, but core.stdc.sprintf write the formatted string into
specified buffer. The two behaviors are quite different.<
Andrei Alexandrescu says:
There's no problem with core.stdc.sprintf bearing the same name as
std.format.sprintf. Phobos has had such duplicate names for years without a
problem.<
I agree that Phobos has some name clashes. But I don't agree it's a good thing. It should be avoided if possible for newly added names. And I agree the behavior of the new functions is different from the C functions. So I agree with Kenji Hara, they should have different names. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532






text is just to!string wrapped in a variadic template to support multiple
arguments.  The implementation of to!string for pointer types (line 1259 in
conv.d, in 2.059) converts it to a size_t, which is an integral type, leading
to it being formatted as decimal.

I'm not sure whether it's related or not.  But what it does show is that we
need to investigate the long chains of template instantiations all these
various functions go through.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 20 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4532




16:22:09 PST ---
It seems all code samples in this issue are fixed.

There seems to be very few doFormat calls left in Phobos:

std\stdio.d:1498:   std.format.doFormat(&putc, arguments, argptr);
std\stdio.d:1533:   std.format.doFormat(&putcw, arguments, argptr);
std\stream.d:1209:  doFormat(&doFormatCallback,arguments,argptr);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 24 2013