Files
rea/src/domain/unicodeCodePointOrder.ts
T
morluto 392f1f3107 refactor: consolidate boundary semantics and prune redundant tests
Share parser modes and collision-free composite keys, enforce architecture guards, and consolidate redundant unit assertions into filesystem, CLI, MCP, and producer-backed workflows. Preserve concurrent upstream boundary fixes and exclude legacy Objective-C class-name bookkeeping labels.

Validation: source/composition suites (3358 passing), focused canonical digest and MCP checks, typecheck/lint, Knip, formatting, architecture guards, and real Foundation archive and Apple legacy simulator CLI/MCP verification. No real Hopper, Ghidra, or IDA verification claim.
2026-10-10 05:56:01 +08:00

27 lines
1.0 KiB
TypeScript

/** Compare strings lexicographically by Unicode code point, independent of locale. */
export const compareUnicodeCodePoints = (
left: string,
right: string,
): number => {
let leftIndex = 0;
let rightIndex = 0;
while (leftIndex < left.length && rightIndex < right.length) {
const leftPoint = left.codePointAt(leftIndex) ?? 0;
const rightPoint = right.codePointAt(rightIndex) ?? 0;
const difference = leftPoint - rightPoint;
if (difference !== 0) return difference;
leftIndex += leftPoint > 0xffff ? 2 : 1;
rightIndex += rightPoint > 0xffff ? 2 : 1;
}
if (leftIndex === left.length && rightIndex === right.length) return 0;
return leftIndex === left.length ? -1 : 1;
};
/**
* Collision-free composite key for deduplication/sorting. `\0`-joins
* collide when any component contains NUL (valid in JS property names);
* a JSON tuple escapes every component. Single owner for composite keys.
*/
export const compositeKey = (parts: readonly unknown[]): string =>
JSON.stringify(parts);