MCPcopy Index your code
hub / github.com/numpy/numpy / strip_comments

Function strip_comments

tools/ci/check_c_api_usage.py:26–65  ·  view source on GitHub ↗

Return (code_without_comments, updated_in_block). Removes // line comments and /* ... */ block comments (non-nesting, C-style).

(line: str, in_block: bool)

Source from the content-addressed store, hash-verified

24"""
25
26def strip_comments(line: str, in_block: bool) -> tuple[str, bool]:
27 """
28 Return (code_without_comments, updated_in_block).
29 Removes // line comments and /* ... */ block comments (non-nesting, C-style).
30 """
31 i = 0
32 out_parts: list[str] = []
33 n = len(line)
34
35 while i < n:
36 if in_block:
37 end = line.find("*/", i)
38 if end == -1:
39 # Entire remainder is inside a block comment.
40 return ("".join(out_parts), True)
41 i = end + 2
42 in_block = False
43 continue
44
45 # Not in block: look for next // or /* from current i
46 sl = line.find("//", i)
47 bl = line.find("/*", i)
48
49 if sl != -1 and (bl == -1 or sl < bl):
50 # Line comment starts first: take code up to '//' and stop
51 out_parts.append(line[i:sl])
52 return ("".join(out_parts), in_block)
53
54 if bl != -1:
55 # Block comment starts: take code up to '/*', then enter block
56 out_parts.append(line[i:bl])
57 i = bl + 2
58 in_block = True
59 continue
60
61 # No more comments
62 out_parts.append(line[i:])
63 break
64
65 return ("".join(out_parts), in_block)
66
67def iter_source_files(root: Path, exts: set[str], excludes: set[str]) -> list[Path]:
68 """

Callers 1

scan_fileFunction · 0.85

Calls 2

findMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…