View source code
Display the source code in std/algorithm/searching.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.algorithm.searching.endsWith
Checks if the given range ends with (one of) the given needle(s).
The reciprocal of
.
startsWith
Prototypes
uint endsWith(alias pred, Range, Needles...)( Range doesThisEnd, Needles withOneOfThese ) if (isBidirectionalRange!Range && Needles.length > 1 && is(typeof(.endsWith!pred(doesThisEnd, withOneOfThese[0])) : bool) && is(typeof(.endsWith!pred(doesThisEnd, withOneOfThese[1..__dollar])) : uint)); bool endsWith(alias pred, R1, R2)( R1 doesThisEnd, R2 withThis ) if (isBidirectionalRange!R1 && isBidirectionalRange!R2 && is(typeof(binaryFun!pred(doesThisEnd.back, withThis.back)) : bool)); bool endsWith(alias pred, R, E)( R doesThisEnd, E withThis ) if (isBidirectionalRange!R && is(typeof(binaryFun!pred(doesThisEnd.back, withThis)) : bool));
Parameters
Name | Description |
---|---|
pred | The predicate to use for comparing elements between the range and the needle(s). |
doesThisEnd | The bidirectional range to check. |
withOneOfThese | The needles to check against, which may be single elements, or bidirectional ranges of elements. |
withThis | The single element to check. |
Returns
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
, 2 if it ends with withOneOfThese
[0]
, and so
on.
withOneOfThese
[1]
Example
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);