MCPcopy Index your code
hub / github.com/clips/pattern / collapse_tabs

Function collapse_tabs

pattern/web/__init__.py:859–868  ·  view source on GitHub ↗

Returns a string with (consecutive) tabs replaced by a single space. Whitespace on empty lines and at the end of each line is removed. With indentation=True, retains leading whitespace on each line.

(string, indentation=False, replace=" ")

Source from the content-addressed store, hash-verified

857 return "\n".join(p)
858
859def collapse_tabs(string, indentation=False, replace=" "):
860 """ Returns a string with (consecutive) tabs replaced by a single space.
861 Whitespace on empty lines and at the end of each line is removed.
862 With indentation=True, retains leading whitespace on each line.
863 """
864 p = []
865 for x in string.splitlines():
866 n = indentation and len(x) - len(x.lstrip()) or 0
867 p.append(x[:n] + RE_TABS.sub(replace, x[n:]).strip())
868 return "\n".join(p)
869
870def collapse_linebreaks(string, threshold=1):
871 """ Returns a string with consecutive linebreaks collapsed to at most the given threshold.

Callers 1

plaintextFunction · 0.85

Calls 3

lenFunction · 0.85
stripMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…