//#region src/lib/parsers/configparser-parser.ts
/**
* Parse a ConfigParser-style INI file into sections with key-value pairs.
* Handles Python ConfigParser conventions: multi-line values via indented
* continuation lines, `#` and `;` comments.
*/
function parseConfigparser(content) {
	const sections = {};
	let currentSection = "";
	let lastKey = "";
	for (const line of content.split("\n")) {
		const trimmed = line.trimEnd();
		if (trimmed === "" || trimmed.startsWith("#") || trimmed.startsWith(";")) continue;
		const sectionMatch = /^\[([^\]]+)\]/.exec(trimmed);
		if (sectionMatch) {
			currentSection = sectionMatch[1];
			sections[currentSection] ??= {};
			lastKey = "";
			continue;
		}
		if (/^\s/.test(line) && lastKey && currentSection) {
			const existing = sections[currentSection][lastKey];
			const continuation = trimmed.trim();
			if (continuation) sections[currentSection][lastKey] = existing ? `${existing}\n${continuation}` : continuation;
			continue;
		}
		const kvMatch = /^([^=:]+)[=:](.*)$/.exec(trimmed);
		if (kvMatch && currentSection) {
			const key = kvMatch[1].trim();
			const value = kvMatch[2].trim();
			sections[currentSection] ??= {};
			sections[currentSection][key] = value;
			lastKey = key;
		}
	}
	return sections;
}
/** Split a multi-line value into individual non-empty lines. */
function splitMultiline(value) {
	return value.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
}
//#endregion
export { parseConfigparser, splitMultiline };
