Array-only version of startsWith and skipOver
Per Nordlöw
per.nordlow at gmail.com
Fri Oct 25 07:03:50 UTC 2019
On Friday, 25 October 2019 at 06:59:07 UTC, Per Nordlöw wrote:
> /** Array-overload for `skipOver` with no explicit predicate
> predicate. */
> bool skipOver(T)(scope ref const(T)[] haystack,
> scope const(T)[] needle)
Found it.
The parameter `haystack` must be qualified with inout instead of
const because it's `ref`.
bool skipOver(T)(scope ref inout(T)[] haystack,
scope const(T)[] needle)
{
if (startsWith(haystack, needle))
{
haystack = haystack[needle.length .. $];
return true;
}
return false;
}
Why?
More information about the Digitalmars-d-learn
mailing list