Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 12, 2012 [Issue 7282] New: std.string.format throws at runtime where writef works fine | ||||
---|---|---|---|---|
| ||||
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@puremagic.com ReportedBy: andrej.mitrovich@gmail.com --- Comment #0 from Andrej Mitrovic <andrej.mitrovich@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@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: ------- |
January 12, 2012 [Issue 7282] std.string.format throws at runtime where writef works fine | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=7282 --- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-01-12 12:12:49 PST --- Btw a workaround: string str = to!string(pretty("123456")); auto str1 = format("%s", str); So to!string works as well, it's just format() that bails. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 12, 2012 [Issue 7282] std.string.format throws at runtime where writef works fine | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=7282 --- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-01-12 12:23:57 PST --- Also that function is broken (I mean its result), fixed one is: auto pretty(string src) { Appender!(dchar[]) res; size_t i = 1; while (!src.empty) { res.put(src.back); src.popBack; if (!src.empty && (i++ % 3 == 0)) res.put("_"); } return retro(res.data); } I was hoping there was something like this in Phobos but it didn't catch my eye. Anywho.. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 22, 2013 [Issue 7282] std.string.format throws at runtime where writef works fine | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=7282 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |WORKSFORME --- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-21 17:51:28 PST --- Works in 2.061. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation