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)
  2. bool endsWith(R1 doesThisEnd, R2 withThis)
    bool
    endsWith
    (
    alias pred = "a == b"
    R1
    R2
    )
    if (
    is(typeof(binaryFun!pred(doesThisEnd.back, withThis.back)) : bool)
    )
  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 R1

The bidirectional range to check.

withThis R2

The single element to check.

Return Value

Type: bool

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

1 import std.ascii : isAlpha;
2 assert("abc".endsWith!(a => a.isAlpha));
3 assert("abc".endsWith!isAlpha);
4 
5 assert(!"ab1".endsWith!(a => a.isAlpha));
6 
7 assert(!"ab1".endsWith!isAlpha);
8 assert(!"".endsWith!(a => a.isAlpha));
9 
10 import std.algorithm.comparison : among;
11 assert("abc".endsWith!(a => a.among('c', 'd') != 0));
12 assert(!"abc".endsWith!(a => a.among('a', 'b') != 0));
13 
14 assert(endsWith("abc", ""));
15 assert(!endsWith("abc", "b"));
16 assert(endsWith("abc", "a", 'c') == 2);
17 assert(endsWith("abc", "c", "a") == 1);
18 assert(endsWith("abc", "c", "c") == 1);
19 assert(endsWith("abc", "bc", "c") == 2);
20 assert(endsWith("abc", "x", "c", "b") == 2);
21 assert(endsWith("abc", "x", "aa", "bc") == 3);
22 assert(endsWith("abc", "x", "aaa", "sab") == 0);
23 assert(endsWith("abc", "x", "aaa", 'c', "sab") == 3);

Meta

Suggestion Box / Bug Report