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

Function seek_sequence

openspace/skill_engine/patch.py:498–538  ·  view source on GitHub ↗

4-level degrading search for a line pattern inside *lines*. Returns the 0-based index of the first matching position, or -1.

(
    lines: List[str],
    pattern: List[str],
    start_index: int,
    eof: bool = False,
)

Source from the content-addressed store, hash-verified

496
497
498def seek_sequence(
499 lines: List[str],
500 pattern: List[str],
501 start_index: int,
502 eof: bool = False,
503) -> int:
504 """4-level degrading search for a line pattern inside *lines*.
505
506 Returns the 0-based index of the first matching position, or -1.
507 """
508 if not pattern:
509 return -1
510
511 # Pass 1: exact
512 idx = _try_match(lines, pattern, start_index, lambda a, b: a == b, eof)
513 if idx != -1:
514 return idx
515
516 # Pass 2: rstrip
517 idx = _try_match(
518 lines, pattern, start_index,
519 lambda a, b: a.rstrip() == b.rstrip(), eof,
520 )
521 if idx != -1:
522 return idx
523
524 # Pass 3: strip
525 idx = _try_match(
526 lines, pattern, start_index,
527 lambda a, b: a.strip() == b.strip(), eof,
528 )
529 if idx != -1:
530 return idx
531
532 # Pass 4: Unicode-normalised + strip
533 idx = _try_match(
534 lines, pattern, start_index,
535 lambda a, b: _normalize_unicode(a.strip()) == _normalize_unicode(b.strip()),
536 eof,
537 )
538 return idx
539
540def _parse_patch_header(
541 lines: List[str], idx: int,

Callers 1

_compute_replacementsFunction · 0.85

Calls 2

_try_matchFunction · 0.85
_normalize_unicodeFunction · 0.85

Tested by

no test coverage detected