[Issue 4532] std.string.format, std.stream methods, etc. still use the old doFormat instead of formattedWrite

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 9 21:39:46 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=4532



--- Comment #11 from Kenji Hara <k.hara.pg at gmail.com> 2012-04-09 21:40:28 PDT ---
Issue 6595 was a bug report only about std.string.format/sformat functions.

>From issue 6595 comment #0:
> 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: -------


More information about the Digitalmars-d-bugs mailing list