digitalmars.D.learn - std.conv length=0
- Derek Parnell (18/18) Apr 10 2007 Currently, the functions in std.conv throw an exception if the input str...
- Bill Baxter (6/19) Apr 10 2007 Well the empty string is not a number, so it seems clear that there are
- cc (14/18) Mar 28 2012 I too thought this behavior was silly, so I wrote a little
- James Miller (4/8) Mar 28 2012 I award thee the "Necromancer" badge, for reviving a long-dead thread.
- Jesse Phillips (4/8) Mar 28 2012 I find the distaste of reviving a thread strange. It would be
- James Miller (4/12) Mar 28 2012 I have no problem with it, if I did, I would have said so.
- Jesse Phillips (5/13) Mar 29 2012 I realized that, but I see those that revive threads all the time
Currently, the functions in std.conv throw an exception if the input string is empty. What is the rationale for this? I find myself writing shims like ... int makeInt(char[] d) { if (d.length == 0) return toInt("0"); return toInt(d); } Is there anyone here that relies on an empty string throwing a conversion error? Also, I see that there is no link back to the DWiki/DocComments in the std.conv docs. -- Derek (skype: derek.j.parnell) Melbourne, Australia "Justice for David Hicks!" 10/04/2007 5:27:01 PM
Apr 10 2007
Derek Parnell wrote:Currently, the functions in std.conv throw an exception if the input string is empty. What is the rationale for this? I find myself writing shims like ... int makeInt(char[] d) { if (d.length == 0) return toInt("0"); return toInt(d); } Is there anyone here that relies on an empty string throwing a conversion error?Well the empty string is not a number, so it seems clear that there are times (perhaps the majority even) when you would want to treat that as an ill-formatted number error. Just like "fred" isn't a number. I'm assuming that throws an exception too. --bb
Apr 10 2007
On Tuesday, 10 April 2007 at 07:46:35 UTC, Bill Baxter wrote:Derek Parnell wrote:I too thought this behavior was silly, so I wrote a little wrapper for it (replying 5 years after the fact because someone'll probably stumble onto this question through Google like I did): import std.conv : toOrig = to; T toSafe(T, S)(S arg) { static if ((is(T == int) || (is(T == real))) && is(S == string)) if (!arg.length) return 0; return toOrig!T(arg); } alias toSafe to; and then just continue to call 'to' normally.Currently, the functions in std.conv throw an exception if the input string is empty. What is the rationale for this?
Mar 28 2012
On 29 March 2012 16:03, cc <cc nevernet.com> wrote:On Tuesday, 10 April 2007 at 07:46:35 UTC, Bill Baxter wrote: I too thought this behavior was silly, so I wrote a little wrapper for it (replying 5 years after the fact because someone'll probably stumble onto this question through Google like I did):I award thee the "Necromancer" badge, for reviving a long-dead thread. -- James Miller
Mar 28 2012
On Thursday, 29 March 2012 at 03:40:55 UTC, James Miller wrote:I award thee the "Necromancer" badge, for reviving a long-dead thread. -- James MillerI find the distaste of reviving a thread strange. It would be like removing the "reopened" feature of bug tracking software (who wants to transpose all that information).
Mar 28 2012
On 29 March 2012 17:05, Jesse Phillips <jessekphillips+D gmail.com> wrote:On Thursday, 29 March 2012 at 03:40:55 UTC, James Miller wrote:I have no problem with it, if I did, I would have said so. -- James MillerI award thee the "Necromancer" badge, for reviving a long-dead thread. -- James MillerI find the distaste of reviving a thread strange. It would be like removing the "reopened" feature of bug tracking software (who wants to transpose all that information).
Mar 28 2012
On Thursday, 29 March 2012 at 04:25:54 UTC, James Miller wrote:I realized that, but I see those that revive threads all the time say, "sorry for the old thread" And I think there have been moderator complaints on some phpbb forums I've been (maybe the rules of conduct).I find the distaste of reviving a thread strange. It would be like removing the "reopened" feature of bug tracking software (who wants to transpose all that information).I have no problem with it, if I did, I would have said so. -- James Miller
Mar 29 2012