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

Function stripPython

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

Source from the content-addressed store, hash-verified

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

Callers 1

stripCommentsForRegexFunction · 0.85

Calls 2

blankRangeFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected