On 30/03/2016 1:46 AM, eastanon wrote:
On Thursday, 24 March 2016 at 06:34:51 UTC, rikki cattermole wrote:
            void popFront() {
                import std.string : indexOf;

                if (source is null) {
                    isEmpty = true;
                    return;
                }

                void tidyInput() {
                    foreach(i, c; source) {
                        switch(c) {
                            case 0: .. case ' ':
                                break;
                            default:
                                source = source[i .. $];
                                return;
                        }
                    }

                    source = null;
                }

                tidyInput();

Do you mind to explain  what is really going on at popFront() and
tidyInput() functions?

popFront is a special function used with input ranges.
It has support in the language for e.g. foreach loops.
You also need empty and front to go along with it however.
With front returning a value and empty if there is any more items.

The if statement in popFront is just to make empty set correctly (delayed).

Now tidyInput basically just trims (on the left) the source and sets it to null if there is no more of it.
That way things like "   @Myid" will still work fine.

If you need an explanation about the rest of popFront, let me know!

Reply via email to