Expand description
Pure word/character counting over &str — no document, no store, no threads.
Mirrors djot_to_plain_text
and the search matcher’s shape: a cheap primitive over &str with the policy
(which counting method) passed in as a parameter, so a host app can count a manuscript
of thousands of scenes without importing each one into a document.
Language is not a parameter: UAX #29 word segmentation is not locale-tailored the
way case-folding is, and the CJK rule (CountMethod::CjkHybrid) is script-detected
per character. A caller that wants “count this Chinese scene per character” selects
CjkHybrid; it does not pass a language tag.
Structs§
- Word
Char Counts - The three counts a caller might display. All three are always computed — “characters with spaces” vs “without” is a display choice, not a separate counting mode.
Enums§
- Count
Method - How words are delimited. Characters are always counted the same way (Unicode scalar
values), independent of this choice — see
WordCharCounts.
Functions§
- count
- Count words and characters in already-extracted plain text.
- count_
djot - Extract prose from Djot source, then count. The two-step (strip then count) is kept
deliberately simple:
djot_to_plain_textcarries a pinned contract (table-anchor sentinel, single-\nblock joins) and fusing the parse-and-count into one AST walk is the easiest way to accidentally create a third, silently-diverging “what is the text”.