MCPcopy Create free account
hub / github.com/SalesforceAIResearch/perfcodegen / remove_unindented_lines

Function remove_unindented_lines

src/sanitize.py:285–307  ·  view source on GitHub ↗
(code, protect_before, execeptions, trim_tails)

Source from the content-addressed store, hash-verified

283
284
285def remove_unindented_lines(code, protect_before, execeptions, trim_tails):
286 lines = code.splitlines()
287 cut_idx = []
288 cut_enabled = False
289 for i, line in enumerate(lines):
290 if not cut_enabled and line.startswith(protect_before):
291 cut_enabled = True
292 continue
293 if line.strip() == "":
294 continue
295 if any(line.startswith(e) for e in execeptions):
296 continue
297
298 lspace = len(line) - len(line.lstrip())
299 if lspace == 0:
300 cut_idx.append(i)
301
302 if any(line.rstrip().startswith(t) for t in trim_tails):
303 # cut off everything behind
304 cut_idx.extend(list(range(i, len(lines))))
305 break
306
307 return "\n".join([line for i, line in enumerate(lines) if i not in cut_idx])
308
309
310def to_four_space_indents(old_code):

Callers 1

sanitizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected