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 {
301
301
mutating func reverseMatch(
302
302
_ e: Element , isCaseInsensitive: Bool
303
303
) -> Bool {
304
- guard let previous = input. reverseMatch (
304
+ let previous = input. reverseMatch (
305
305
e,
306
306
at: currentPosition,
307
307
limitedBy: start,
308
308
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
312
320
}
321
+
313
322
currentPosition = previous
314
323
return true
315
324
}
@@ -358,16 +367,23 @@ extension Processor {
358
367
boundaryCheck: Bool ,
359
368
isCaseInsensitive: Bool
360
369
) -> Bool {
361
- guard let previous = input. reverseMatchScalar (
370
+ let previous = input. reverseMatchScalar (
362
371
s,
363
372
at: currentPosition,
364
373
limitedBy: start,
365
374
boundaryCheck: boundaryCheck,
366
375
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
370
385
}
386
+
371
387
currentPosition = previous
372
388
return true
373
389
}
You can’t perform that action at this time.
0 commit comments