// src/platform/token-optimizer/line-filter.ts
function matchesLine(pattern, line) {
  const safePattern = pattern.global || pattern.sticky ? new RegExp(pattern.source, pattern.flags) : pattern;
  safePattern.lastIndex = 0;
  return safePattern.test(line);
}
var filterLines = (text, options) => {
  const { keepPatterns, stripPatterns, stripEmptyLines } = options;
  let lines = text.split("\n");
  if (keepPatterns && keepPatterns.length > 0) {
    lines = lines.filter((line) => keepPatterns.some((pattern) => matchesLine(pattern, line)));
  }
  if (stripPatterns && stripPatterns.length > 0) {
    lines = lines.filter((line) => !stripPatterns.some((pattern) => matchesLine(pattern, line)));
  }
  if (stripEmptyLines) {
    lines = lines.filter((line) => line.trim().length > 0);
  }
  return lines.join("\n");
};

export { filterLines };
