The OpenD Programming Language

endsWith

Checks if the given range ends with (one of) the given needle(s). The reciprocal of startsWith.

  1. uint endsWith(Range doesThisEnd, Needles withOneOfThese)
    uint
    endsWith
    (
    alias pred = "a == b"
    Range
    Needles...
    )
    (,)
    if (
    isBidirectionalRange!Range &&
    Needles.length > 1
    &&
    allSatisfy!(canTestStartsWith!(pred, Range), Needles)
    )
  2. bool endsWith(R1 doesThisEnd, R2 withThis)
  3. bool endsWith(R doesThisEnd, E withThis)
  4. bool endsWith(R doesThisEnd)

Parameters

pred

The predicate to use for comparing elements between the range and the needle(s).

doesThisEnd Range

The bidirectional range to check.

withOneOfThese Needles

The needles to check against, which may be single elements, or bidirectional ranges of elements.

Return Value

Type: uint

0 if the needle(s) do not occur at the end of the given range; otherwise the position of the matching needle, that is, 1 if the range ends with withOneOfThese[0], 2 if it ends with withOneOfThese[1], and so on.

In the case when no needle parameters are given, return true iff back of doesThisStart fulfils predicate pred.

Examples

import std.ascii : isAlpha;
assert("abc".endsWith!(a => a.isAlpha));
assert("abc".endsWith!isAlpha);

assert(!"ab1".endsWith!(a => a.isAlpha));

assert(!"ab1".endsWith!isAlpha);
assert(!"".endsWith!(a => a.isAlpha));

import std.algorithm.comparison : among;
assert("abc".endsWith!(a => a.among('c', 'd') != 0));
assert(!"abc".endsWith!(a => a.among('a', 'b') != 0));

assert(endsWith("abc", ""));
assert(!endsWith("abc", "b"));
assert(endsWith("abc", "a", 'c') == 2);
assert(endsWith("abc", "c", "a") == 1);
assert(endsWith("abc", "c", "c") == 1);
assert(endsWith("abc", "bc", "c") == 2);
assert(endsWith("abc", "x", "c", "b") == 2);
assert(endsWith("abc", "x", "aa", "bc") == 3);
assert(endsWith("abc", "x", "aaa", "sab") == 0);
assert(endsWith("abc", "x", "aaa", 'c', "sab") == 3);

Meta