Skip to content

Commit

Permalink
Merge pull request #3191 from schuetzm/indexof-fixed-size-array
Browse files Browse the repository at this point in the history
Re-add overload for fixed-size arrays to `std.string.indexOf`
  • Loading branch information
WalterBright committed Apr 17, 2015
2 parents 3b3e49b + 97dddde commit 325c7b0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions std/string.d
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);
}

@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

0 comments on commit 325c7b0

Please sign in to comment.