std.conv length=0

Bill Baxter dnewsgroup at billbaxter.com
Tue Apr 10 00:46:20 PDT 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


More information about the Digitalmars-d-learn mailing list