[Issue 7282] New: std.string.format throws at runtime where writef works fine

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jan 12 12:11:04 PST 2012


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

           Summary: std.string.format throws at runtime where writef works
                    fine
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2012-01-12 12:11:01 PST ---
module test;

import std.array;
import std.conv;
import std.range;
import std.string;
import std.stdio;

auto pretty(string src)
{
    Appender!(dchar[]) res;

    size_t i;
    foreach (dchar ch; retro(src))
    {
        if (++i % 3 == 0)
            res.put("_");

        res.put(ch);
    }

    return retro(res.data);
}

void main()
{
    // ok, "123_456"
    writefln("%s", pretty("123456"));

    // FormatException
    // std.format.FormatException at std\format.d(3956): 
    // Can't convert std.range.retro!(dchar[]).retro.Result to string: 
    // "string toString()" not defined    
    auto str1 = format("%s", pretty("123456"));  
}

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