日本語 —
encoding-fixの公式日本語版。
Encoding Fix (日本語)
Windows cp1252/Latin-1 の誤解釈によって発生する文字化け(二重/三重エンコードされた UTF-8)を修復します。依存関係ゼロ — Python 標準ライブラリのみ使用。
典型的な問題
"ue" (U+00FC) -> UTF-8 \xc3\xbc -> read as cp1252 -> "ü"
使い方
ライブラリとして使用
from encoding_fix import sanitize_outbound
clean = sanitize_outbound("Würge") # -> "Wuerge"
サブプロセス出力
from encoding_fix import sanitize_subprocess_output
text = sanitize_subprocess_output(process.stdout)
CLI
python encoding_fix.py "Würge" # Check a single string
python encoding_fix.py # Self-test
特徴
- 冪等性: 正しくエンコードされたテキストは変更されません
- 最大 3 ラウンド: 三重にエンコードされた文字列さえも修復
- サブプロセスデコーダー: プロセス出力用の UTF-8/cp1252 フォールバック
- 依存関係ゼロ: Python 標準ライブラリのみ使用
変更履歴
1.0.0 (2026-03-12)
- BACH system/tools/encoding_fix.py から移植