lastRange(of:in:)
Returns the last found range of the type’s data buffer.
Declaration
func lastRange<D, R>(of: D, in: R) -> Range<Self.Index>? where D : DataProtocol, R : RangeExpression, Self.Index == R.BoundParameters
- of:
The data sequence to find.
- in:
A range to limit the scope of the search.
Return Value
The range, if found, of the last match of the provided data sequence.
Discussion
An example of searching a constrained range within a data buffer for the last match:
let data: [UInt8] = [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]
let pattern: [UInt8] = [2, 3]
let match = data.lastRange(of: pattern, in: 0...9)
// match == 6..<8