View source code
Display the source code in std/algorithm/searching.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
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.
Function std.algorithm.searching.endsWith
Checks if the given range ends with (one of) the given needle(s).
The reciprocal of startsWith
.
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));
bool endsWith(alias pred, R)
(
R doesThisEnd
)
if (isInputRange!R && ifTestable!(typeof(doesThisEnd .front), unaryFun!pred));
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 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
.
Example
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"));
writeln(endsWith("abc", "a", 'c')); // 2
writeln(endsWith("abc", "c", "a")); // 1
writeln(endsWith("abc", "c", "c")); // 1
writeln(endsWith("abc", "bc", "c")); // 2
writeln(endsWith("abc", "x", "c", "b")); // 2
writeln(endsWith("abc", "x", "aa", "bc")); // 3
writeln(endsWith("abc", "x", "aaa", "sab")); // 0
writeln(endsWith("abc", "x", "aaa", 'c', "sab")); // 3
Authors
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.