File tree Expand file tree Collapse file tree 1 file changed +24
-8
lines changed
Sources/_StringProcessing/Engine Expand file tree Collapse file tree 1 file changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -301,15 +301,24 @@ extension Processor {
301301 mutating func reverseMatch(
302302 _ e: Element , isCaseInsensitive: Bool
303303 ) -> Bool {
304- guard let previous = input. reverseMatch (
304+ let previous = input. reverseMatch (
305305 e,
306306 at: currentPosition,
307307 limitedBy: start,
308308 isCaseInsensitive: isCaseInsensitive
309- ) else {
310- signalFailure ( )
311- return false
309+ )
310+
311+ guard let previous else {
312+ guard currentPosition == start else {
313+ // If there's no previous character, and we're not
314+ // at the start of the string, the match has failed
315+ signalFailure ( )
316+ return false
317+ }
318+
319+ return true
312320 }
321+
313322 currentPosition = previous
314323 return true
315324 }
@@ -358,16 +367,23 @@ extension Processor {
358367 boundaryCheck: Bool ,
359368 isCaseInsensitive: Bool
360369 ) -> Bool {
361- guard let previous = input. reverseMatchScalar (
370+ let previous = input. reverseMatchScalar (
362371 s,
363372 at: currentPosition,
364373 limitedBy: start,
365374 boundaryCheck: boundaryCheck,
366375 isCaseInsensitive: isCaseInsensitive
367- ) else {
368- signalFailure ( )
369- return false
376+ )
377+
378+ guard let previous else {
379+ guard currentPosition == start else {
380+ signalFailure ( )
381+ return false
382+ }
383+
384+ return true
370385 }
386+
371387 currentPosition = previous
372388 return true
373389 }
You can’t perform that action at this time.
0 commit comments