MCPcopy Create free account
hub / github.com/blocksecteam/rustle / findImpl

Function findImpl

utils/core.py:150–172  ·  view source on GitHub ↗
(filename, includeMod=False)

Source from the content-addressed store, hash-verified

148
149
150def findImpl(filename, includeMod=False) -> list:
151 results = []
152 with open(filename, "r") as file:
153 string = re.sub(r" +//[^\n]+\n", "\n", file.read())
154 # while '\n\n\n' in string:
155 # string = re.sub(r'\n\s+\n', r'\n\n', string)
156 # string = re.sub(r'#\[cfg\(test\)\]\n+mod\s+\w+\s*\{(.|\s)+\n\}', '', string)
157
158 pattern = r"(impl" + (r"|mod" if includeMod else r"") + r")\s+((?P<trait>[^\s]+)\s+for\s+)?(?P<struct>[^\s]+)\s*\{"
159 # for func in re.findall(pattern, re.sub('/\\*.+\\*/', '', re.sub('//.+\n', '\n', file.read()))): # remove comment
160 # for func in re.findall(pattern, re.sub('//.+\n', '\n', file.read())): # remove comment
161
162 matches = re.compile(pattern, re.MULTILINE | re.DOTALL)
163 for match in matches.finditer(string):
164 results.append(
165 {
166 "struct": match.groupdict()["struct"] if match.groupdict()["struct"] else "",
167 "trait": match.groupdict()["trait"] if match.groupdict()["trait"] else "",
168 "file": filename,
169 "line_number": string[0 : match.start()].count("\n") + 1,
170 }
171 )
172 return results
173
174
175def findFunc(filename, ignoreTest=False) -> list:

Callers 2

findFuncFunction · 0.85
unused-ret.pyFile · 0.85

Calls 1

subMethod · 0.80

Tested by

no test coverage detected