Attempt to find *pattern* inside *lines* using *compare*.
(
lines: List[str],
pattern: List[str],
start_index: int,
compare: Comparator,
eof: bool,
)
| 454 | |
| 455 | |
| 456 | def _try_match( |
| 457 | lines: List[str], |
| 458 | pattern: List[str], |
| 459 | start_index: int, |
| 460 | compare: Comparator, |
| 461 | eof: bool, |
| 462 | ) -> int: |
| 463 | """Attempt to find *pattern* inside *lines* using *compare*.""" |
| 464 | n = len(lines) |
| 465 | p = len(pattern) |
| 466 | if p == 0: |
| 467 | return -1 |
| 468 | |
| 469 | if eof: |
| 470 | from_end = n - p |
| 471 | if from_end >= start_index: |
| 472 | if all(compare(lines[from_end + j], pattern[j]) for j in range(p)): |
| 473 | return from_end |
| 474 | |
| 475 | for i in range(start_index, n - p + 1): |
| 476 | if all(compare(lines[i + j], pattern[j]) for j in range(p)): |
| 477 | return i |
| 478 | |
| 479 | return -1 |
| 480 | |
| 481 | |
| 482 | # Unicode normalisation (from ShinkaEvolve) |