www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6595] New: std.string.format() and sformat() are obsolete

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

           Summary: std.string.format() and sformat() are obsolete
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: k.hara.pg gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg gmail.com> 2011-09-02 09:54:03 PDT ---
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];
}

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


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2011-09-02 11:13:39 PDT ---
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: -------
Sep 02 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6595


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |smjg iname.com
         Resolution|                            |DUPLICATE


--- Comment #2 from Stewart Gordon <smjg iname.com> 2012-04-01 15:04:46 PDT ---
*** This issue has been marked as a duplicate of issue 4532 ***

-- 
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=6595



--- Comment #3 from github-bugzilla puremagic.com 2012-04-21 10:00:17 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/1b75b2b2890fe22fd24db4c693d718426d576f74
Merge pull request #231 from 9rnsr/fix6595

Issue 6595 - std.string.format() and sformat() are obsolete

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


Kenji Hara <k.hara.pg gmail.com> changed:

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


--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2012-04-22 17:36:58 PDT ---
*** Issue 5042 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 22 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6595


Kenji Hara <k.hara.pg gmail.com> changed:

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


--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2012-04-24 04:59:22 PDT ---
*** Issue 7598 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 24 2012