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

Function stripRuby

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

Source from the content-addressed store, hash-verified

186// ---------- Ruby ----------
187
188function stripRuby(src: string): string {
189 const out = src.split('');
190 let i = 0;
191 const n = src.length;
192 let atLineStart = true;
193
194 while (i < n) {
195 const c = src[i]!;
196
197 // =begin / =end block comments must be at start of line (after optional whitespace)
198 if (atLineStart && c === '=' && src.startsWith('=begin', i)) {
199 const start = i;
200 // consume to matching =end at line start
201 i += '=begin'.length;
202 while (i < n) {
203 if (src[i] === '\n') {
204 // check next line for =end
205 let j = i + 1;
206 while (j < n && (src[j] === ' ' || src[j] === '\t')) j++;
207 if (src.startsWith('=end', j)) {
208 i = j + '=end'.length;
209 // consume rest of that line
210 while (i < n && src[i] !== '\n') i++;
211 break;
212 }
213 }
214 i++;
215 }
216 blankRange(out, start, i, src);
217 atLineStart = i > 0 && src[i - 1] === '\n';
218 continue;
219 }
220
221 // String literals
222 if (c === '"' || c === "'") {
223 const quote = c;
224 i++;
225 while (i < n && src[i] !== quote) {
226 if (src[i] === '\\' && i + 1 < n) {
227 i += 2;
228 continue;
229 }
230 if (src[i] === '\n') break;
231 i++;
232 }
233 if (i < n && src[i] === quote) i++;
234 atLineStart = false;
235 continue;
236 }
237
238 // Line comment
239 if (c === '#') {
240 const start = i;
241 while (i < n && src[i] !== '\n') i++;
242 blankRange(out, start, i, src);
243 atLineStart = false;
244 continue;
245 }

Callers 1

stripCommentsForRegexFunction · 0.85

Calls 2

blankRangeFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected