mirror of
https://github.com/dlang/phobos.git
synced 2025-05-13 07:39:15 +03:00
Review updates
This commit is contained in:
parent
bfebdc7ecc
commit
f7f48475f2
1 changed files with 41 additions and 49 deletions
|
@ -968,7 +968,10 @@ Returns:
|
||||||
otherwise the position of the matching needle, that is, 1 if the range ends
|
otherwise the position of the matching needle, that is, 1 if the range ends
|
||||||
with $(D withOneOfThese[0]), 2 if it ends with $(D withOneOfThese[1]), and so
|
with $(D withOneOfThese[0]), 2 if it ends with $(D withOneOfThese[1]), and so
|
||||||
on.
|
on.
|
||||||
*/
|
|
||||||
|
In the case when no needle parameters are given, return $(D true) iff back of
|
||||||
|
$(D doesThisStart) fulfils predicate $(D pred).
|
||||||
|
*/
|
||||||
uint endsWith(alias pred = "a == b", Range, Needles...)(Range doesThisEnd, Needles withOneOfThese)
|
uint endsWith(alias pred = "a == b", Range, Needles...)(Range doesThisEnd, Needles withOneOfThese)
|
||||||
if (isBidirectionalRange!Range && Needles.length > 1 &&
|
if (isBidirectionalRange!Range && Needles.length > 1 &&
|
||||||
is(typeof(.endsWith!pred(doesThisEnd, withOneOfThese[0])) : bool) &&
|
is(typeof(.endsWith!pred(doesThisEnd, withOneOfThese[0])) : bool) &&
|
||||||
|
@ -1063,29 +1066,6 @@ if (isBidirectionalRange!R1 &&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Checks whether the given
|
|
||||||
$(XREF_PACK_NAMED range,primitives,isInputRange,input range) ends with an
|
|
||||||
element that fulfils predicate $(D pred).
|
|
||||||
|
|
||||||
Params:
|
|
||||||
|
|
||||||
pred = Unary mandatory predicate.
|
|
||||||
|
|
||||||
doesThisEnd = The input range to check.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
$(D bool) if the first element in range $(D doesThisEnd) fulfils predicate
|
|
||||||
$(D pred), $(D false) otherwise.
|
|
||||||
*/
|
|
||||||
bool endsWith(alias pred = "a", R)(R doesThisEnd)
|
|
||||||
if (isInputRange!R &&
|
|
||||||
is(typeof(unaryFun!pred(doesThisEnd.front)) : bool))
|
|
||||||
{
|
|
||||||
return !doesThisEnd.empty && unaryFun!pred(doesThisEnd.back);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ditto
|
/// Ditto
|
||||||
bool endsWith(alias pred = "a == b", R, E)(R doesThisEnd, E withThis)
|
bool endsWith(alias pred = "a == b", R, E)(R doesThisEnd, E withThis)
|
||||||
if (isBidirectionalRange!R &&
|
if (isBidirectionalRange!R &&
|
||||||
|
@ -1096,13 +1076,30 @@ if (isBidirectionalRange!R &&
|
||||||
: binaryFun!pred(doesThisEnd.back, withThis);
|
: binaryFun!pred(doesThisEnd.back, withThis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ditto
|
||||||
|
bool endsWith(alias pred, R)(R doesThisEnd)
|
||||||
|
if (isInputRange!R &&
|
||||||
|
ifTestable!(typeof(doesThisEnd.front), unaryFun!pred))
|
||||||
|
{
|
||||||
|
return !doesThisEnd.empty && unaryFun!pred(doesThisEnd.back);
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@safe unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
import std.ascii : isAlpha;
|
import std.ascii : isAlpha;
|
||||||
assert("abc".endsWith!(a => a.isAlpha));
|
assert("abc".endsWith!(a => a.isAlpha));
|
||||||
|
assert("abc".endsWith!isAlpha);
|
||||||
|
|
||||||
assert(!"ab1".endsWith!(a => a.isAlpha));
|
assert(!"ab1".endsWith!(a => a.isAlpha));
|
||||||
|
|
||||||
|
assert(!"ab1".endsWith!isAlpha);
|
||||||
assert(!"".endsWith!(a => a.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", ""));
|
||||||
assert(!endsWith("abc", "b"));
|
assert(!endsWith("abc", "b"));
|
||||||
assert(endsWith("abc", "a", 'c') == 2);
|
assert(endsWith("abc", "a", 'c') == 2);
|
||||||
|
@ -3182,6 +3179,9 @@ elements in $(D withOneOfThese), then the shortest one matches (if there are
|
||||||
two which match which are of the same length (e.g. $(D "a") and $(D 'a')), then
|
two which match which are of the same length (e.g. $(D "a") and $(D 'a')), then
|
||||||
the left-most of them in the argument
|
the left-most of them in the argument
|
||||||
list matches).
|
list matches).
|
||||||
|
|
||||||
|
In the case when no needle parameters are given, return $(D true) iff front of
|
||||||
|
$(D doesThisStart) fulfils predicate $(D pred).
|
||||||
*/
|
*/
|
||||||
uint startsWith(alias pred = "a == b", Range, Needles...)(Range doesThisStart, Needles withOneOfThese)
|
uint startsWith(alias pred = "a == b", Range, Needles...)(Range doesThisStart, Needles withOneOfThese)
|
||||||
if (isInputRange!Range && Needles.length > 1 &&
|
if (isInputRange!Range && Needles.length > 1 &&
|
||||||
|
@ -3324,32 +3324,9 @@ if (isInputRange!R1 &&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Checks whether the given
|
|
||||||
$(XREF_PACK_NAMED range,primitives,isInputRange,input range) starts with an
|
|
||||||
element that fulfils predicate $(D pred).
|
|
||||||
|
|
||||||
Params:
|
|
||||||
|
|
||||||
pred = Unary mandatory predicate.
|
|
||||||
|
|
||||||
doesThisStart = The input range to check.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
$(D bool) if the first element in range $(D doesThisStart) fulfils predicate
|
|
||||||
$(D pred), $(D false) otherwise.
|
|
||||||
*/
|
|
||||||
bool startsWith(alias pred = "a", R)(R doesThisStart)
|
|
||||||
if (isInputRange!R &&
|
|
||||||
is(typeof(unaryFun!pred(doesThisStart.front)) : bool))
|
|
||||||
{
|
|
||||||
return !doesThisStart.empty && unaryFun!pred(doesThisStart.front);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ditto
|
/// Ditto
|
||||||
bool startsWith(alias pred = "a == b", R, E)(R doesThisStart, E withThis)
|
bool startsWith(alias pred = "a == b", R, E)(R doesThisStart, E withThis)
|
||||||
if (isInputRange!R &&
|
if (isInputRange!R &&
|
||||||
is(typeof(binaryFun!pred(doesThisStart.front, withThis)) : bool))
|
is(typeof(binaryFun!pred(doesThisStart.front, withThis)) : bool))
|
||||||
{
|
{
|
||||||
return doesThisStart.empty
|
return doesThisStart.empty
|
||||||
|
@ -3357,13 +3334,28 @@ if (isInputRange!R &&
|
||||||
: binaryFun!pred(doesThisStart.front, withThis);
|
: binaryFun!pred(doesThisStart.front, withThis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ditto
|
||||||
|
bool startsWith(alias pred, R)(R doesThisStart)
|
||||||
|
if (isInputRange!R &&
|
||||||
|
ifTestable!(typeof(doesThisStart.front), unaryFun!pred))
|
||||||
|
{
|
||||||
|
return !doesThisStart.empty && unaryFun!pred(doesThisStart.front);
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@safe unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
import std.ascii : isAlpha;
|
import std.ascii : isAlpha;
|
||||||
|
|
||||||
assert("abc".startsWith!(a => a.isAlpha));
|
assert("abc".startsWith!(a => a.isAlpha));
|
||||||
|
assert("abc".startsWith!isAlpha);
|
||||||
assert(!"1ab".startsWith!(a => a.isAlpha));
|
assert(!"1ab".startsWith!(a => a.isAlpha));
|
||||||
assert(!"".startsWith!(a => a.isAlpha));
|
assert(!"".startsWith!(a => a.isAlpha));
|
||||||
|
|
||||||
|
import std.algorithm.comparison : among;
|
||||||
|
assert("abc".startsWith!(a => a.among('a', 'b') != 0));
|
||||||
|
assert(!"abc".startsWith!(a => a.among('b', 'c') != 0));
|
||||||
|
|
||||||
assert(startsWith("abc", ""));
|
assert(startsWith("abc", ""));
|
||||||
assert(startsWith("abc", "a"));
|
assert(startsWith("abc", "a"));
|
||||||
assert(!startsWith("abc", "b"));
|
assert(!startsWith("abc", "b"));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue