<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Sep 6, 2013 at 9:38 PM, Jonathan M Davis <span dir="ltr"><<a href="mailto:jmdavisProg@gmx.com" target="_blank">jmdavisProg@gmx.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On Friday, September 06, 2013 21:15:44 Timothee Cour wrote:<br>

> I'd like to have a function:<br>
><br>
> @nothrow bool isNumberLitteral(string a);<br>
> unittest{<br>
> assert(isNumberLitteral("1.2"));<br>
> assert(!isNumberLitteral("a1.2"));<br>
> assert(!isNumberLitteral("a.b"));<br>
> }<br>
><br>
> I want it nothrow for efficiency (I'm using it intensively), and try/catch<br>
> as below has significant runtime overhead (esp when the exception is<br>
> caught):<br>
<br>
</div>You could try std.string.isNumeric.<br></blockquote><div><br></div><div>beautiful, thanks. not clear if it's better in std.string rather than std.conv. </div><div><br></div><div>While I'm at it, I was also curious whether there's functionality for the following (I wrote my own versions but they might not consider all cases) :</div>
<div><br></div><div>unittest{<br></div><div>  // isQuotedString: tests whether a string represents a quoted string.</div><div>  assert(`"abc"`. isQuotedString);</div><div>  assert(`q{abc}`. isQuotedString);</div>
<div>  assert(!"abc". isQuotedString);</div><div>}<br></div><div><br></div><div>//escapeString:</div><div><div>/// escapes a to be pasted as is in D code (analog to std.process.escapeShellFileName which btw has little business to do in std.process)</div>
<div>string escapeD(string a){</div><div><span class="" style="white-space:pre">    </span>import std.array:replace;</div><div><span class="" style="white-space:pre">  </span>return `r"`~a.replace(`"`,`" "\"" r"`)~`"`;</div>
<div>}<br></div></div><div><br></div><div>//inverse operation to unEscapeString</div><div><div>string escapeString(string a);</div></div><div><br></div><div><br></div><div>I have clear use cases for those, which I can explain if it's not obvious.</div>
<div><br></div><div> </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
But it's true that it would be nice to have some sort of counterpart to<br>
<a href="http://std.conv.to" target="_blank">std.conv.to</a> which checked whether a conversion was possible or which returned<br>
its argument via an out parameter and returned whether it succeeded or not (or<br>
something similar) for cases where you need to avoid throwing.<br>
<br>
<a href="http://d.puremagic.com/issues/show_bug.cgi?id=6840" target="_blank">http://d.puremagic.com/issues/show_bug.cgi?id=6840</a><br>
<a href="http://d.puremagic.com/issues/show_bug.cgi?id=6843" target="_blank">http://d.puremagic.com/issues/show_bug.cgi?id=6843</a></blockquote><div><br></div><div>Agreed with this and <a href="http://std.conv.to">std.conv.to</a> calling a nothrow function that returns a boolean. </div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
<span class=""><font color="#888888"><br>
- Jonathan M Davis<br>
</font></span></blockquote></div><br></div></div>