diff --git a/docs/changes.md b/docs/changes.md index fe59d2d04..292fed2ac 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,4 +1,7 @@ # 最新动态 +* 2020/03/24 + * 增加工具 remove\_utf8\_bom + * 2020/03/23 * 增加函数 tk_strlen。 * 完善圆角矩形(感谢智明提供补丁)。 diff --git a/tools/remove_utf8_bom/README.md b/tools/remove_utf8_bom/README.md new file mode 100644 index 000000000..331586aae --- /dev/null +++ b/tools/remove_utf8_bom/README.md @@ -0,0 +1,11 @@ +# 去掉UTF-8前的BOM + +有的编译器不支持UTF-8 BOM,此时需要取到去掉UTF-8 BOM文件的BOM. + +用法(bash): + +``` +find src -name \*.h -exec node tools/remove_utf8_bom/index.js {} \; +``` + +> 请安装[nodejs](https://nodejs.org)。 \ No newline at end of file diff --git a/tools/remove_utf8_bom/index.js b/tools/remove_utf8_bom/index.js new file mode 100644 index 000000000..7dc78184a --- /dev/null +++ b/tools/remove_utf8_bom/index.js @@ -0,0 +1,12 @@ +var fs = require('fs'); +var options = {encoding:"utf8"}; + +var filename = process.argv.length > 2 ? process.argv[2] : "test.c"; + +var content = fs.readFileSync(filename).toString(); +if(content.charCodeAt(0) === 0xfeff) { + content = content.substr(1); + fs.writeFileSync(filename, content, options); + console.log(filename + " done"); +} +