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

Function stripRuby

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

Source from the content-addressed store, hash-verified

137// ---------- Ruby ----------
138
139function stripRuby(src: string): string {
140 const out = src.split('');
141 let i = 0;
142 const n = src.length;
143 let atLineStart = true;
144
145 while (i < n) {
146 const c = src[i]!;
147
148 // =begin / =end block comments must be at start of line (after optional whitespace)
149 if (atLineStart && c === '=' && src.startsWith('=begin', i)) {
150 const start = i;
151 // consume to matching =end at line start
152 i += '=begin'.length;
153 while (i < n) {
154 if (src[i] === '\n') {
155 // check next line for =end
156 let j = i + 1;
157 while (j < n && (src[j] === ' ' || src[j] === '\t')) j++;
158 if (src.startsWith('=end', j)) {
159 i = j + '=end'.length;
160 // consume rest of that line
161 while (i < n && src[i] !== '\n') i++;
162 break;
163 }
164 }
165 i++;
166 }
167 blankRange(out, start, i, src);
168 atLineStart = i > 0 && src[i - 1] === '\n';
169 continue;
170 }
171
172 // String literals
173 if (c === '"' || c === "'") {
174 const quote = c;
175 i++;
176 while (i < n && src[i] !== quote) {
177 if (src[i] === '\\' && i + 1 < n) {
178 i += 2;
179 continue;
180 }
181 if (src[i] === '\n') break;
182 i++;
183 }
184 if (i < n && src[i] === quote) i++;
185 atLineStart = false;
186 continue;
187 }
188
189 // Line comment
190 if (c === '#') {
191 const start = i;
192 while (i < n && src[i] !== '\n') i++;
193 blankRange(out, start, i, src);
194 atLineStart = false;
195 continue;
196 }

Callers 1

stripCommentsForRegexFunction · 0.85

Calls 2

blankRangeFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected