add remove_utf8_bom

This commit is contained in:
xianjimli 2020-03-24 16:36:02 +08:00
parent df1a91e8a7
commit f0d1687e05
3 changed files with 26 additions and 0 deletions

View File

@ -1,4 +1,7 @@
# 最新动态
* 2020/03/24
* 增加工具 remove\_utf8\_bom
* 2020/03/23
* 增加函数 tk_strlen。
* 完善圆角矩形(感谢智明提供补丁)。

View File

@ -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)。

View File

@ -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");
}