MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / format_text

Function format_text

src/licensedcode/tracing.py:39–52  ·  view source on GitHub ↗

Return a formatted text wrapped at `width` given an iterable of tokens. None tokens for unmatched positions are replaced with `no_match`.

(tokens, width=80, margin=4)

Source from the content-addressed store, hash-verified

37
38
39def format_text(tokens, width=80, margin=4):
40 """
41 Return a formatted text wrapped at `width` given an iterable of tokens.
42 None tokens for unmatched positions are replaced with `no_match`.
43 """
44 noop = lambda x: [x]
45 initial_indent = subsequent_indent = u' ' * margin
46 wrapper = partial(textwrap.wrap,
47 width=width,
48 break_on_hyphens=False,
49 initial_indent=initial_indent,
50 subsequent_indent=subsequent_indent)
51 wrap = width and wrapper or noop
52 return u'\n'.join(wrap(u' '.join(tokens)))
53
54
55def matched_rule_tokens_str(match):

Callers 1

get_textsFunction · 0.85

Calls 3

partialFunction · 0.85
wrapFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected