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

Function extract_ascii_strings

src/textcode/strings2.py:31–47  ·  view source on GitHub ↗

Yield Unicode strings (ASCII) from a buf string of binary data. :param buf: A bytestring. :type buf: str :param n: The minimum length of strings to extract. :type n: int :rtype: Sequence[string]

(buf, n=3)

Source from the content-addressed store, hash-verified

29
30
31def extract_ascii_strings(buf, n=3):
32 """
33 Yield Unicode strings (ASCII) from a buf string of binary data.
34
35 :param buf: A bytestring.
36 :type buf: str
37 :param n: The minimum length of strings to extract.
38 :type n: int
39 :rtype: Sequence[string]
40 """
41 if not buf:
42 return
43
44 reg = '([%s]{%d,})' % (ASCII_BYTE, n)
45 r = re.compile(reg)
46 for match in r.finditer(buf):
47 yield match.group().decode('ascii')
48
49
50def extract_unicode_strings(buf, n=3):

Callers 1

extract_stringsFunction · 0.85

Calls 2

groupMethod · 0.80
decodeMethod · 0.45

Tested by

no test coverage detected