cratefield-text-diff 0.1.0

Word-level diff (removed, added, same) in which protected ranges are atomic and reported as locked
Documentation
  • Coverage
  • 81.82%
    9 out of 11 items documented1 out of 5 items with examples
  • Size
  • Source code size: 29.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 173.7 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 6s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Cratefield/harness
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ParallelEntrepreneur

cratefield-text-diff

A word-level diff for showing what a rewrite changed: segments that are removed, added or same, and locked for protected ranges that came through unchanged.

use cratefield_text_diff::{Op, diff_words};

let segments = diff_words("revenue grew by 18%", "revenue rose 18%");
assert_eq!(segments[1].op, Op::Removed); // "grew by "
assert_eq!(segments[2].op, Op::Added);   // "rose "

diff_words_locked(before, after, before_ranges, after_ranges) treats each protected byte range as one atomic token, never split into words, so a quotation or a figure is shown as kept or changed as a whole. The ranges can come from cratefield-text-guard or anywhere else.

Whitespace rides on the token before it and is not compared, so re-wrapping is not a change; the segments that are not removed, in order, rebuild the rewrite exactly. The algorithm is Myers' O(ND) diff in linear space, so a full rewrite of a 10,000-word text costs memory proportional to its length. Pure Rust, no dependencies beyond serde; builds for wasm32-unknown-unknown.