MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / stripPython

Function stripPython

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

Source from the content-addressed store, hash-verified

124// ---------- Python ----------
125
126function stripPython(src: string): string {
127 const out = src.split('');
128 let i = 0;
129 const n = src.length;
130
131 while (i < n) {
132 const c = src[i]!;
133 const c2 = src[i + 1] ?? '';
134 const c3 = src[i + 2] ?? '';
135
136 // Triple-quoted string: """...""" or '''...'''
137 if ((c === '"' || c === "'") && c2 === c && c3 === c) {
138 const quote = c;
139 const start = i;
140 i += 3;
141 while (i < n) {
142 if (src[i] === '\\' && i + 1 < n) {
143 i += 2;
144 continue;
145 }
146 if (src[i] === quote && src[i + 1] === quote && src[i + 2] === quote) {
147 i += 3;
148 break;
149 }
150 i++;
151 }
152 blankRange(out, start, i, src);
153 continue;
154 }
155
156 // Single-line string: '...' or "..."
157 if (c === '"' || c === "'") {
158 const quote = c;
159 i++;
160 while (i < n && src[i] !== quote) {
161 if (src[i] === '\\' && i + 1 < n) {
162 i += 2;
163 continue;
164 }
165 if (src[i] === '\n') break; // unterminated
166 i++;
167 }
168 if (i < n && src[i] === quote) i++;
169 continue;
170 }
171
172 // Line comment
173 if (c === '#') {
174 const start = i;
175 while (i < n && src[i] !== '\n') i++;
176 blankRange(out, start, i, src);
177 continue;
178 }
179
180 i++;
181 }
182
183 return out.join('');

Callers 1

stripCommentsForRegexFunction · 0.85

Calls 2

blankRangeFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected