Need help with basic functional programming
Eric via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 22 10:38:50 PDT 2014
On Tuesday, 22 July 2014 at 17:09:29 UTC, bearophile wrote:
> Eric:
>
>> while (!buf.empty())
>> {
>> p++;
>> buf.popFront();
>
> Those () can be omitted, if you mind the noise (but you can
> also keep them).
>
>
>> if (buf.front() <= '0' || buf.front() >= '9') break;
>
> std.ascii.isDigit helps.
>
>
>> curTok.image = cast(string) cbuffer[0 .. (p -
>> cbuffer.ptr)].dup;
>
> If you want a string, then idup is better. Try to minimize the
> number of casts in your code.
>
>
>> auto s = buf.until("a <= '0' || a >= '9'");
>
> Perhaps you need a ! after the until, or a !q{a <= '0' || a >=
> '9'}.
>
>
>> Also, what is the fastest way to convert a range to a string?
>
> The "text" function is the simplest.
>
> Bye,
> bearophile
Thanks! All very good suggestions...
-Eric
More information about the Digitalmars-d-learn
mailing list