MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / indent

Function indent

tools/python-3.11.9-amd64/Lib/textwrap.py:470–485  ·  view source on GitHub ↗

Adds 'prefix' to the beginning of selected lines in 'text'. If 'predicate' is provided, 'prefix' will only be added to the lines where 'predicate(line)' is True. If 'predicate' is not provided, it will default to adding 'prefix' to all non-empty lines that do not consist solely

(text, prefix, predicate=None)

Source from the content-addressed store, hash-verified

468
469
470def indent(text, prefix, predicate=None):
471 """Adds 'prefix' to the beginning of selected lines in 'text'.
472
473 If 'predicate' is provided, 'prefix' will only be added to the lines
474 where 'predicate(line)' is True. If 'predicate' is not provided,
475 it will default to adding 'prefix' to all non-empty lines that do not
476 consist solely of whitespace characters.
477 """
478 if predicate is None:
479 def predicate(line):
480 return line.strip()
481
482 def prefixed_lines():
483 for line in text.splitlines(True):
484 yield (prefix + line if predicate(line) else line)
485 return ''.join(prefixed_lines())
486
487
488if __name__ == "__main__":

Callers 2

_expand_summaryMethod · 0.90
_expand_detailsMethod · 0.90

Calls 2

prefixed_linesFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected