//#region src/lib/parsers/rfc822-header-parser.ts
/** Multi-value headers that can appear multiple times. */
const MULTI_VALUE_HEADERS = new Set([
	"Classifier",
	"Platform",
	"Project-URL",
	"Requires-Dist",
	"Requires-External",
	"Supported-Platform"
]);
/**
* Parse RFC 822-style headers from PKG-INFO / METADATA content.
* Multi-value headers are collected into newline-separated strings.
* Stops at the first blank line (which separates headers from body).
*/
function parseRfc822Headers(content) {
	const headers = {};
	let lastKey = "";
	for (const line of content.split("\n")) {
		if (line.trim() === "") break;
		if (/^\s/.test(line) && lastKey) {
			const continuation = line.trim();
			if (continuation) headers[lastKey] = `${headers[lastKey]}\n${continuation}`;
			continue;
		}
		const colonIndex = line.indexOf(": ");
		if (colonIndex > 0) {
			const key = line.slice(0, colonIndex);
			const value = line.slice(colonIndex + 2).trim();
			headers[key] = MULTI_VALUE_HEADERS.has(key) && headers[key] ? `${headers[key]}\n${value}` : value;
			lastKey = key;
		}
	}
	return headers;
}
/** Extract body text after the first blank line. */
function extractRfc822Body(content) {
	const blankIndex = content.indexOf("\n\n");
	if (blankIndex === -1) return void 0;
	return content.slice(blankIndex + 2).trim() || void 0;
}
/** Split newline-separated multi-value into array. */
function splitMultiValues(value) {
	if (!value) return [];
	return value.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
}
//#endregion
export { extractRfc822Body, parseRfc822Headers, splitMultiValues };
