CHSTRING – String Replacement Using a Changes File
Status: Current Last updated: 2026-05-27 10:06 EDT
Purpose
Reimplements CLAN’s chstring command, which reads a changes file containing find/replace pairs (alternating lines) and applies text substitutions to main-tier words. Replacements are applied to all word nodes, including words inside annotated groups, replacement forms, and bracketed groups.
See the CLAN manual for the original command documentation.
Usage
chatter-clan chstring --changes changes.cut file.cha
Options
| Option | Type | Default | Description |
|---|---|---|---|
-c, --changes | path | (required) | Path to the changes file containing find/replace pairs |
-o, --output | path | stdout | Output CHAT file path |
CLAN +-flag coverage audit
CHSTRING is a transform: it mutates CHAT input and writes
CHAT output. It does not emit a banner and does not share
CommonAnalysisArgs (no speaker/role/gem/range filters apply).
The flag set is entirely command-specific.
Sources: OSX-CLAN/src/clan/chstring.cpp::usage,
crates/talkbank-clan/src/transforms/chstring.rs,
crates/talkbank-cli/src/cli/args/clan_commands.rs::Chstring.
(Status legend: same as FREQ.)
CHSTRING-specific +-flags (from chstring.cpp::usage)
| CLAN flag | Meaning | Chatter | Status | Notes |
|---|---|---|---|---|
+b | Work only on text right of the colon (CHAT format) | (default) | Done | CLAN: chstring.cpp:1120 (case 'b': lineonly = TRUE; no_arg_option(f)). chatter’s chstring already mutates only main-tier word content (never speaker codes or dependent-tier text), so +b is semantically a no-op. Per-CHSTRING rewriter arm in clan_args.rs consumes-and-drops +b so it doesn’t fall through to the positional <PATH> slot. |
+cF / -c | Dictionary file path / do not change inside [...] codes | --changes <PATH> (file form only) | Partial | chatter requires the path explicitly (no changes.cut-in-cwd default). The -c inside-codes guard is implicit, chatter’s AST-based replacement only touches word leaves, never code-bracket content. |
+d | Do not re-wrap tiers | , | Missing | Bare-only per OSX-CLAN/src/clan/chstring.cpp:1087 (NO_CHANGE = TRUE + no_arg_option(f)). chatter never wraps on output, so semantically a no-op. Per-CHSTRING rewriter arm in clan_args.rs passes the token through so clap reports the literal +d argument rather than the misleading --display-mode rewrite. |
+l | Work only on codes left of colon (speaker tag) | , | Missing | |
+lx | Do not show the list of changes | (default) | Done | CLAN: chstring.cpp:1108-1111 (case 'l': if (*f == 'x') DispChanges = FALSE). chatter never prints a changes-list (silent by design), so +lx is semantically a no-op. Per-CHSTRING rewriter arm in clan_args.rs consumes-and-drops the specific lx form so it doesn’t fall through to the positional <PATH> slot. Bare +l (headeronly = TRUE) is genuinely unimplemented and falls through to clap. |
+q | Clean up tiers (add tabs after colons, remove blank spaces) | , | Missing | Tier-cleanup pass. |
+q1 | Clean up tiers for CORELEX | , | Missing | |
+sS S | Inline find/replace pair | , | Missing | All replacements must come via --changes. |
-w | String-oriented search and replacement | (default) | Done | CLAN: chstring.cpp:1145-1147 (case 'w': if (*f == EOS) stringOriented = 1). chatter’s word-leaf replacement is already string-oriented by default, so -w is semantically a no-op. Per-CHSTRING rewriter arm in clan_args.rs consumes-and-drops bare -w so it doesn’t fall through to clap as an unknown short flag. CLAN’s -w1 (stringOriented = 2) is not documented in this audit and is left to fall through. |
+x | Interpret *, _, \ as literal characters | , | Missing | chatter’s matcher does not yet expose wildcard-vs-literal switching. |
Audit summary
| Bucket | Count |
|---|---|
| Done | 3 |
| Partial | 1 |
| Missing | 6 |
CHSTRING is intentionally a thin transform in chatter, the
typed-AST design eliminates several CLAN flags by construction
(+b, -c inside-codes guard, +lx). The remaining gaps are
mostly orthogonal niceties (+q tier-cleanup, +sS inline pair,
+x literal-character mode); none change correctness of the
default file → file transform.
Changes File Format
The changes file contains alternating lines of find and replace strings:
find_text1
replace_text1
find_text2
replace_text2
The file must have an even number of non-empty lines. CLAN looks for changes.cut in the current directory by default; chatter-clan chstring requires the path to be passed explicitly via --changes.
Behavior
For each utterance in the file, the transform walks all word nodes on the main tier – including words inside annotated groups, replacement forms, and bracketed groups – and applies find/replace substitutions from the changes file.
Differences from CLAN
- Operates on the parsed AST rather than raw text, ensuring structural integrity of the CHAT file after substitution.
- Does not support CLAN’s regex-based pattern matching in the changes file.
- Uses the framework transform pipeline (parse -> transform -> serialize -> write).
- Golden test parity: Verified against CLAN C binary output.