[Issue 10291] New: formattedWrite() to an Appender fails silently after Appender.clear()
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jun 7 14:19:38 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10291
Summary: formattedWrite() to an Appender fails silently after
Appender.clear()
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: jared at economicmodeling.com
--- Comment #0 from Jared Miller <jared at economicmodeling.com> 2013-06-07 14:19:36 PDT ---
After calling clear() on a std.array.Appender, formattedWrite() using that
appender fails silently. Calling the appender's put() method once after a
clear() is a workaround. Tested on DMD 2.062.
Example:
----
import std.stdio, std.array, std.format, std.string;
void main()
{
// FIRST EXAMPLE: use only put().
auto a = appender!string;
a.put( format("%d", 1) );
writeln(a.data);
a.clear();
// put() after clear() is OK.
a.put( format("%d", 2) );
writeln(a.data);
assert(a.data == "2");
// SECOND EXAMPLE: use only formattedWrite().
auto b = appender!string;
b.reserve(128);
formattedWrite(b, "%d", 1);
writeln(b.data);
assert(b.data == "1");
b.clear();
// formattedWrite() after clear() does not work.
formattedWrite(b, "%d", 2); // <-- FAILS SILENTLY
writeln(b.data); // "" (writes empty string)
assert(b.data == ""); // this should not pass, but it does.
// You have to call put() on appender before formattedWrite() works again.
b.put("");
formattedWrite(b, "%d", 3);
writeln(b.data);
assert(b.data == "3");
}
----
--
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