[Issue 10571] formattedWrite error with delegate and string
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Aug 29 10:27:34 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10571
monarchdodra at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |monarchdodra at gmail.com
--- Comment #3 from monarchdodra at gmail.com 2013-08-29 10:27:33 PDT ---
(In reply to comment #0)
> I can't format a string into a delegate taking a 'const char[]'. This seems
> wrong to me.
>
> ----------------------------------
>
> import std.format;
>
> void main()
> {
> string buf;
> formattedWrite((in char[] s) { buf ~= s; }, "%s", "hello");
> assert(buf == "hello");
> }
>
> ----------------------------------
Yup. The branches char/string don't work with a delegate sink that accepts a
const(char)[]. Here is a somewhat reduced case.
//----
import std.format;
void main()
{
FormatSpec!char f;
formatValue((const(char)[]){}, '本', f);
formatValue((const(char)[]){}, "a", f);
}
//----
The root issue is that "formatValue" for wide characters doesn't actually work.
It just calls "put" and hopes put will magically do the work :D
formatValue for strings then also fails, because it has to compile the "%r"
path (raw), which iterates over the string as a range (dchars), and then prints
these raw with formatValue(dchar), which, again, doesn't work.
The reason we haven't seen this failure in the testers yet, is that std.format
is mostly unittest using Appender, and Appender *knows* how to transcode,
making it a very poor choice for thorough testing.
In any case, this gets fixed by my "put" fix:
https://github.com/D-Programming-Language/phobos/pull/1439
--
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