File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,9 @@ extension DataProtocol {
137
137
}
138
138
139
139
public func firstRange< D: DataProtocol , R: RangeExpression > ( of data: D , in range: R ) -> Range < Index > ? where R. Bound == Index {
140
+ guard !data. isEmpty else {
141
+ return nil
142
+ }
140
143
let r = range. relative ( to: self )
141
144
let rangeCount = distance ( from: r. lowerBound, to: r. upperBound)
142
145
if rangeCount < data. count {
@@ -166,6 +169,9 @@ extension DataProtocol {
166
169
}
167
170
168
171
public func lastRange< D: DataProtocol , R: RangeExpression > ( of data: D , in range: R ) -> Range < Index > ? where R. Bound == Index {
172
+ guard !data. isEmpty else {
173
+ return nil
174
+ }
169
175
let r = range. relative ( to: self )
170
176
let rangeCount = distance ( from: r. lowerBound, to: r. upperBound)
171
177
if rangeCount < data. count {
You can’t perform that action at this time.
0 commit comments