mirror of
https://github.com/dlang/phobos.git
synced 2025-05-07 19:49:36 +03:00
Merge pull request #6132 from JackStouffer/startswith-ascii
Remove auto-decoding from startsWith when Needles are all narrow chars merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>
This commit is contained in:
commit
15da6f6aca
1 changed files with 19 additions and 2 deletions
|
@ -4099,12 +4099,29 @@ list matches).
|
|||
In the case when no needle parameters are given, return `true` iff front of
|
||||
`doesThisStart` fulfils predicate `pred`.
|
||||
*/
|
||||
uint startsWith(alias pred = "a == b", Range, Needles...)(Range doesThisStart, Needles withOneOfThese)
|
||||
uint startsWith(alias pred = (a, b) => a == b, Range, Needles...)(Range doesThisStart, Needles withOneOfThese)
|
||||
if (isInputRange!Range && Needles.length > 1 &&
|
||||
is(typeof(.startsWith!pred(doesThisStart, withOneOfThese[0])) : bool ) &&
|
||||
is(typeof(.startsWith!pred(doesThisStart, withOneOfThese[1 .. $])) : uint))
|
||||
{
|
||||
import std.meta : allSatisfy;
|
||||
|
||||
template checkType(T)
|
||||
{
|
||||
enum checkType = is(Unqual!(ElementEncodingType!Range) == Unqual!T);
|
||||
}
|
||||
|
||||
// auto-decoding special case
|
||||
static if (__traits(isSame, binaryFun!pred, (a, b) => a == b) &&
|
||||
isNarrowString!Range && allSatisfy!(checkType, Needles))
|
||||
{
|
||||
import std.utf : byCodeUnit;
|
||||
auto haystack = doesThisStart.byCodeUnit;
|
||||
}
|
||||
else
|
||||
{
|
||||
alias haystack = doesThisStart;
|
||||
}
|
||||
alias needles = withOneOfThese;
|
||||
|
||||
// Make one pass looking for empty ranges in needles
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue