Files

17 lines
490 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""检查 C/C++ 源码中是否含 U+FFFD 替换符(编码损坏标志,不可逆),含则退出码 1。"""
import sys
BAD = b"\xef\xbf\xbd"
bad_files = []
for path in sys.argv[1:]:
with open(path, "rb") as f:
if BAD in f.read():
bad_files.append(path)
if bad_files:
print("U+FFFD replacement chars found (encoding corrupted, irreversible!):")
for p in bad_files:
print(" -", p)
sys.exit(1)