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 · Roadmap
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 / UTF-32 LE / UTF-32 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 (double-BOM inputs converge in two passes)
- ✅ Whitelist-driven recursion — never touches
dep/, binaries, or build outputs - ✅ Gitignore-style
.utf8forgeignoreexclusions (auto-discovered) - ✅ TOML config file (
--config) with CLI > config > defaults precedence - ✅ 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
Install
# From crates.io
# 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
# Optional: convert + verify in one pass
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).
Notes: --backup-dir cannot be combined with --url (fatal, exit 2). An oversized payload fails with exit 1 and is
not written. When --output is omitted, a URL segment with an extension is kept verbatim (…/a.cpp → a.cpp); an
extension-less segment gets .utf8 (…/foo → foo.utf8). Re-fetching identical content reports unchanged and skips
the write. The size cap is enforced during download — an oversized payload aborts mid-stream and nothing is written.
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 | ❌ |
fix |
Convert + verify in one pass (exit 3 on gate failure) | ✅ |
diff |
Compare two JSON reports per path | ❌ |
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.
Rust Toolchain Compatibility
utf8-forge tracks Rust stable (edition 2024). It uses stable language features that require a reasonably recent
toolchain — any stable Rust 1.88 or newer builds the crate. No MSRV is pinned; CI validates the latest stable
toolchain on every push.
License
Apache License, Version 2.0 only. Copyright © 2026 houseme. See LICENSE for the full text.