diff --git a/src/core/file/fileManipulate.ts b/src/core/file/fileManipulate.ts index dcc76997d..8f6234ca9 100644 --- a/src/core/file/fileManipulate.ts +++ b/src/core/file/fileManipulate.ts @@ -6,7 +6,11 @@ interface FileManipulator { removeEmptyLines(content: string): string; } -const rtrimLines = (content: string): string => content.replace(/[ \t]+$/gm, ''); +const rtrimLines = (content: string): string => + content + .split('\n') + .map((line) => line.trimEnd()) + .join('\n'); class BaseManipulator implements FileManipulator { removeComments(content: string): string { @@ -88,32 +92,17 @@ class PythonManipulator extends BaseManipulator { removeHashComments(content: string): string { const searchInPairs = (pairs: [number, number][], hashIndex: number): boolean => { - let ans = -1; - let start = 0; - let end = pairs.length - 1; - while (start <= end) { - const mid = Math.floor((start + end) / 2); - const [pairStart, pairEnd] = pairs[mid]; - if (hashIndex > pairStart && hashIndex < pairEnd) { - ans = mid; - break; - } - if (hashIndex < pairStart) { - end = mid - 1; - } else { - start = mid + 1; - } - } - return ans !== -1; + return pairs.some(([start, end]) => hashIndex > start && hashIndex < end); }; + let result = ''; const pairs: [number, number][] = []; let prevQuote = 0; while (prevQuote < content.length) { - const openingQuote: number = content.slice(prevQuote + 1).search(/(?