MCPcopy Create free account
hub / github.com/HKUDS/OpenSpace / _try_match

Function _try_match

openspace/skill_engine/patch.py:456–479  ·  view source on GitHub ↗

Attempt to find *pattern* inside *lines* using *compare*.

(
    lines: List[str],
    pattern: List[str],
    start_index: int,
    compare: Comparator,
    eof: bool,
)

Source from the content-addressed store, hash-verified

454
455
456def _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)

Callers 1

seek_sequenceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected