mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-29 18:48:09 +08:00
add to_utf8_bom
This commit is contained in:
parent
2f8f91c331
commit
bfd6985b33
9
tools/to_utf8_bom/README.md
Normal file
9
tools/to_utf8_bom/README.md
Normal 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 {} \;
|
||||
```
|
14
tools/to_utf8_bom/index.js
Normal file
14
tools/to_utf8_bom/index.js
Normal 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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user