MCPcopy Create free account
hub / github.com/ElementsProject/lightning / collapse_with_linemap

Function collapse_with_linemap

devtools/bolt-coverage.py:31–61  ·  view source on GitHub ↗

Collapse whitespace across a list of (lineno, text) pairs. Returns (collapsed_text, linemap) where linemap[i] is the original line number for character i in collapsed_text. Matches the behaviour of collapse_whitespace() so positions are compatible with coverage records.

(raw_lines: List[Tuple[int, str]])

Source from the content-addressed store, hash-verified

29
30
31def collapse_with_linemap(raw_lines: List[Tuple[int, str]]) -> Tuple[str, List[int]]:
32 """Collapse whitespace across a list of (lineno, text) pairs.
33
34 Returns (collapsed_text, linemap) where linemap[i] is the original line
35 number for character i in collapsed_text. Matches the behaviour of
36 collapse_whitespace() so positions are compatible with coverage records.
37 """
38 result: List[str] = []
39 linemap: List[int] = []
40 in_ws = False
41 ws_lineno = 1
42
43 for lineno, line in raw_lines:
44 for ch in line:
45 if whitespace_re.match(ch):
46 if not in_ws:
47 in_ws = True
48 ws_lineno = lineno
49 else:
50 if in_ws:
51 result.append(" ")
52 linemap.append(ws_lineno)
53 in_ws = False
54 result.append(ch)
55 linemap.append(lineno)
56
57 if in_ws:
58 result.append(" ")
59 linemap.append(ws_lineno)
60
61 return "".join(result), linemap
62
63
64def load_bolt(boltdir: str, num: int) -> Tuple[str, List[Tuple[str, List[int]]]]:

Callers 1

load_boltFunction · 0.85

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected