MCPcopy Index your code
hub / github.com/colbymchenry/codegraph / stripPython

Function stripPython

src/resolution/strip-comments.ts:77–135  ·  view source on GitHub ↗
(src: string)

Source from the content-addressed store, hash-verified

75// ---------- Python ----------
76
77function stripPython(src: string): string {
78 const out = src.split('');
79 let i = 0;
80 const n = src.length;
81
82 while (i < n) {
83 const c = src[i]!;
84 const c2 = src[i + 1] ?? '';
85 const c3 = src[i + 2] ?? '';
86
87 // Triple-quoted string: """...""" or '''...'''
88 if ((c === '"' || c === "'") && c2 === c && c3 === c) {
89 const quote = c;
90 const start = i;
91 i += 3;
92 while (i < n) {
93 if (src[i] === '\\' && i + 1 < n) {
94 i += 2;
95 continue;
96 }
97 if (src[i] === quote && src[i + 1] === quote && src[i + 2] === quote) {
98 i += 3;
99 break;
100 }
101 i++;
102 }
103 blankRange(out, start, i, src);
104 continue;
105 }
106
107 // Single-line string: '...' or "..."
108 if (c === '"' || c === "'") {
109 const quote = c;
110 i++;
111 while (i < n && src[i] !== quote) {
112 if (src[i] === '\\' && i + 1 < n) {
113 i += 2;
114 continue;
115 }
116 if (src[i] === '\n') break; // unterminated
117 i++;
118 }
119 if (i < n && src[i] === quote) i++;
120 continue;
121 }
122
123 // Line comment
124 if (c === '#') {
125 const start = i;
126 while (i < n && src[i] !== '\n') i++;
127 blankRange(out, start, i, src);
128 continue;
129 }
130
131 i++;
132 }
133
134 return out.join('');

Callers 1

stripCommentsForRegexFunction · 0.85

Calls 2

blankRangeFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected