indexOfNeither

Searches haystack for a character not in needles.

  1. ptrdiff_t indexOfNeither(const(Char)[] haystack, const(Char2)[] needles, CaseSensitive cs)
  2. ptrdiff_t indexOfNeither(const(Char)[] haystack, const(Char2)[] needles, size_t startIdx, CaseSensitive cs)
    @safe pure
    ptrdiff_t
    indexOfNeither
    (
    Char
    Char2
    )
    (
    const(Char)[] haystack
    ,
    const(Char2)[] needles
    ,
    in size_t startIdx
    ,
    in CaseSensitive cs = Yes.caseSensitive
    )
    if (
    isSomeChar!Char &&
    )

Parameters

haystack const(Char)[]

string to search for needles in

needles const(Char2)[]

characters to search for in haystack

startIdx size_t

index of a well-formed code point in haystack to start searching from; defaults to 0

cs CaseSensitive

specifies whether comparisons are case-sensitive (Yes.caseSensitive) or not (No.caseSensitive)

Return Value

Type: ptrdiff_t

The index of the first character in haystack that is not an element of needles. If all characters of haystack are elements of needles or startIdx is greater than or equal to haystack.length, then -1 is returned. If the parameters are not valid UTF, the result will still be either -1 or in the range [startIdx .. haystack.length], but will not be reliable otherwise.

Throws

If the sequence starting at startIdx does not represent a well-formed code point, then a std.utf.UTFException may be thrown.

Examples

assert(indexOfNeither("abba", "a", 2) == 2);
assert(indexOfNeither("def", "de", 1) == 2);
assert(indexOfNeither("dfefffg", "dfe", 4) == 6);
assert(indexOfNeither("def", "a") == 0);
assert(indexOfNeither("def", "de") == 2);
assert(indexOfNeither("dfefffg", "dfe") == 6);

Meta