| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
June 30, 2012 Re: std.string.format results in run-time exception | ||||
|---|---|---|---|---|
| ||||
Attachments:
| I have files a phobos bug report. http://d.puremagic.com/issues/show_bug.cgi?id=8326 Regards - Puneet | |||
June 30, 2012 Re: std.string.format results in run-time exception | ||||
|---|---|---|---|---|
| ||||
std.string.format uses std.format.doFormat, and it is based on RTTI. On the other hand, writeln/writefln uses std.format.formattedWrite and formatValue, they are based on Compile Time Reflection. So the results are different. In 2.060head, std.string.xformat is added, and it works as like writefln. https://github.com/D-Programming-Language/phobos/blob/master/std/string.d#L2611 Bye. Kenji Hara 2012/7/1 d coder <dlang.coder@gmail.com>: > Greetings > > std.string.format throws runtime exception for BigInt and for BitArray types even though writefln works fine. The run-time error says std.format.FormatException@std/format.d(4744): Can't convert std.bigint.BigInt to string: "string toString()" not defined > > Here is a small test case. > > Regards > - Puneet > > void main() > { > import std.stdio; > import std.string; > import std.bigint; > import std.bitmanip; > > BigInt aa = 100; > > BitArray bb; > bb.init([true, false]); > > writefln("%x", aa); > writefln("%x", bb); > writeln(format("%x", aa)); > writeln(format("%x", bb)); > } > | ||||
June 30, 2012 Re: std.string.format results in run-time exception | ||||
|---|---|---|---|---|
| ||||
Attachments:
| Thanks Kenji, I will use xformat. BTW, why is it named "x"format? Would not "s"format be a better name? Where "s" could stand for string. Also I feel, std.string.format should work for BitArray and BigInt too. Both these types are defined as part of phobos. Regards - Puneet | |||
June 30, 2012 Re: std.string.format results in run-time exception | ||||
|---|---|---|---|---|
| ||||
2012/7/1 d coder <dlang.coder@gmail.com>: > Thanks Kenji, I will use xformat. BTW, why is it named "x"format? Would not "s"format be a better name? Where "s" could stand for string. eXtended format. > Also I feel, std.string.format should work for BitArray and BigInt too. Both these types are defined as part of phobos. We couldn't replace the implementation of std.string.format directly. See the discussion: https://github.com/D-Programming-Language/phobos/pull/231 But, in the future, xformat would be renamed to format. Kenji Hara | ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply