Skip to content

Commit 784046c

Browse files
committed
ref(wcwidth): add datahash
1 parent b885ff2 commit 784046c

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/wcwidth.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* wcwidth.c - Unicode character width lookup
2-
* Unicode 16.0 - generated by tasks/gen-wcwidth.ts on 2026-05-28
2+
* Unicode 16.0 - generated by tasks/gen-wcwidth.ts
3+
* Data hash: 2397fe3ee973c18a
34
*
45
* Only zero-width (combining marks + default ignorable) and double-width
56
* (wide/fullwidth) codepoints are stored. Everything else defaults to

tasks/gen-wcwidth.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ function formatUint8Array(values: number[], indent = " "): string {
181181
return lines.join("\n");
182182
}
183183

184+
async function sha256Hex(input: string): Promise<string> {
185+
let bytes = new TextEncoder().encode(input);
186+
let digest = await crypto.subtle.digest("SHA-256", bytes);
187+
return Array.from(new Uint8Array(digest))
188+
.map((byte) => byte.toString(16).padStart(2, "0"))
189+
.join("");
190+
}
191+
184192
let [derivedCategoryText, derivedCorePropsText, eastAsianWidthText] =
185193
await Promise.all([
186194
fetchText("extracted/DerivedGeneralCategory.txt"),
@@ -307,11 +315,24 @@ console.error(`special_large_ranges: ${largeRanges.length} entries`);
307315
console.error(`BMP dirty blocks: ${dirtyBlocks} / 512`);
308316
console.error(`Table data: ${tableBytes} bytes`);
309317

310-
let date = new Date().toISOString().slice(0, 10);
318+
// Fingerprint the generated tables (not the source text or comments) so the
319+
// header changes only when the emitted data would actually differ. Re-running
320+
// against identical Unicode data is byte-for-byte reproducible.
321+
let dataHash = (await sha256Hex(
322+
JSON.stringify({
323+
unicode: UNICODE_BASE,
324+
bmpFilter: Array.from(bmpFilter),
325+
smallPacked,
326+
largeStarts,
327+
largeCounts,
328+
largeWidths,
329+
}),
330+
)).slice(0, 16);
311331

312332
let output = `\
313333
/* wcwidth.c - Unicode character width lookup
314-
* Unicode 16.0 - generated by tasks/gen-wcwidth.ts on ${date}
334+
* Unicode 16.0 - generated by tasks/gen-wcwidth.ts
335+
* Data hash: ${dataHash}
315336
*
316337
* Only zero-width (combining marks + default ignorable) and double-width
317338
* (wide/fullwidth) codepoints are stored. Everything else defaults to
@@ -423,3 +444,5 @@ if (Deno.args.includes("--check")) {
423444
await Deno.writeTextFile("src/wcwidth.c", output);
424445
console.error("Wrote src/wcwidth.c");
425446
}
447+
448+
export {};

0 commit comments

Comments
 (0)