findSkip

Finds needle in haystack and positions haystack right after the first occurrence of needle.

If no needle is provided, the haystack is advanced as long as pred evaluates to true. Similarly, the haystack is positioned so as pred evaluates to false for haystack.front.

For more information about pred see find.

  1. bool findSkip(R1 haystack, R2 needle)
  2. size_t findSkip(R1 haystack)
    size_t
    findSkip
    (
    alias pred
    R1
    )
    (
    ref R1 haystack
    )
    if (
    ifTestable!(typeof(haystack.front), unaryFun!pred)
    )

Parameters

haystack R1

The forward range to search in.

pred

Custom predicate for comparison of haystack and needle

Return Value

Type: size_t

true if the needle was found, in which case haystack is positioned after the end of the first occurrence of needle; otherwise false, leaving haystack untouched. If no needle is provided, it returns the number of times pred(haystack.front) returned true.

Examples

import std.ascii : isWhite;
string s = "    abc";
assert(findSkip!isWhite(s) && s == "abc");
assert(!findSkip!isWhite(s) && s == "abc");

s = "  ";
assert(findSkip!isWhite(s) == 2);
import std.range.primitives : empty;
// Needle is found; s is replaced by the substring following the first
// occurrence of the needle.
string s = "abcdef";
assert(findSkip(s, "cd") && s == "ef");

// Needle is not found; s is left untouched.
s = "abcdef";
assert(!findSkip(s, "cxd") && s == "abcdef");

// If the needle occurs at the end of the range, the range is left empty.
s = "abcdef";
assert(findSkip(s, "def") && s.empty);

See Also

Meta