File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -167,3 +167,28 @@ extension ReplacingSubrangeCollection {
167167 }
168168}
169169
170+ extension ReplacingSubrangeCollection : BidirectionalCollection
171+ where Base: BidirectionalCollection , Replacements: BidirectionalCollection {
172+
173+ @inlinable
174+ public func index( before i: Index ) -> Index {
175+ switch i. wrapped {
176+ case . base( var baseIndex) :
177+ if baseIndex == replacedRange. upperBound {
178+ if replacements. isEmpty {
179+ return makeIndex ( base. index ( before: replacedRange. lowerBound) )
180+ }
181+ return makeIndex ( replacements. index ( before: replacements. endIndex) )
182+ }
183+ base. formIndex ( before: & baseIndex)
184+ return makeIndex ( baseIndex)
185+
186+ case . replacement( var replacementIndex) :
187+ if replacementIndex == replacements. startIndex {
188+ return makeIndex ( base. index ( before: replacedRange. lowerBound) )
189+ }
190+ replacements. formIndex ( before: & replacementIndex)
191+ return makeIndex ( replacementIndex)
192+ }
193+ }
194+ }
You can’t perform that action at this time.
0 commit comments