Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions std/string.d
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,13 @@ ptrdiff_t indexOf(Range)(Range s, in dchar c,
return -1;
}

ptrdiff_t indexOf(T, size_t n)(ref T[n] s, in dchar c,
in CaseSensitive cs = CaseSensitive.yes) @safe pure
if (isSomeChar!T)
{
return indexOf(s[], c, cs);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An optimization would be to use const(T)[], b/c of less template instantiations.

}

@safe pure unittest
{
import std.conv : to;
Expand Down Expand Up @@ -511,6 +518,9 @@ ptrdiff_t indexOf(Range)(Range s, in dchar c,
assert(indexOf("hello\U00010100".byWchar, '\U00010100', cs) == 5);
assert(indexOf("hello\U00010100".byWchar, '\U00010101', cs) == -1);
}

char[10] fixedSizeArray = "0123456789";
assert(indexOf(fixedSizeArray, '2') == 2);
});
}

Expand Down