The predicate to use for comparing elements between the range and the needle(s).
The bidirectional range to check.
The single element to check.
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.
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);
Checks if the given range ends with (one of) the given needle(s). The reciprocal of startsWith.