add to_utf8_bom

This commit is contained in:
lixianjing 2019-10-15 09:52:08 +08:00
parent 2f8f91c331
commit bfd6985b33
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,9 @@
# utf8 to utf8 with bom
在UTF8文件前加上UTF-8 BOM的标志。
用法:
```
find src -name \*.h -exec node tools/to_utf8_bom/index.js {} \;
```

View File

@ -0,0 +1,14 @@
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) {
console.log(filename + " is utf-8 with BOM");
} else {
content = "\ufeff"+content;
fs.writeFileSync(filename, content, options);
console.log(filename + " done");
}