Files
rea/src/process/boundedUtf8Text.ts
T
morluto b5ededd0f9 fix(providers): retain native parsing and compiler failure diagnostics
Parse otool field occurrences once and reject valueless required fields while retaining empty dylib options. Preserve compiler exit outcomes and stderr through capture errors and nested Ghidra causes, with explicit UTF-8 truncation after redaction.

Strengthen provider failure assertions and document the manual Ghidra 12.1.4 macOS x64 decompiler build using upstream instructions.

Validation: focused producer tests, nine fake-compiler preparation and cancellation tests, temporary-directory hygiene, static and documentation checks. No real Swift or Ghidra compilation was run locally.
2026-10-12 08:59:14 +08:00

17 lines
564 B
TypeScript

/** Keep a UTF-8 string within a byte budget without cutting a code point. */
export const boundedUtf8Text = (
value: string,
maximumBytes: number,
): { readonly text: string; readonly truncated: boolean } => {
let bytes = 0;
let end = 0;
for (const codePoint of value) {
const codePointBytes = Buffer.byteLength(codePoint, "utf8");
if (bytes + codePointBytes > maximumBytes)
return { text: value.slice(0, end), truncated: true };
bytes += codePointBytes;
end += codePoint.length;
}
return { text: value, truncated: false };
};