import { z } from "zod"; const resultSchema = z.object({ input: z.string(), output: z.string(), status: z.enum(["demangled", "unchanged", "invalid"]), }); /** * Preserve input ordering while parsing `swift-demangle --compact` lines. * The demangler ends each record with LF, so a carriage return belongs to the * symbol text. */ export const parseDemangledSymbols = ( inputs: readonly string[], output: string, ) => { const lines = output.replace(/\n$/u, "").split("\n"); if (lines.length !== inputs.length) throw new TypeError("swift-demangle output count does not match input"); return inputs.map((input, index) => { const value = lines[index]; if (value === undefined) throw new TypeError("swift-demangle omitted an output line"); return resultSchema.parse({ input, output: value, status: value === input ? input.startsWith("$s") || input.startsWith("_$s") ? "invalid" : "unchanged" : "demangled", }); }); };