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

Function get_texts

src/licensedcode/tracing.py:18–36  ·  view source on GitHub ↗

Given a match and a query location of query string return a tuple of wrapped texts at `width` for: - the matched query text as a string. - the matched rule text as a string. If `width` is a number superior to zero, the texts are wrapped to width.

(match, width=80, margin=0)

Source from the content-addressed store, hash-verified

16
17
18def get_texts(match, width=80, margin=0):
19 """
20 Given a match and a query location of query string return a tuple of wrapped
21 texts at `width` for:
22
23 - the matched query text as a string.
24 - the matched rule text as a string.
25
26 If `width` is a number superior to zero, the texts are wrapped to width.
27 """
28 qtokens = match.matched_text(whole_lines=False).split()
29 mqt = format_text(tokens=qtokens, width=width, margin=margin)
30 if match.matcher == '6-unknown':
31 itokens = match.rule.text.split()
32 else:
33 itokens = matched_rule_tokens_str(match)
34 mit = format_text(tokens=itokens, width=width, margin=margin)
35
36 return mqt, mit
37
38
39def format_text(tokens, width=80, margin=4):

Calls 4

format_textFunction · 0.85
matched_rule_tokens_strFunction · 0.85
splitMethod · 0.45
matched_textMethod · 0.45