computeFileHash function

String computeFileHash(
  1. String text
)

Computes the content-derived hash tag carried by a hashline section header: the low 16 bits of xxHash32 (seed 0) over the UTF-8 bytes of the normalized text, as 4 uppercase hex characters.

Ported from omp's computeFileHash: any read of byte-identical content mints the same tag, and a follow-up edit anchored at any line validates whenever the live file still hashes to it. Normalization trims trailing [ \t\r] from every line in a single pass.

Implementation

String computeFileHash(String text) {
  final normalized = text.replaceAll(_trailingWhitespaceRe, '');
  final low16 = xxHash32(utf8.encode(normalized)) & 0xFFFF;
  return low16.toRadixString(16).padLeft(hlFileHashLength, '0').toUpperCase();
}