README.md (English — default)
utf8-forge
A focused, idempotent, bidirectional charset transcoder for Windows source trees. Default output: UTF-8 without BOM.
中文 · Design · Maintainer guide · Rollout playbook · Full usage
Why
Mixed-encoding source trees (GB18030 / UTF-8 / UTF-8 BOM / UTF-16) cause:
C4819on English Windows / CI- Mojibake in comments and narrow string literals
- Silent corruption when editors re-save with the wrong ACP
utf8-forge normalizes the tree in one idempotent pass, so you can safely enable /utf-8 afterwards.
Features
- ✅ Detect and convert UTF-8 / UTF-8 BOM / UTF-16 LE / UTF-16 BE / GB18030
- ✅ Default target: UTF-8 without BOM (Strategy A of the Playbook)
- ✅ Bidirectional conversion (GB18030 → UTF-8 → GB18030 is byte-lossless)
- ✅ Idempotent: second run changes 0 bytes
- ✅ Whitelist-driven recursion — never touches
dep/, binaries, or build outputs - ✅ Atomic writes — crash-safe, no truncated files
- ✅ Parallel per-file processing (
rayon) - ✅ Optional remote download (
--url) reuses the same pipeline - ✅ Human-readable + JSON reports
- ✅ Rust 2024 edition, MSRV 1.85
Install
# From source
# Or build in-tree
# Binary: target/release/utf8-forge
Local-only build (no reqwest):
Quick start
# 1) Scan encoding distribution
# 2) Dry-run: see what would change
# 3) Real conversion with backup
# 4) Verify everything is UTF-8 without BOM
Safety rule: scan → --dry-run → convert. Never skip step 2.
Remote download
--url reuses the exact same detection / transcoding pipeline; only the source of bytes changes. Size is capped by
--max-file-size (default 200 MiB).
Commands
| Command | Purpose | Writes? |
|---|---|---|
scan |
Encoding distribution report | ❌ |
convert |
Detect + transcode + atomic write | ✅ |
convert --url |
Fetch remote file and transcode | ✅ |
verify |
Assert all whitelisted files are UTF-8 no BOM | ❌ |
See docs/USAGE.md for the full CLI reference and recipes.
Default whitelist (excerpt)
C/C++ (.c .cc .cpp .cxx .h .hh .hpp .hxx .inl .ipp .tpp), .NET (.cs), JVM (.java .kt), Rust (.rs), Go (.go),
Python (.py), JS/TS (.js .jsx .ts .tsx), Shell (.sh .bash .ps1 .bat), Config (.json .yaml .toml .ini .xml), Docs
(.md .txt .rst), Protocol (.proto).
Not included by default: .rc, .sln, .vcxproj — enable with --include-rc / --include-msbuild.
Excluded by default: dep/, _tools/, .svn/, .git/, build/, temp/, OutputFile*/, node_modules/,
__pycache__/, etc.
License
MIT OR Apache-2.0 (dual-licensed, standard Rust ecosystem convention).