MCPcopy
hub / github.com/prompt-toolkit/ptpython / _common_whitespace_prefix

Function _common_whitespace_prefix

src/ptpython/utils.py:194–213  ·  view source on GitHub ↗

Return common prefix for a list of lines. This will ignore lines that contain whitespace only.

(strings: Iterable[str])

Source from the content-addressed store, hash-verified

192
193
194def _common_whitespace_prefix(strings: Iterable[str]) -> str:
195 """
196 Return common prefix for a list of lines.
197 This will ignore lines that contain whitespace only.
198 """
199 # Ignore empty lines and lines that have whitespace only.
200 strings = [s for s in strings if not s.isspace() and not len(s) == 0]
201
202 if not strings:
203 return ""
204
205 else:
206 s1 = min(strings)
207 s2 = max(strings)
208
209 for i, c in enumerate(s1):
210 if c != s2[i] or c not in " \t":
211 return s1[:i]
212
213 return s1

Callers 1

unindent_codeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected