0
0
Fork 0
mirror of https://github.com/renovatebot/renovate.git synced 2025-05-12 23:51:55 +00:00
renovatebot_renovate/lib/modules/manager/homebrew/util.ts
renovate[bot] 55845508b6
chore(deps): update eslint monorepo to v9 (major) (#33573)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2025-02-20 11:31:13 +00:00

66 lines
1.5 KiB
TypeScript

export function skip(
idx: number,
content: string,
cond: (s: string) => boolean,
): number {
let i = idx;
while (i < content.length) {
if (!cond(content[i])) {
return i;
}
i += 1;
}
return i;
}
export function isSpace(c: string): boolean {
return /\s/.test(c);
}
// Remove line comments starting with #
function removeLineComments(content: string): string {
let newContent = '';
let comment = false;
for (const c of content) {
if (c === '#') {
comment = true;
}
if (comment) {
if (c === '\n') {
comment = false;
}
}
if (!comment) {
newContent += c;
}
}
return newContent;
}
// Remove multi-line comments enclosed between =begin and =end
function removeMultiLineComments(content: string): string {
const beginRegExp = /(^|\n)=begin\s/;
const endRegExp = /(^|\n)=end\s/;
let newContent = content;
let i = newContent.search(beginRegExp);
let j = newContent.search(endRegExp);
while (i !== -1 && j !== -1) {
if (newContent[i] === '\n') {
i += 1;
}
if (newContent[j] === '\n') {
j += 1;
}
j += '=end'.length;
newContent = newContent.substring(0, i) + newContent.substring(j);
i = newContent.search(beginRegExp);
j = newContent.search(endRegExp);
}
return newContent;
}
export function removeComments(content: string): string {
let newContent = removeLineComments(content);
newContent = removeMultiLineComments(newContent);
return newContent;
}